Exemplo n.º 1
0
        public void Process(Task <Heapshot> heapshotTask, bool isCleanup, string iterationName, Components.AutoTest.AutoTestSession.MemoryStats memoryStats)
        {
            taskQueue.Enqueue(async() => {
                var heapshot = await heapshotTask;

                var previousData  = result.Iterations.LastOrDefault();
                var leakedObjects = DetectLeakedObjects(heapshot, isCleanup, previousData, iterationName);
                var leakResult    = new ResultIterationData(iterationName, leakedObjects, memoryStats);

                result.Iterations.Add(leakResult);
            });
        }
Exemplo n.º 2
0
        public void Process(Heapshot heapshot, bool isCleanup, string iterationName, Components.AutoTest.AutoTestSession.MemoryStats memoryStats)
        {
            if (heapshot == null)
            {
                return;
            }

            // TODO: Make this async.

            var previousData  = result.Iterations.LastOrDefault();
            var leakedObjects = DetectLeakedObjects(heapshot, isCleanup, previousData, iterationName);
            var leakResult    = new ResultIterationData(iterationName, leakedObjects, memoryStats);

            result.Iterations.Add(leakResult);
        }
Exemplo n.º 3
0
        Dictionary <string, LeakItem> DetectLeakedObjects(Heapshot heapshot, bool isCleanup, ResultIterationData previousData, string iterationName)
        {
            if (heapshot == null || ProfilerOptions.Type == ProfilerOptions.ProfilerType.Disabled)
            {
                return(new Dictionary <string, LeakItem> ());
            }

            var trackedLeaks = scenario.GetLeakAttributes(isCleanup);

            if (trackedLeaks.Count == 0)
            {
                return(new Dictionary <string, LeakItem> ());
            }

            Directory.CreateDirectory(graphsDirectory);

            Console.WriteLine("Live objects count per type:");
            var leakedObjects = new Dictionary <string, LeakItem> (trackedLeaks.Count);

            foreach (var kvp in trackedLeaks)
            {
                var name = kvp.Key;

                if (!heapshot.TryGetHeapshotTypeInfo(name, out var heapshotTypeInfo))
                {
                    continue;
                }

                var resultFile = ReportPathsToRoots(heapshot, heapshotTypeInfo, iterationName, out int objectCount);
                if (resultFile == null)
                {
                    // We have determined the leak is not an actual leak.
                    continue;
                }

                // We need to check if the root is finalizer or ephemeron, and not report the value.
                leakedObjects.Add(name, new LeakItem(name, objectCount, resultFile));
            }

            foreach (var kvp in leakedObjects)
            {
                var leak  = kvp.Value;
                int delta = 0;
                if (previousData != null && previousData.Leaks.TryGetValue(kvp.Key, out var previousLeak))
                {
                    int previousCount = previousLeak.Count;
                    delta = leak.Count - previousCount;
                }

                Console.WriteLine("{0}: {1} {2:+0;-#}", leak.ClassName, leak.Count, delta);
            }
            return(leakedObjects);
        }