Example #1
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();
            }
        }
Example #2
0
        protected IEnumerator <object> FilterHeapData(HeapRecording instance, string filter)
        {
            var result = new Dictionary <HeapSnapshotInfo, FilteredHeapSnapshotInfo>();

            filter = EscapeFilter(filter);
            var regex         = new Regex(filter);
            var functionNames = (from functionName in KnownFunctionNames
                                 where regex.IsMatch(functionName)
                                 select functionName).Distinct();

            using (var activity = Activities.AddItem("Filtering heap")) {
                var fFrameIDs = instance.Database.SymbolsByFunction.Find(functionNames);
                using (fFrameIDs)
                    yield return(fFrameIDs);

                var frameIDs = new HashSet <UInt32>(
                    from key in fFrameIDs.Result select BitConverter.ToUInt32(key.Data.Array, key.Data.Offset)
                    );

                for (int i = 0, c = instance.Snapshots.Count; i < c; i++)
                {
                    activity.Maximum  = c;
                    activity.Progress = i;

                    var info = instance.Snapshots[i];

                    var fSnapshot = instance.GetSnapshot(info);
                    using (fSnapshot)
                        yield return(fSnapshot);

                    var snapshot = fSnapshot.Result;
                    Func <HeapSnapshot.Traceback, bool> tracebackMatches = (traceback) => {
                        var _f = traceback.Frames.Array;
                        for (int _i = 0, _c = traceback.Frames.Count, _o = traceback.Frames.Offset; _i < _c; _i++)
                        {
                            if (frameIDs.Contains(_f[_i + _o]))
                            {
                                return(true);
                            }
                        }

                        return(false);
                    };

                    var fMatchingTracebacks = Future.RunInThread(() => new HashSet <UInt32>(
                                                                     from traceback in snapshot.Tracebacks.AsParallel() where tracebackMatches(traceback) select traceback.ID
                                                                     ));
                    yield return(fMatchingTracebacks);

                    var matchingTracebacks = fMatchingTracebacks.Result;

                    var fInfo = Future.RunInThread(() => new FilteredHeapSnapshotInfo(
                                                       (from heap in snapshot.Heaps.AsParallel() select(from alloc in heap.Allocations.AsParallel() where matchingTracebacks.Contains(alloc.TracebackID) select(long) alloc.Size).Sum()).Sum(),
                                                       (from heap in snapshot.Heaps.AsParallel() select(from alloc in heap.Allocations.AsParallel() where matchingTracebacks.Contains(alloc.TracebackID) select(long) alloc.Overhead).Sum()).Sum(),
                                                       (from heap in snapshot.Heaps.AsParallel() select(from alloc in heap.Allocations.AsParallel() where matchingTracebacks.Contains(alloc.TracebackID) select(long)(alloc.Size + alloc.Overhead)).Sum()).Sum(),
                                                       (from heap in snapshot.Heaps.AsParallel() select(from alloc in heap.Allocations.AsParallel() where matchingTracebacks.Contains(alloc.TracebackID) select alloc).Count()).Sum()
                                                       ));

                    yield return(fInfo);

                    result[info] = fInfo.Result;

                    info.ReleaseStrongReference();
                }
            }

            CurrentFilterData   = result;
            CurrentFilter       = filter;
            PendingFilter       = null;
            PendingFilterFuture = null;

            SnapshotTimeline.Invalidate();
        }
Example #3
0
        protected IEnumerator<object> FilterHeapData(HeapRecording instance, string filter)
        {
            var result = new Dictionary<HeapSnapshotInfo, FilteredHeapSnapshotInfo>();

            var regex = MainWindow.FilterToRegex(filter);
            var functionNames = (from functionName in KnownFunctionNames
                                 where regex.IsMatch(functionName)
                                 select functionName).Distinct();

            using (var activity = Activities.AddItem("Filtering heap")) {
                var fFrameIDs = instance.Database.SymbolsByFunction.Find(functionNames);
                using (fFrameIDs)
                    yield return fFrameIDs;

                var frameIDs = new HashSet<UInt32>(
                    from key in fFrameIDs.Result select BitConverter.ToUInt32(key.Data.Array, key.Data.Offset)
                );

                var matchingTracebacks = new HashSet<UInt32>();

                for (int i = 0, c = instance.Snapshots.Count; i < c; i++) {
                    activity.Maximum = c;
                    activity.Progress = i;

                    var info = instance.Snapshots[i];

                    var fSnapshot = instance.GetSnapshot(info);
                    using (fSnapshot)
                        yield return fSnapshot;

                    var snapshot = fSnapshot.Result;
                    Func<HeapSnapshot.Traceback, bool> tracebackMatches = (traceback) => {
                        if (matchingTracebacks.Contains(traceback.ID))
                            return false;

                        var _f = traceback.Frames.Array;
                        for (int _i = 0, _c = traceback.Frames.Count, _o = traceback.Frames.Offset; _i < _c; _i++) {
                            if (frameIDs.Contains(_f[_i + _o]))
                                return true;
                        }

                        return false;
                    };

                    var fNewMatchingTracebacks = Future.RunInThread(() => new HashSet<UInt32>(
                        from traceback in snapshot.Tracebacks.AsParallel() where tracebackMatches(traceback) select traceback.ID
                    ));
                    yield return fNewMatchingTracebacks;

                    matchingTracebacks.UnionWith(fNewMatchingTracebacks.Result);

                    var fInfo = Future.RunInThread(() => new FilteredHeapSnapshotInfo(
                        (from heap in snapshot.Heaps.AsParallel() select (from alloc in heap.Allocations.AsParallel() where matchingTracebacks.Contains(alloc.TracebackID) select (long)alloc.Size).Sum()).Sum(),
                        (from heap in snapshot.Heaps.AsParallel() select (from alloc in heap.Allocations.AsParallel() where matchingTracebacks.Contains(alloc.TracebackID) select (long)alloc.Overhead).Sum()).Sum(),
                        (from heap in snapshot.Heaps.AsParallel() select (from alloc in heap.Allocations.AsParallel() where matchingTracebacks.Contains(alloc.TracebackID) select (long)(alloc.Size + alloc.Overhead)).Sum()).Sum(),
                        (from heap in snapshot.Heaps.AsParallel() select (from alloc in heap.Allocations.AsParallel() where matchingTracebacks.Contains(alloc.TracebackID) select alloc).Count()).Sum()
                    ));

                    yield return fInfo;
                    result[info] = fInfo.Result;

                    info.ReleaseStrongReference();
                }
            }

            CurrentFilterData = result;
            CurrentFilter = filter;
            PendingFilter = null;
            PendingFilterFuture = null;

            SnapshotTimeline.Invalidate();
        }