HeapProfiler.DiffViewer.LoadDiff C# (CSharp) Method

LoadDiff() public method

public LoadDiff ( string filename ) : IEnumerator
filename string
return IEnumerator
        public IEnumerator<object> LoadDiff(string filename)
        {
            var progress = new CallbackProgressListener {
                OnSetStatus = (status) => {
                    LoadingPanel.Text = status;
                },
                OnSetMaximum = (maximum) => {
                    if (LoadingProgress.Maximum != maximum)
                        LoadingProgress.Maximum = maximum;
                },
                OnSetProgress = (value) => {
                    if (value.HasValue) {
                        var v = value.Value;
                        if (LoadingProgress.Style != ProgressBarStyle.Continuous)
                            LoadingProgress.Style = ProgressBarStyle.Continuous;
                        LoadingProgress.Value = Math.Min(v + 1, LoadingProgress.Maximum);
                        LoadingProgress.Value = v;
                    } else {
                        if (LoadingProgress.Style != ProgressBarStyle.Marquee)
                            LoadingProgress.Style = ProgressBarStyle.Marquee;
                    }
                }
            };

            var rtc = new RunToCompletion<HeapDiff>(
                HeapDiff.FromFile(filename, progress)
            );
            using (rtc)
                yield return rtc;

            DiffLoaded(rtc.Result, filename);
        }

Usage Example

Exemplo n.º 1
0
        public static IEnumerator<object> OpenFilenames(IEnumerable<string> filenames, MainWindow mainWindow = null)
        {
            var diffs = new HashSet<string>();
            var snapshots = new HashSet<string>();
            string recording = null;

            foreach (var filename in filenames) {
                switch (Path.GetExtension(filename)) {
                    case ".heaprecording": {
                        if (recording != null) {
                            MessageBox.Show("Only one heap recording can be opened at a time.", "Error");
                            continue;
                        } else if (snapshots.Count > 0) {
                            MessageBox.Show("You cannot open snapshots and a recording in the same session.", "Error");
                            continue;
                        }

                        recording = filename;
                    } break;
                    case ".heapsnap": {
                        if (recording != null) {
                            MessageBox.Show("You cannot open snapshots and a recording in the same session.", "Error");
                            continue;
                        }

                        snapshots.Add(filename);
                    } break;
                    case ".heapdiff": {
                        diffs.Add(filename);
                    } break;
                }
            }

            var futures = new OwnedFutureSet();
            var disposables = new HashSet<IDisposable>();

            if ((recording != null) || (snapshots.Count > 0)) {
                if (mainWindow == null) {
                    mainWindow = new MainWindow(Scheduler);
                    disposables.Add(mainWindow);
                    futures.Add(mainWindow.Show());
                }

                if (recording != null)
                    mainWindow.OpenRecording(recording);
                else
                    mainWindow.OpenSnapshots(snapshots);
            }

            foreach (var diff in diffs) {
                var viewer = new DiffViewer(Scheduler);
                disposables.Add(viewer);

                if (mainWindow != null)
                    futures.Add(viewer.Show(mainWindow));
                else
                    futures.Add(viewer.Show());

                yield return viewer.LoadDiff(diff);
            }

            if (futures.Count == 0) {
                if ((mainWindow == null) && (disposables.Count > 0))
                    throw new InvalidDataException();
            } else {
                using (futures)
                try {
                    yield return Future.WaitForAll(futures);
                } finally {
                    foreach (var disposable in disposables)
                        disposable.Dispose();
                }
            }
        }
All Usage Examples Of HeapProfiler.DiffViewer::LoadDiff