Esempio n. 1
0
        private void HeapViewer_FormClosed(object sender, FormClosedEventArgs e)
        {
            Dispose();

            Snapshot.Info.ReleaseStrongReference();
            Timeline.Items      = new List <HeapSnapshotInfo>();
            LayoutView.Snapshot = Snapshot = null;
        }
Esempio n. 2
0
 public void ReleaseStrongReference()
 {
     if (_StrongRef != null)
     {
         _WeakRef = new WeakReference(_StrongRef);
     }
     _StrongRef = null;
 }
Esempio n. 3
0
        protected void AddSnapshot(HeapSnapshot snapshot)
        {
            Snapshots.Add(snapshot.Info);

            // Resort the loaded snapshots, since it's possible for the user to load
            //  a subset of a full capture, or load snapshots in the wrong order
            Snapshots.Sort((lhs, rhs) => lhs.Timestamp.CompareTo(rhs.Timestamp));

            OnSnapshotsChanged();
        }
Esempio n. 4
0
        internal void SetSnapshot(HeapSnapshot heapSnapshot)
        {
            var oldSnapshot = Snapshot;

            if (oldSnapshot != null)
            {
                throw new InvalidOperationException();
            }

            _StrongRef = heapSnapshot;
            _WeakRef   = null;
        }
Esempio n. 5
0
        public IEnumerator <object> Build(
            HeapSnapshot snapshot,
            Dictionary <uint, HeapSnapshot.Traceback> tracebacks,
            Dictionary <uint, TracebackFrame> symbols
            )
        {
            var allocations = from heap in snapshot.Heaps
                              from allocation in heap.Allocations
                              select allocation;

            yield return(Future.RunInThread(() => {
                Parallel.ForEach(
                    allocations, (alloc) => {
                    StackGraphNode parent = null, node;
                    var traceback = tracebacks[alloc.TracebackID];

                    foreach (var frameId in traceback.Reverse())
                    {
                        var frame = symbols[frameId];

                        if (parent != null)
                        {
                            node = parent.GetNodeForChildFrame(frame);
                        }
                        else
                        {
                            node = GetNodeForFrame(frame);
                        }

                        if (node != null)
                        {
                            node.Visit(alloc);
                        }

                        if (node != null)
                        {
                            parent = node;
                        }

                        node = Functions.GetNodeForFrame(frame);
                        node.Visit(alloc);
                    }
                }
                    );
            }));

            yield return(FinalizeBuild());
        }
Esempio n. 6
0
        protected static IEnumerable <VisibleHeap> WalkHeaps(
            HeapSnapshot snapshot, int scrollOffsetInRows,
            int bytesPerRow, int contentWidth
            )
        {
            int rowY = -scrollOffsetInRows;

            foreach (var heapId in snapshot.Heaps.Keys)
            {
                var heap       = snapshot.Heaps[heapId];
                var itemHeight = ComputeHeapHeightInRows(heap, bytesPerRow);

                yield return(new VisibleHeap(
                                 heap, rowY, itemHeight
                                 ));

                rowY += itemHeight;
            }
        }
Esempio n. 7
0
        private IEnumerator <object> SetCurrentSnapshot(HeapSnapshotInfo info)
        {
            var oldSnapshot = Snapshot;

            if (oldSnapshot != null)
            {
                oldSnapshot.Info.ReleaseStrongReference();
            }

            using (Finally.Do(() => {
                UseWaitCursor = false;
            })) {
                var fSnapshot = Instance.GetSnapshot(info);
                yield return(fSnapshot);

                Snapshot = fSnapshot.Result;
                RefreshHeap();
            }
        }
Esempio n. 8
0
        protected IEnumerator <object> ResolveSymbolsForSnapshot(HeapSnapshot snapshot)
        {
            TracebackFrame          tf;
            Future <TracebackFrame> ftf;

            SymbolResolveState.Count = 0;

            yield return(Future.RunInThread(() => {
                for (int i = 0, c = snapshot.Tracebacks.Count; i < c; i++)
                {
                    var traceback = snapshot.Tracebacks[i];

                    lock (SymbolResolveLock)
                        foreach (var frame in traceback)
                        {
                            ResolveFrame(frame, out tf, out ftf);
                        }
                }
            }));
        }
Esempio n. 9
0
        private IEnumerator <object> FinishLoadingSnapshotEpilogue(HeapSnapshot snapshot)
        {
            AddSnapshot(snapshot);

            foreach (var module in snapshot.Modules)
            {
                SymbolModules.Add(module);
            }

            yield return(new Start(
                             ResolveSymbolsForSnapshot(snapshot),
                             TaskExecutionPolicy.RunAsBackgroundTask
                             ));

            if (!snapshot.SavedToDatabase)
            {
                yield return(snapshot.SaveToDatabase(Database));
            }

            Interlocked.Increment(ref SnapshotLoadState.Count);
        }
Esempio n. 10
0
        public HeapSnapshotInfo(
            int index, DateTime timestamp, string filename,
            MemoryStatistics memory, HeapSnapshot snapshot
            ) : base(
                (from heap in snapshot.Heaps select(from alloc in heap.Allocations select(long) alloc.Size).Sum()).Sum(),
                (from heap in snapshot.Heaps select(from alloc in heap.Allocations select(long) alloc.Overhead).Sum()).Sum(),
                (from heap in snapshot.Heaps select(from alloc in heap.Allocations select(long)(alloc.Size + alloc.Overhead)).Sum()).Sum(),
                (from heap in snapshot.Heaps select heap.Allocations.Count).Sum()
                )
        {
            Index      = index;
            Timestamp  = timestamp;
            Filename   = filename;
            Memory     = memory;
            _StrongRef = snapshot;

            HeapFragmentation        = (from heap in snapshot.Heaps select heap.Info.EmptySpans).Sum() / (float)Math.Max(1, (from heap in snapshot.Heaps select heap.Allocations.Count).Sum());
            LargestFreeHeapBlock     = (from heap in snapshot.Heaps select heap.Info.LargestFreeSpan).Max();
            LargestOccupiedHeapBlock = (from heap in snapshot.Heaps select heap.Info.LargestOccupiedSpan).Max();
            AverageFreeBlockSize     = (long)(from heap in snapshot.Heaps select(heap.Info.EstimatedFree) / Math.Max(heap.Info.EmptySpans, 1)).Average();
            AverageOccupiedBlockSize = (long)(from heap in snapshot.Heaps select(heap.Info.TotalOverhead + heap.Info.TotalRequested) / Math.Max(heap.Info.OccupiedSpans, 1)).Average();
        }
Esempio n. 11
0
        protected HeapSnapshotInfo(
            int index, DateTime timestamp, string filename, MemoryStatistics memory,
            float heapFragmentation, long largestFreeHeapBlock, long largestOccupiedHeapBlock,
            long averageFreeBlockSize, long averageOccupiedBlockSize,
            long bytesAllocated, long bytesOverhead, long bytesTotal,
            int allocationCount
            ) : base(
                bytesAllocated, bytesOverhead, bytesTotal, allocationCount
                )
        {
            Index     = index;
            Timestamp = timestamp;
            Filename  = filename;
            Memory    = memory;

            HeapFragmentation        = heapFragmentation;
            LargestFreeHeapBlock     = largestFreeHeapBlock;
            LargestOccupiedHeapBlock = largestOccupiedHeapBlock;
            AverageFreeBlockSize     = averageFreeBlockSize;
            AverageOccupiedBlockSize = averageOccupiedBlockSize;

            _StrongRef = null;
            _WeakRef   = null;
        }
Esempio n. 12
0
        protected IEnumerator <object> LoadSnapshotFromDatabase(HeapSnapshotInfo info)
        {
            var result = new HeapSnapshot(info);

            var fModules = Database.SnapshotModules.Get(info.Index);
            var fHeaps   = Database.SnapshotHeaps.Get(info.Index);

            using (fModules)
                yield return(fModules);

            var fModuleInfos = Database.Modules.Select(
                from moduleName in fModules.Result select moduleName
                );

            using (fModuleInfos)
                yield return(fModuleInfos);

            foreach (var module in fModuleInfos.Result)
            {
                result.Modules.Add(module);
            }

            using (fHeaps)
                yield return(fHeaps);

            var heapIDs      = from heap in fHeaps.Result select heap.HeapID;
            var fAllocations = Database.HeapAllocations.Select(heapIDs);

            using (fAllocations)
                yield return(fAllocations);

            var allocations = SequenceUtils.ToDictionary(heapIDs, fAllocations.Result);

            var tracebackIDs = new HashSet <UInt32>();

            foreach (var heapInfo in fHeaps.Result)
            {
                var theHeap = new HeapSnapshot.Heap(heapInfo);

                var allocationIds = allocations[heapInfo.HeapID];
                theHeap.Allocations.Capacity = allocationIds.Length;

                var fRanges = Database.Allocations.Select(allocationIds);
                using (fRanges)
                    yield return(fRanges);

                yield return(Future.RunInThread(() =>
                                                SequenceUtils.Zip(
                                                    allocationIds, fRanges.Result, (id, ranges) => {
                    HeapSnapshot.AllocationRanges.Range range;

                    if (ranges.Get(info.Index, out range))
                    {
                        theHeap.Allocations.Add(new HeapSnapshot.Allocation(
                                                    id, range.Size, range.Overhead, range.TracebackID
                                                    ));

                        tracebackIDs.Add(range.TracebackID);
                    }
                }
                                                    )
                                                ));

                result.Heaps.Add(theHeap);
            }

            var fTracebacks = Database.Tracebacks.Select(tracebackIDs);

            using (fTracebacks)
                yield return(fTracebacks);

            yield return(Future.RunInThread(() => {
                foreach (var traceback in fTracebacks.Result)
                {
                    result.Tracebacks.Add(traceback);
                }
            }));

            yield return(Result.New(result));
        }