Example #1
1
        public DiffViewer(TaskScheduler scheduler, HeapRecording instance)
            : base(scheduler)
        {
            InitializeComponent();

            ListFormat = new StringFormat {
                Trimming = StringTrimming.None,
                FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox
            };

            Timeline.ItemValueGetter = GetBytesTotal;
            Timeline.ItemValueFormatter = MainWindow.FormatSizeBytes;

            Instance = instance;
            if (Instance != null) {
                Timeline.Items = Instance.Snapshots;
                Instance.TracebacksFiltered += Instance_TracebacksFiltered;
                ViewHistogramByModuleMenu.Enabled = ViewHistogramByFunctionMenu.Enabled = true;
                ViewHistogramBySourceFolderMenu.Enabled = ViewHistogramBySourceFileMenu.Enabled = true;
                ViewHistogramByNamespaceMenu.Enabled = ViewTreemapMenu.Enabled = true;
            } else {
                Timeline.Visible = false;
                MainSplit.Height += Timeline.Bottom - MainSplit.Bottom;
                ViewHistogramByModuleMenu.Enabled = ViewHistogramByFunctionMenu.Enabled = false;
                ViewHistogramBySourceFolderMenu.Enabled = ViewHistogramBySourceFileMenu.Enabled = false;
                ViewHistogramByNamespaceMenu.Enabled = ViewTreemapMenu.Enabled = false;
            }
        }
Example #2
0
        protected IEnumerator <object> RefreshFunctionNames(HeapRecording instance)
        {
            var sleep = new Sleep(0.05);

            // This sucks :(
            while (instance.Database.SymbolsByFunction == null)
            {
                yield return(sleep);
            }

            var result = new HashSet <string>();

            var keys = instance.Database.SymbolsByFunction.GetAllKeys();

            using (keys)
                yield return(keys);

            foreach (var key in keys.Result)
            {
                var text = key.Value as string;

                if (text != null)
                {
                    result.Add(text);
                }
            }

            KnownFunctionNames           = result;
            HeapFilter.AutoCompleteItems = result;
        }
Example #3
0
        public DiffViewer(TaskScheduler scheduler, HeapRecording instance)
            : base(scheduler)
        {
            InitializeComponent();

            ListFormat = new StringFormat {
                Trimming    = StringTrimming.None,
                FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox
            };

            Timeline.ItemValueGetter    = GetBytesTotal;
            Timeline.ItemValueFormatter = MainWindow.FormatSizeBytes;

            Instance = instance;
            if (Instance != null)
            {
                Timeline.Items = Instance.Snapshots;
                Instance.TracebacksFiltered            += Instance_TracebacksFiltered;
                ViewHistogramByModuleMenu.Enabled       = ViewHistogramByFunctionMenu.Enabled = true;
                ViewHistogramBySourceFolderMenu.Enabled = ViewHistogramBySourceFileMenu.Enabled = true;
                ViewHistogramByNamespaceMenu.Enabled    = ViewTreemapMenu.Enabled = true;
            }
            else
            {
                Timeline.Visible  = false;
                MainSplit.Height += Timeline.Bottom - MainSplit.Bottom;
                ViewHistogramByModuleMenu.Enabled       = ViewHistogramByFunctionMenu.Enabled = false;
                ViewHistogramBySourceFolderMenu.Enabled = ViewHistogramBySourceFileMenu.Enabled = false;
                ViewHistogramByNamespaceMenu.Enabled    = ViewTreemapMenu.Enabled = false;
            }
        }
Example #4
0
        public HeapViewer(TaskScheduler scheduler, HeapRecording instance)
            : base(scheduler)
        {
            InitializeComponent();

            ListFormat = new StringFormat {
                Trimming    = StringTrimming.None,
                FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox
            };

            LayoutView.Instance = instance;

            Timeline.ItemValueGetter    = GetBytesTotal;
            Timeline.ItemValueFormatter = MainWindow.FormatSizeBytes;

            Instance = instance;
            if (Instance != null)
            {
                Timeline.Items = Instance.Snapshots;
            }
            else
            {
                Timeline.Visible   = false;
                LayoutView.Height += Timeline.Bottom - LayoutView.Bottom;
            }
        }
Example #5
0
 protected void SubscribeToEvents(HeapRecording instance)
 {
     Instance.StatusChanged    += (s, _) => RefreshStatus();
     Instance.SnapshotsChanged += (s, _) => RefreshSnapshots();
     Instance.SymbolsChanged   += (s, _) => {
         Scheduler.Start(
             RefreshFunctionNames(Instance), TaskExecutionPolicy.RunAsBackgroundTask
             );
     };
 }
Example #6
0
        public void OpenSnapshots(IEnumerable <string> filenames)
        {
            DisposeInstance();

            Instance = HeapRecording.FromSnapshots(
                Scheduler, Activities, filenames.OrderBy((f) => f)
                );
            SubscribeToEvents(Instance);

            RefreshStatus();
            RefreshSnapshots();
        }
Example #7
0
        public void OpenSnapshots(IEnumerable <string> filenames)
        {
            DisposeInstance();

            Instance = HeapRecording.FromSnapshots(
                Scheduler, Activities, filenames.OrderBy((f) => f)
                );
            Instance.StatusChanged    += (s, _) => RefreshStatus();
            Instance.SnapshotsChanged += (s, _) => RefreshSnapshots();

            RefreshStatus();
            RefreshSnapshots();
        }
Example #8
0
        protected IEnumerator <object> FinishShowingTooltip(
            Point mouseLocation,
            HeapSnapshot.Heap heap,
            HeapSnapshot.Allocation allocation,
            HeapSnapshot.Traceback rawTraceback
            )
        {
            var uniqueRawFrames = rawTraceback.Frames.AsEnumerable().Distinct();

            var fSymbols = Instance.Database.SymbolCache.Select(uniqueRawFrames);

            using (fSymbols)
                yield return(fSymbols);

            var symbolDict = SequenceUtils.ToDictionary(
                uniqueRawFrames, fSymbols.Result
                );

            var tracebackInfo = HeapRecording.ConstructTracebackInfo(
                rawTraceback.ID, rawTraceback.Frames, symbolDict
                );

            var renderParams = new DeltaInfo.RenderParams {
                BackgroundBrush = new SolidBrush(SystemColors.Info),
                BackgroundColor = SystemColors.Info,
                TextBrush       = new SolidBrush(SystemColors.InfoText),
                IsExpanded      = true,
                IsSelected      = false,
                Font            = Font,
                ShadeBrush      = new SolidBrush(Color.FromArgb(31, 0, 0, 0)),
                StringFormat    = CustomTooltip.GetDefaultStringFormat()
            };

            var content = new HeapSnapshot.AllocationTooltipContent(
                ref allocation, ref tracebackInfo, ref renderParams
                )
            {
                Location = mouseLocation,
                Font     = Font
            };

            using (var g = CreateGraphics())
                CustomTooltip.FitContentOnScreen(
                    g, content,
                    ref content.RenderParams.Font,
                    ref content.Location, ref content.Size
                    );

            Tooltip.SetContent(content);
        }
Example #9
0
        public DiffViewer(TaskScheduler scheduler, HeapRecording instance)
            : base(scheduler)
        {
            InitializeComponent();

            ListFormat = new StringFormat {
                Trimming = StringTrimming.None,
                FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox
            };

            Timeline.ItemValueGetter = GetBytesTotal;
            Timeline.ItemValueFormatter = MainWindow.FormatSizeBytes;

            Instance = instance;
            if (Instance != null) {
                Timeline.Items = Instance.Snapshots;
            } else {
                Timeline.Visible = false;
                MainSplit.Height += Timeline.Bottom - MainSplit.Bottom;
            }
        }
Example #10
0
        public void OpenRecording(string filename)
        {
            if (!DatabaseFile.CheckTokenFileVersion(filename))
            {
                MessageBox.Show(this, "The recording you have selected was produced by a different version of Heap Profiler and cannot be opened.", "Error");
                return;
            }

            DisposeInstance();

            Instance = HeapRecording.FromRecording(
                Scheduler, Activities, filename
                );
            SubscribeToEvents(Instance);

            RefreshStatus();
            RefreshSnapshots();

            Scheduler.Start(
                RefreshFunctionNames(Instance), TaskExecutionPolicy.RunAsBackgroundTask
                );
        }
Example #11
0
        private void LaunchProcess_Click(object sender, EventArgs e)
        {
            DisposeInstance();

            LaunchProcess.Enabled = false;

            Instance = HeapRecording.StartProcess(
                Scheduler, Activities,
                ExecutablePath.Text,
                Arguments.Text,
                WorkingDirectory.Text
                );
            SubscribeToEvents(Instance);

            RefreshStatus();
            RefreshSnapshots();

            if (AutoCapture.Checked)
            {
                AutoCaptureFuture = Start(AutoCaptureTask());
            }
        }
Example #12
0
        public IEnumerator <object> Build(HeapRecording instance, IEnumerable <DeltaInfo> deltas)
        {
            yield return(Future.RunInThread(() => {
                Parallel.ForEach(
                    deltas, (delta) => {
                    StackGraphNode parent = null, node;

                    foreach (var frame in delta.Traceback.Reverse())
                    {
                        if (parent != null)
                        {
                            node = parent.GetNodeForChildFrame(frame);
                        }
                        else
                        {
                            node = GetNodeForFrame(frame);
                        }

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

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

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

            yield return(FinalizeBuild());
        }
Example #13
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();
        }
Example #14
0
        public void OpenRecording(string filename)
        {
            if (!DatabaseFile.CheckTokenFileVersion(filename)) {
                MessageBox.Show(this, "The recording you have selected was produced by a different version of Heap Profiler and cannot be opened.", "Error");
                return;
            }

            DisposeInstance();

            Instance = HeapRecording.FromRecording(
                Scheduler, Activities, filename
            );
            SubscribeToEvents(Instance);

            RefreshStatus();
            RefreshSnapshots();

            Scheduler.Start(
                RefreshFunctionNames(Instance), TaskExecutionPolicy.RunAsBackgroundTask
            );
        }
Example #15
0
        public void OpenSnapshots(IEnumerable<string> filenames)
        {
            DisposeInstance();

            Instance = HeapRecording.FromSnapshots(
                Scheduler, Activities, filenames.OrderBy((f) => f)
            );
            SubscribeToEvents(Instance);

            RefreshStatus();
            RefreshSnapshots();
        }
Example #16
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 #17
0
        public IEnumerator <object> SaveToRecording(HeapRecording recording)
        {
            var db = recording.Database;

            SavedToDatabase = true;

            yield return(db.Snapshots.Set(Index, Info));

            {
                var batch = db.Modules.CreateBatch(Modules.Count);

                foreach (var module in Modules)
                {
                    batch.Add(module.Filename, module);
                }

                yield return(batch.Execute());
            }

            yield return(db.SnapshotModules.Set(Index, Modules.Keys.ToArray()));

            {
                var tracebackBatch = db.Tracebacks.CreateBatch(Tracebacks.Count);

                foreach (var traceback in Tracebacks)
                {
                    tracebackBatch.Add(traceback.ID, traceback);
                }

                yield return(tracebackBatch.Execute());

                yield return(recording.UpdateFilteredTracebacks(
                                 from traceback in Tracebacks select traceback.ID
                                 ));
            }

            UInt16 uIndex = (UInt16)Index;

            HashSet <UInt32> addressSet;

            DecisionUpdateCallback <AllocationRanges> rangeUpdater =
                (ref AllocationRanges oldValue, ref AllocationRanges newValue) => {
                var r = newValue.Ranges.Array[newValue.Ranges.Offset];
                newValue = oldValue.Update(r.First, r.TracebackID, r.Size, r.Overhead);
                return(true);
            };

            foreach (var heap in Heaps)
            {
                var fAddressSet = db.HeapAllocations.Get(heap.ID);
                yield return(fAddressSet);

                if (fAddressSet.Failed)
                {
                    addressSet = new HashSet <UInt32>();
                }
                else
                {
                    addressSet = new HashSet <UInt32>(fAddressSet.Result);
                }

                var batch = db.Allocations.CreateBatch(heap.Allocations.Count);

                foreach (var allocation in heap.Allocations)
                {
                    batch.AddOrUpdate(
                        allocation.Address, AllocationRanges.New(
                            uIndex, allocation.TracebackID, allocation.Size, allocation.Overhead
                            ), rangeUpdater
                        );

                    addressSet.Add(allocation.Address);
                }

                yield return(batch.Execute());

                yield return(db.HeapAllocations.Set(heap.ID, addressSet.ToArray()));
            }

            yield return(db.SnapshotHeaps.Set(Index, (from heap in Heaps select heap.Info).ToArray()));
        }
Example #18
0
        private void LaunchProcess_Click(object sender, EventArgs e)
        {
            DisposeInstance();

            LaunchProcess.Enabled = false;

            Instance = HeapRecording.StartProcess(
                Scheduler, Activities,
                ExecutablePath.Text,
                Arguments.Text,
                WorkingDirectory.Text
            );
            SubscribeToEvents(Instance);

            RefreshStatus();
            RefreshSnapshots();

            if (AutoCapture.Checked)
                AutoCaptureFuture = Start(AutoCaptureTask());
        }
Example #19
0
 protected void SubscribeToEvents(HeapRecording instance)
 {
     Instance.StatusChanged += (s, _) => RefreshStatus();
     Instance.SnapshotsChanged += (s, _) => RefreshSnapshots();
     Instance.SymbolsChanged += (s, _) => {
         Scheduler.Start(
             RefreshFunctionNames(Instance), TaskExecutionPolicy.RunAsBackgroundTask
         );
     };
 }
Example #20
0
        protected IEnumerator<object> RefreshFunctionNames(HeapRecording instance)
        {
            var sleep = new Sleep(0.05);
            // This sucks :(
            while (instance.Database.SymbolsByFunction == null)
                yield return sleep;

            var result = new HashSet<string>();

            var keys = instance.Database.SymbolsByFunction.GetAllKeys();
            using (keys)
                yield return keys;

            foreach (var key in keys.Result) {
                var text = key.Value as string;

                if (text != null)
                    result.Add(text);
            }

            KnownFunctionNames = result;
            HeapFilter.AutoCompleteItems = result;
        }
Example #21
0
        public void OpenSnapshots(IEnumerable<string> filenames)
        {
            DisposeInstance();

            Instance = HeapRecording.FromSnapshots(
                Scheduler, Activities, filenames.OrderBy((f) => f)
            );
            Instance.StatusChanged += (s, _) => RefreshStatus();
            Instance.SnapshotsChanged += (s, _) => RefreshSnapshots();

            RefreshStatus();
            RefreshSnapshots();
        }