示例#1
0
        public override object [] GetContextConstructorArguments(IConnectionInfo cxInfo)
        {
            var props   = new ConnectionProperties(cxInfo);
            var session = ClrMDSession.AttachToProcess(props.ProcessName);

            Thread.SetData(_threadStorageSlot, session);

            return(new object [] { session });
        }
示例#2
0
        public override List <ExplorerItem> GetSchemaAndBuildAssembly(IConnectionInfo cxInfo, AssemblyName assemblyToBuild,
                                                                      ref string nameSpace, ref string typeName)
        {
            var props = new ConnectionProperties(cxInfo);

            nameSpace = "LINQPad.Extension";
            typeName  = "ClrMDWrapper";

            var allGeneratedSources = new List <string>();
            var sbContextUsings     = new StringBuilder();
            var sbContextProperties = new StringBuilder();

            using (var session = ClrMDSession.AttachToProcess(props.ProcessName))
            {
                var hashset = new HashSet <ClrType>();
                foreach (var sessionAllObject in session.AllObjects)
                {
                    hashset.Add(sessionAllObject.Type);
                }


                CompilerResults results;
                string          outputName = assemblyToBuild.CodeBase;
                using (var codeProvider = new CSharpCodeProvider(new Dictionary <string, string> {
                    { "CompilerVersion", "v4.0" }
                }))
                {
                    string[] assemblies = GetAssembliesToAdd(cxInfo).ToArray();

                    var compilerOptions = new CompilerParameters(assemblies, outputName, true);
                    var dataContext     = DataContextTemplate
                                          .Replace("[usings]", sbContextUsings.ToString())
                                          .Replace("[properties]", sbContextProperties.ToString());

                    allGeneratedSources.Add(dataContext);
                    results = codeProvider.CompileAssemblyFromSource(compilerOptions, allGeneratedSources.ToArray());
                    if (results.Errors.Count > 0)
                    {
                        var sbErr = new StringBuilder();

                        foreach (object o in results.Errors)
                        {
                            sbErr.AppendLine(o.ToString());
                        }

                        // Is there any better troubleshooting mechanism?
                        MessageBox.Show(sbErr.ToString(), "Error compiling generated code");
                    }
                }

                return(SchemaBuilder.GetAppDomainsList(session, hashset));
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            var visits = new List <Visit>();

            using (ClrMDSession session = ClrMDSession.LoadCrashDump(@"C:\AzureDump\Bugfree.Spo.Analytics.Cli-d3c510-08-01-18-51-09.dmp"))
            {
                foreach (ClrObject o in session.EnumerateClrObjects("Bugfree.Spo.Analytics.Cli.Domain+Visit"))
                {
                    var pageLoadTime = (int?)o["PageLoadTime@"]["value"].SimpleValue ?? null;
                    var userAgent    = (string)o["UserAgent@"]["value"].SimpleValue ?? null;
                    var v            = new Visit(
                        (Guid)o["CorrelationId@"],
                        (DateTime)o["Timestamp@"],
                        (string)o["LoginName@"],
                        (string)o["SiteCollectionUrl@"],
                        (string)o["VisitUrl@"],
                        pageLoadTime == null ? FSharpOption <int> .None : new FSharpOption <int>(pageLoadTime.Value),
                        (IPAddress)o["IP@"],
                        userAgent == null ? FSharpOption <string> .None : new FSharpOption <string>(userAgent));
                    visits.Add(v);
                }

                // Enumerating the heap doesn't preserve allocation order. Hence we impose an
                // order using the visit's timestamp for easier inspection.
                foreach (var v in visits.OrderBy(v => v.Timestamp))
                {
                    visitor.Post(VisitorMessage.NewVisit(v));
                }

                // Visitor mailbox processor processes messages/visits on a separate thread.
                // We must wait for the thread to finish processing before terminating the
                // program.
                while (true)
                {
                    var l = visitor.CurrentQueueLength;
                    Console.WriteLine($"Queue length: {l}");
                    Thread.Sleep(5000);

                    if (l == 0)
                    {
                        break;
                    }
                }

                Console.ReadKey();
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            var p = new FluentCommandLineParser();

            p.SetupHelp("help", "h")
            .Callback(() => Console.WriteLine("Usage: \n DumpMemorySummarizer.exe ( -dump=[Dump filename] or -url=[remote RavenDB url] -databaseName=[database name])"))
            .UseForEmptyArgs();

            p.Setup <string>("dump")
            .Callback(record => dumpFilename = record)
            .Required()
            .WithDescription("Dump filename full path");

            p.Setup <string>("url")
            .Callback(record => url = record)
            .Required()
            .WithDescription("URL of RavenDB server");

            p.Setup <string>("databaseName")
            .Callback(record => databaseName = record)
            .SetDefault("DumpMemorySummary")
            .WithDescription("Destination database name");

            p.IsCaseSensitive = false;

            var parseResult = p.Parse(args);

            if (parseResult.HasErrors || String.IsNullOrWhiteSpace(dumpFilename))
            {
                Console.WriteLine(parseResult.ErrorText);
                return;
            }

            IDocumentStore store;

            if (String.IsNullOrWhiteSpace(url))
            {
                store = new EmbeddableDocumentStore
                {
                    RunInMemory           = false,
                    DefaultDatabase       = "DumpMemorySummary",
                    UseEmbeddedHttpServer = true
                };
            }
            else
            {
                store = new DocumentStore
                {
                    Url             = url,
                    DefaultDatabase = databaseName
                };
            }

            using (store)
                using (var session = ClrMDSession.LoadCrashDump(dumpFilename))
                {
                    store.Initialize();
                    store.DatabaseCommands.GlobalAdmin.EnsureDatabaseExists(databaseName);

                    new GcRootCountByKind().Execute(store);
                    new GcRootsCountByKindAndType().Execute(store);
                    new HeapObjectCountByType().Execute(store);
                    new HeapObjectStatisticsByType().Execute(store);

                    var heap = session.Heap;

                    if (heap.CanWalkHeap == false)
                    {
                        throw new ApplicationException("Cannot walk heap, aborting.");
                    }

                    using (var bulkInsert = store.BulkInsert(databaseName))
                    {
                        long rootCount = 0;
                        bulkInsert.Store(session.Runtime.GetThreadPool(), "threadpool/1");

                        Console.Write("Writing threads...");
                        int threadId = 1;
                        foreach (var thread in session.Runtime.Threads)
                        {
                            bulkInsert.Store(new Thread(thread));
                        }
                        Console.WriteLine("done");

                        Console.Write("Writing objects from finalizer queue...");
                        foreach (var finalizerObj in session.Runtime.EnumerateFinalizerQueue())
                        {
                            var clrType = heap.GetObjectType(finalizerObj);

                            if (clrType == null)
                            {
                                continue;
                            }

                            if (clrType.Name.Contains("Stream"))
                            {
                                HandleStreamObject(clrType, bulkInsert, finalizerObj);
                            }
                            else if (clrType.Name.Equals("Microsoft.Isam.Esent.Interop.Table"))
                            {
                                HandleEsentTable(clrType, bulkInsert, finalizerObj);
                            }
                            else
                            {
                                bulkInsert.Store(new FinalizerQueueObject
                                {
                                    TypeName = clrType.Name,
                                    Size     = clrType.BaseSize,
                                });
                            }
                        }
                        Console.WriteLine("done");

                        foreach (var root in heap.EnumerateRoots())
                        {
                            if (root != null && root.Type != null)
                            {
                                var clrType  = root.Type;
                                var rootInfo = new GcRoot
                                {
                                    Address  = root.Address,
                                    Name     = root.Name,
                                    RootKind = root.Kind,
                                    ObjectRefThatRootKeepsAlive = root.Object,
                                    TypeName = (clrType != null) ? clrType.Name : "<No Type>"
                                };
                                bulkInsert.Store(rootInfo);

                                List <ClrRoot> objectRoots;
                                if (gcRootsByObjRef.TryGetValue(root.Object, out objectRoots))
                                {
                                    objectRoots.Add(root);
                                }
                                else
                                {
                                    gcRootsByObjRef.Add(root.Object, new List <ClrRoot> {
                                        root
                                    });
                                }

                                Console.WriteLine("#{0}, {1}", ++rootCount, rootInfo);
                            }
                        }

                        long objectsEnumerated = 0;
                        foreach (var objRef in heap.EnumerateObjects())
                        {
                            objectsEnumerated++;
                            Console.WriteLine("Enumerated {0} objects from the heap", objectsEnumerated);
                            var clrType = heap.GetObjectType(objRef);
                            if (clrType == null)
                            {
                                Console.WriteLine("Warning: heap corrupted, could not determine object type");
                                continue;
                            }
                            var size       = clrType.GetSize(objRef);
                            var generation = heap.GetGeneration(objRef);
                            var objectInfo = new HeapObject
                            {
                                ObjRef      = objRef,
                                Generation  = generation,
                                Size        = size,
                                TypeName    = clrType.Name,
                                IsArray     = clrType.IsArray,
                                ArrayLength = clrType.IsArray ? clrType.GetArrayLength(objRef) : -1,
                                IsInLOH     = heap.IsInHeap(objRef),
                                GcRootPaths = new Dictionary <ulong, List <string> >()
                            };

//						List<ClrRoot> clrRoots;
//						if (gcRootsByObjRef.TryGetValue(objRef, out clrRoots))
//							foreach (var root in clrRoots)
//							{
//								//var path = PathToGcRoots(heap, objRef, root);
//								//objectInfo.GcRootPaths.Add(root.Address, path);
//							}

                            Console.WriteLine("#{0}, {1}", ++objectsEnumerated, objectInfo);
                            bulkInsert.Store(objectInfo);
                        }
                    }
                }
        }
示例#5
0
 public static List <ExplorerItem> GetAppDomainsList(ClrMDSession session, HashSet <ClrType> types)
 {
     return(session.Runtime.AppDomains.Select(domain => BuildAppDomainExplorerItem(domain, types)).ToList());
 }