Example #1
0
        private void RunTriage()
        {
            string[] dumpFiles = GetFilesFromPattern(_options.TriagePattern);
            _context.WriteInfoLine("Triage: enumerated {0} dump files in directory '{1}'", dumpFiles.Length, Path.GetDirectoryName(_options.TriagePattern));
            Dictionary <string, TriageInformation> triages = new Dictionary <string, TriageInformation>();

            for (int i = 0; i < dumpFiles.Length; ++i)
            {
                string dumpFile = dumpFiles[i];
                string analysisProgressMessage = String.Format("Analyzing dump file '{0}' ({1}/{2})", dumpFile, i + 1, dumpFiles.Length);
                _context.WriteInfoLine(analysisProgressMessage);
                Console.Title = analysisProgressMessage;

                _target = new AnalysisTarget(dumpFile, _context);
                TriageInformation triageInformation = new Triage().GetTriageInformation(_context);
                triages.Add(dumpFile, triageInformation);
            }

            _context.WriteLine("{0,-30} {1,-30} {2,-50} {3,-30}", "DUMP", "EVENT", "METHOD", "MEMORY (CMT/RSV/MGD)");
            foreach (var kvp in triages)
            {
                string            dumpFile          = kvp.Key;
                TriageInformation triageInformation = kvp.Value;
                _context.WriteLine("{0,-30} {1,-30} {2,-50} {3,-30}",
                                   dumpFile.TrimStartToLength(30),
                                   triageInformation.GetEventDisplayString().TrimStartToLength(30),
                                   (triageInformation.FaultingMethod ?? "N/A").TrimStartToLength(50),
                                   String.Format("{0}/{1}/{2}",
                                                 triageInformation.CommittedMemoryBytes.ToMemoryUnits(),
                                                 triageInformation.ReservedMemoryBytes.ToMemoryUnits(),
                                                 triageInformation.GCHeapMemoryBytes.ToMemoryUnits()
                                                 )
                                   );
            }

            var groupedByModule = from triage in triages.Values
                                  group triage by triage.FaultingModule into g
                                  let count = g.Count()
                                              select new { Module = g.Key, Count = count };

            _context.WriteLine();
            _context.WriteLine("{0,-30} {1,-12}", "MODULE", "COUNT");
            foreach (var moduleCount in groupedByModule)
            {
                _context.WriteLine("{0,-30} {1,-12}", moduleCount.Module, moduleCount.Count);
            }

            var groupedByEvent = from triage in triages.Values
                                 group triage by triage.GetEventDisplayString() into g
                                 let count = g.Count()
                                             select new { Event = g.Key, Count = count };

            _context.WriteLine();
            _context.WriteLine("{0,-50} {1,-12}", "EVENT", "COUNT");
            foreach (var eventCount in groupedByEvent)
            {
                _context.WriteLine("{0,-50} {1,-12}", eventCount.Event, eventCount.Count);
            }
        }
Example #2
0
        private void Run()
        {
            // The NO_CONSOLE environment variable requests that console modifications such as the following one
            // are not performed. This is necessary in no-console environments such as Azure App Service.
            if (Environment.GetEnvironmentVariable("NO_CONSOLE") == null)
            {
                const int ConsoleBufferSize = 4096;
                Console.SetIn(new StreamReader(
                                  Console.OpenStandardInput(bufferSize: ConsoleBufferSize), Console.InputEncoding, false, ConsoleBufferSize)
                              );
            }

            Console.BackgroundColor = ConsoleColor.Black;
            _context.Printer        = new ConsolePrinter();
            _parser = new CmdLineParser(new PrinterTextWriter(_context.Printer));

            ParseCommandLineArguments();
            _context.DisplayDiagnosticInformation = _options.DisplayDiagnosticInformation;

            if (!String.IsNullOrEmpty(_options.DumpFile))
            {
                _target       = new AnalysisTarget(_options.DumpFile, _context, _options.ClrVersion);
                Console.Title = "msos - " + _options.DumpFile;
            }
            else if (!String.IsNullOrEmpty(_options.SummaryDumpFile))
            {
                DisplayShortSummary();
                return; // Do not proceed to the main loop
            }
            else if (!String.IsNullOrEmpty(_options.ProcessName))
            {
                AttachToProcessByName();
            }
            else if (_options.ProcessId != 0)
            {
                _target       = new AnalysisTarget(_options.ProcessId, _context, _options.ClrVersion);
                Console.Title = "msos - attached to pid " + _options.ProcessId;
            }
            else if (!String.IsNullOrEmpty(_options.TriagePattern))
            {
                RunTriage();
                return; // Do not proceed to the main loop
            }
            else
            {
                PrintUsage();
                Bail("One of the -z, --pid, --pn, or --triage options must be specified.");
            }

            RunMainLoop();
        }
Example #3
0
        private void AttachToProcessByName()
        {
            string processName = _options.ProcessName;

            Process[] processes = Process.GetProcessesByName(processName);
            if (processes.Length == 0)
            {
                Bail("There are no processes matching the name '{0}'.", processName);
            }
            if (processes.Length > 1)
            {
                _context.WriteErrorLine("There is more than one process matching the name '{0}', use --pid to disambiguate.", processName);
                _context.WriteInfoLine("Matching process ids: {0}", String.Join(", ", processes.Select(p => p.Id).ToArray()));
                Bail();
            }
            _target = new AnalysisTarget(processes[0].Id, _context, _options.ClrVersion);
        }
Example #4
0
        private void Run()
        {
            const int ConsoleBufferSize = 4096;

            Console.SetIn(new StreamReader(
                              Console.OpenStandardInput(bufferSize: ConsoleBufferSize), Console.InputEncoding, false, ConsoleBufferSize)
                          );

            Console.BackgroundColor = ConsoleColor.Black;
            _context.Printer        = new ConsolePrinter();
            _parser = new CmdLineParser(new PrinterTextWriter(_context.Printer));

            ParseCommandLineArguments();

            if (!String.IsNullOrEmpty(_options.DumpFile))
            {
                _target       = new AnalysisTarget(_options.DumpFile, _context, _options.ClrVersion);
                Console.Title = "msos - " + _options.DumpFile;
            }
            else if (!String.IsNullOrEmpty(_options.ProcessName))
            {
                AttachToProcessByName();
            }
            else if (_options.ProcessId != 0)
            {
                _target       = new AnalysisTarget(_options.ProcessId, _context, _options.ClrVersion);
                Console.Title = "msos - attached to pid " + _options.ProcessId;
            }
            else if (!String.IsNullOrEmpty(_options.TriagePattern))
            {
                RunTriage();
                return; // Do not proceed to the main loop
            }
            else
            {
                PrintUsage();
                Bail("One of the -z, --pid, --pn, or --triage options must be specified.");
            }

            RunMainLoop();
        }
Example #5
0
        private void Run()
        {
            const int ConsoleBufferSize = 4096;
            Console.SetIn(new StreamReader(
                Console.OpenStandardInput(bufferSize: ConsoleBufferSize), Console.InputEncoding, false, ConsoleBufferSize)
                );

            Console.BackgroundColor = ConsoleColor.Black;
            _context.Printer = new ConsolePrinter();
            _parser = new CmdLineParser(new PrinterTextWriter(_context.Printer));

            ParseCommandLineArguments();

            if (!String.IsNullOrEmpty(_options.DumpFile))
            {
                _target = new AnalysisTarget(_options.DumpFile, _context, _options.ClrVersion);
                Console.Title = "msos - " + _options.DumpFile;
            }
            else if (!String.IsNullOrEmpty(_options.ProcessName))
            {
                AttachToProcessByName();
            }
            else if (_options.ProcessId != 0)
            {
                _target = new AnalysisTarget(_options.ProcessId, _context, _options.ClrVersion);
                Console.Title = "msos - attached to pid " + _options.ProcessId;
            }
            else if (!String.IsNullOrEmpty(_options.TriagePattern))
            {
                RunTriage();
                return; // Do not proceed to the main loop
            }
            else
            {
                PrintUsage();
                Bail("One of the -z, --pid, --pn, or --triage options must be specified.");
            }

            RunMainLoop();
        }
Example #6
0
 private void AttachToProcessByName()
 {
     string processName = _options.ProcessName;
     Process[] processes = Process.GetProcessesByName(processName);
     if (processes.Length == 0)
     {
         Bail("There are no processes matching the name '{0}'.", processName);
     }
     if (processes.Length > 1)
     {
         _context.WriteErrorLine("There is more than one process matching the name '{0}', use --pid to disambiguate.", processName);
         _context.WriteInfoLine("Matching process ids: {0}", String.Join(", ", processes.Select(p => p.Id).ToArray()));
         Bail();
     }
     _target = new AnalysisTarget(processes[0].Id, _context, _options.ClrVersion);
 }
Example #7
0
        private void RunTriage()
        {
            string[] dumpFiles = GetFilesFromPattern(_options.TriagePattern);
            _context.WriteInfoLine("Triage: enumerated {0} dump files in directory '{1}'", dumpFiles.Length, Path.GetDirectoryName(_options.TriagePattern));
            Dictionary<string, TriageInformation> triages = new Dictionary<string, TriageInformation>();
            for (int i = 0; i < dumpFiles.Length; ++i)
            {
                string dumpFile = dumpFiles[i];
                string analysisProgressMessage = String.Format("Analyzing dump file '{0}' ({1}/{2})", dumpFile, i + 1, dumpFiles.Length);
                _context.WriteInfoLine(analysisProgressMessage);
                Console.Title = analysisProgressMessage;

                _target = new AnalysisTarget(dumpFile, _context);
                TriageInformation triageInformation = new Triage().GetTriageInformation(_context);
                triages.Add(dumpFile, triageInformation);
            }

            _context.WriteLine("{0,-30} {1,-30} {2,-50} {3,-30}", "DUMP", "EVENT", "METHOD", "MEMORY (CMT/RSV/MGD)");
            foreach (var kvp in triages)
            {
                string dumpFile = kvp.Key;
                TriageInformation triageInformation = kvp.Value;
                _context.WriteLine("{0,-30} {1,-30} {2,-50} {3,-30}",
                    dumpFile.TrimStartToLength(30),
                    triageInformation.GetEventDisplayString().TrimStartToLength(30),
                    (triageInformation.FaultingMethod ?? "N/A").TrimStartToLength(50),
                    String.Format("{0}/{1}/{2}",
                        triageInformation.CommittedMemoryBytes.ToMemoryUnits(),
                        triageInformation.ReservedMemoryBytes.ToMemoryUnits(),
                        triageInformation.GCHeapMemoryBytes.ToMemoryUnits()
                        )
                    );
            }

            var groupedByModule = from triage in triages.Values
                                  group triage by triage.FaultingModule into g
                                  let count = g.Count()
                                  select new { Module = g.Key, Count = count };
            _context.WriteLine();
            _context.WriteLine("{0,-30} {1,-12}", "MODULE", "COUNT");
            foreach (var moduleCount in groupedByModule)
            {
                _context.WriteLine("{0,-30} {1,-12}", moduleCount.Module, moduleCount.Count);
            }

            var groupedByEvent = from triage in triages.Values
                                 group triage by triage.GetEventDisplayString() into g
                                 let count = g.Count()
                                 select new { Event = g.Key, Count = count };
            _context.WriteLine();
            _context.WriteLine("{0,-50} {1,-12}", "EVENT", "COUNT");
            foreach (var eventCount in groupedByEvent)
            {
                _context.WriteLine("{0,-50} {1,-12}", eventCount.Event, eventCount.Count);
            }
        }
Example #8
0
        private void Run()
        {
            // The NO_CONSOLE environment variable requests that console modifications such as the following one
            // are not performed. This is necessary in no-console environments such as Azure App Service.
            if (Environment.GetEnvironmentVariable("NO_CONSOLE") == null)
            {
                const int ConsoleBufferSize = 4096;
                Console.SetIn(new StreamReader(
                    Console.OpenStandardInput(bufferSize: ConsoleBufferSize), Console.InputEncoding, false, ConsoleBufferSize)
                    );
            }

            Console.BackgroundColor = ConsoleColor.Black;
            _context.Printer = new ConsolePrinter();
            _parser = new CmdLineParser(new PrinterTextWriter(_context.Printer));

            ParseCommandLineArguments();
            _context.DisplayDiagnosticInformation = _options.DisplayDiagnosticInformation;

            if (!String.IsNullOrEmpty(_options.DumpFile))
            {
                _target = new AnalysisTarget(_options.DumpFile, _context, _options.ClrVersion);
                Console.Title = "msos - " + _options.DumpFile;
            }
            else if (!String.IsNullOrEmpty(_options.SummaryDumpFile))
            {
                DisplayShortSummary();
                return; // Do not proceed to the main loop
            }
            else if (!String.IsNullOrEmpty(_options.ProcessName))
            {
                AttachToProcessByName();
            }
            else if (_options.ProcessId != 0)
            {
                _target = new AnalysisTarget(_options.ProcessId, _context, _options.ClrVersion);
                Console.Title = "msos - attached to pid " + _options.ProcessId;
            }
            else if (!String.IsNullOrEmpty(_options.TriagePattern))
            {
                RunTriage();
                return; // Do not proceed to the main loop
            }
            else
            {
                PrintUsage();
                Bail("One of the -z, --pid, --pn, or --triage options must be specified.");
            }

            RunMainLoop();
        }