Пример #1
0
        public void Run(AnalysisSession analysisSession, string[] arguments)
        {
            var address = ulong.Parse(arguments[0], NumberStyles.HexNumber);
            var type    = analysisSession.Context.Runtime.Heap.GetObjectType(address);

            analysisSession.Reporter.Write(new ClrObject(address, type).Describe());
        }
Пример #2
0
        public void Run(AnalysisSession analysisSession, string[] arguments)
        {
            var modules            = analysisSession.Context.Runtime.Modules;
            var sharedRuntimePaths = new[] { "Microsoft.NetCore.App", "Microsoft.AspNetCore.App" };
            Dictionary <string, string> frameworks     = new Dictionary <string, string>();
            HashSet <ClrModule>         runtimeModules = new HashSet <ClrModule>();

            foreach (var sharedRuntime in sharedRuntimePaths)
            {
                var sharedRuntimePath = Path.Combine("shared", sharedRuntime) + Path.DirectorySeparatorChar;
                foreach (var clrModule in modules)
                {
                    var fileName = clrModule.FileName;
                    if (fileName == null)
                    {
                        continue;
                    }
                    var index = fileName.IndexOf(sharedRuntimePath, StringComparison.OrdinalIgnoreCase);
                    if (index != -1)
                    {
                        var nextSlashIndex = fileName.IndexOf(Path.DirectorySeparatorChar, index + sharedRuntimePath.Length);
                        if (nextSlashIndex != -1)
                        {
                            var version = fileName.Substring(index + sharedRuntimePath.Length, nextSlashIndex - (index + sharedRuntimePath.Length));
                            frameworks[sharedRuntime] = version;
                            runtimeModules.Add(clrModule);
                        }
                    }
                }
            }

            analysisSession.Reporter.Write(new Table("Detected frameworks", frameworks.ToTable("Name", "Version")));


            analysisSession.Reporter.Write(new Table("Non-shared runtime Modules",
                                                     analysisSession.Context.Runtime.Modules.Where(m => !runtimeModules.Contains(m)).ToTable(
                                                         module =>
            {
                string version     = string.Empty;
                string infoVersion = "";

                var reader = module.CreateMetadataReader();
                if (reader != null)
                {
                    version = reader.GetAssemblyDefinition().Version.ToString();

                    var infVersionValue = reader.GetAssemblyAttributeStringValue("AssemblyInformationalVersionAttribute");
                    if (!infVersionValue.FixedArguments.IsDefaultOrEmpty)
                    {
                        infoVersion = infVersionValue.FixedArguments[0].Value.ToString();
                    }
                }
                return(new[]
                {
                    module.Name ?? "<empty>",
                    version,
                    infoVersion
                });
            }, "Name", "Version", "Informational version")));
        }
Пример #3
0
        private void OnExecute()
        {
            var context = AnalysisContext.FromProcessDump(ProcessDump, DAC);

            AnalyzerFactory factory = new AnalyzerFactory();

            if (Web)
            {
                new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(Directory.GetCurrentDirectory())
                .ConfigureServices(
                    collection => {
                    collection.AddSingleton <AnalyzerFactory>(factory);
                    collection.AddSingleton <AnalysisContext>(context);
                })
                .UseStartup <Startup>().Build().Run();
            }
            else
            {
                var reporter        = new ConsoleAnalysisReporter();
                var analysisSession = new AnalysisSession(context, reporter);
                System.Console.CancelKeyPress += (sender, args) => analysisSession.Stop();
                foreach (var analyzerName in Analyzers)
                {
                    var analyzer = factory.CreateAnalyzer(analyzerName);
                    analyzer.Run(analysisSession);
                }
            }
        }
Пример #4
0
 public void Run(AnalysisSession analysisSession)
 {
     foreach (var o in analysisSession.Context.Runtime.Heap.EnumerateObjects().Take(50))
     {
         if (o.Type.IsString)
         {
             analysisSession.Reporter.Write(new StringInstance((string)o.Type.GetValue(o.Address)));
         }
         else
         {
             analysisSession.Reporter.Write(new ObjectInstance(o));
         }
     }
 }
Пример #5
0
        public void Run(AnalysisSession analysisSession, string[] arguments)
        {
            var clrObjects = analysisSession.Context.Runtime.Heap.EnumerateObjects();
            var typeName   = arguments.FirstOrDefault();

            if (!string.IsNullOrEmpty(typeName))
            {
                clrObjects = clrObjects.Where(t => t.Type?.Name == typeName);
            }
            foreach (var o in clrObjects.Take(50))
            {
                analysisSession.Reporter.Write(o.Describe());
            }
        }
Пример #6
0
        public void Run(AnalysisSession analysisSession, string[] arguments)
        {
            var pool = analysisSession.Context.Runtime.ThreadPool;

            analysisSession.Reporter.Write(new Table("ThreadPool status",
                                                     new[]
            {
                new [] { nameof(pool.TotalThreads), pool.TotalThreads.ToString() },
                new [] { nameof(pool.RunningThreads), pool.RunningThreads.ToString() },
                new [] { nameof(pool.IdleThreads), pool.IdleThreads.ToString() },
                new [] { nameof(pool.CpuUtilization), pool.CpuUtilization.ToString() },
                new [] { nameof(pool.FreeCompletionPortCount), pool.FreeCompletionPortCount.ToString() }
            }));

            analysisSession.Reporter.Write(new Table("ThreadPool limits",
                                                     new[]
            {
                new [] { nameof(pool.MinThreads), pool.MinThreads.ToString() },
                new [] { nameof(pool.MaxThreads), pool.MaxThreads.ToString() },
                new [] { nameof(pool.MinCompletionPorts), pool.MinCompletionPorts.ToString() },
                new [] { nameof(pool.MaxCompletionPorts), pool.MaxCompletionPorts.ToString() },
                new [] { nameof(pool.MaxFreeCompletionPorts), pool.MaxFreeCompletionPorts.ToString() },
            }));
        }
Пример #7
0
 public void Run(AnalysisSession analysisSession, string[] arguments)
 {
     analysisSession.Reporter.Write(new FormattedString("Welcome. Try executing ", new CommandRef("dumpheap"), ", ", new CommandRef("threadpool"), ", or", new CommandRef("heapstats"), " command"));
 }