RunProcess() public static method

public static RunProcess ( ProcessStartInfo psi, ProcessPriorityClass priority = null, string>.IEnumerable customEnvironment = null ) : IEnumerator
psi System.Diagnostics.ProcessStartInfo
priority ProcessPriorityClass
customEnvironment string>.IEnumerable
return IEnumerator
コード例 #1
0
        protected IEnumerator <object> DiffSnapshotFiles(string file1, string file2)
        {
            var pair = Pair.New(file1, file2);

            string filename;

            if (DiffCache.TryGetValue(pair, out filename))
            {
                yield return(new Result(filename));
            }
            else
            {
                filename = Path.GetTempFileName();

                var psi = new ProcessStartInfo(
                    Settings.UmdhPath, String.Format(
                        "\"{0}\" \"{1}\" -f:\"{2}\"", file1, file2, filename
                        )
                    );

                var rp = Scheduler.Start(Program.RunProcess(psi), TaskExecutionPolicy.RunAsBackgroundTask);

                using (Activities.AddItem("Generating heap diff"))
                    using (rp)
                        yield return(rp);

                DiffCache[pair] = filename;
                TemporaryFiles.Add(filename);

                yield return(new Result(filename));
            }
        }
コード例 #2
0
        protected IEnumerator <object> CaptureSnapshotTask(string targetFilename)
        {
            var now = DateTime.Now;

            var mem = new MemoryStatistics(Process);

            var psi = new ProcessStartInfo(
                Settings.UmdhPath, String.Format(
                    "-g -p:{0} -f:\"{1}\"", Process.Id, targetFilename
                    )
                );

            TemporaryFiles.Add(targetFilename);

            using (Activities.AddItem("Capturing heap snapshot"))
                yield return(Program.RunProcess(psi));

            yield return(Future.RunInThread(
                             () => File.AppendAllText(targetFilename, mem.GetFileText())
                             ));

            var fText = Future.RunInThread(
                () => File.ReadAllText(targetFilename)
                );

            yield return(fText);

            var text = fText.Result;

            fText = null;

            yield return(FinishLoadingSnapshot(Snapshots.Count, now, targetFilename, text));
        }
コード例 #3
0
        protected IEnumerator <object> ProfileMainTask()
        {
            var shortName = Path.GetFileName(Path.GetFullPath(StartInfo.FileName));

            using (Activities.AddItem("Enabling heap instrumentation"))
                yield return(Program.RunProcess(new ProcessStartInfo(
                                                    Settings.GflagsPath, String.Format(
                                                        "-i \"{0}\" +ust", shortName
                                                        )
                                                    )));

            yield return(CreateTemporaryDatabase());

            StartHelperTasks();

            var f = Program.StartProcess(StartInfo);

            using (Activities.AddItem("Starting process"))
                yield return(f);

            using (Process = f.Result) {
                OnStatusChanged();
                yield return(Program.WaitForProcessExit(Process));
            }

            Process = null;

            using (Activities.AddItem("Disabling heap instrumentation"))
                yield return(Program.RunProcess(new ProcessStartInfo(
                                                    Settings.GflagsPath, String.Format(
                                                        "-i \"{0}\" -ust", shortName
                                                        )
                                                    )));

            OnStatusChanged();
        }
コード例 #4
0
        protected IEnumerator <object> SymbolResolverTask()
        {
            var batch        = new List <PendingSymbolResolve>();
            var nullProgress = new CallbackProgressListener();

            ActivityIndicator.CountedItem progress = null;

            while (true)
            {
                var count = SymbolResolveBatchSize - batch.Count;
                SymbolResolveQueue.DequeueMultiple(batch, count);

                if (batch.Count == 0)
                {
                    if (progress != null)
                    {
                        progress.Decrement();
                        progress = null;
                    }

                    if (!SymbolResolveState.Progress.Active && (SymbolResolveQueue.Count <= 0))
                    {
                        SymbolResolveState.Count = 0;
                    }

                    var f = SymbolResolveQueue.Dequeue();
                    using (f)
                        yield return(f);

                    batch.Add(f.Result);
                }
                else
                {
                    if (progress == null)
                    {
                        progress = SymbolResolveState.Progress.Increment();
                    }

                    var maximum = SymbolResolveState.Count + Math.Max(0, SymbolResolveQueue.Count) + 1;
                    progress.Maximum  = maximum;
                    progress.Progress = Math.Min(maximum, SymbolResolveState.Count);

                    string infile = Path.GetTempFileName(), outfile = Path.GetTempFileName();

                    var padNumberRight = (Func <uint, int, string>)((num, length) => {
                        var result = String.Format("{0:X}", num);
                        if (result.Length < length)
                        {
                            result = new String(' ', length - result.Length) + result;
                        }

                        return(result);
                    });

                    var symbolModules = SymbolModules.ToArray();
                    yield return(Future.RunInThread(() => {
                        using (var sw = new StreamWriter(infile, false, Encoding.ASCII)) {
                            sw.WriteLine("// Loaded modules:");
                            sw.WriteLine("//     Base Size Module");

                            foreach (var module in symbolModules)
                            {
                                sw.WriteLine(
                                    "//            {0} {1} {2}",
                                    padNumberRight(module.BaseAddress, 8),
                                    padNumberRight(module.Size, 8),
                                    Path.GetFullPath(module.Filename)
                                    );
                            }

                            sw.WriteLine("//");
                            sw.WriteLine("// Process modules enumerated.");

                            sw.WriteLine();
                            sw.WriteLine("*- - - - - - - - - - Heap 0 Hogs - - - - - - - - - -");
                            sw.WriteLine();

                            for (int i = 0; i < batch.Count; i++)
                            {
                                sw.WriteLine(
                                    "{0:X8} bytes + {1:X8} at {2:X8} by BackTrace{3:X8}",
                                    1, 0, i + 1, i + 1
                                    );

                                sw.WriteLine("\t{0:X8}", batch[i].Frame);
                                sw.WriteLine();
                            }
                        }
                    }));

                    var psi = new ProcessStartInfo(
                        Settings.UmdhPath, String.Format(
                            "\"{0}\" -f:\"{1}\"", infile, outfile
                            )
                        );

                    using (var rp = Scheduler.Start(
                               Program.RunProcess(psi, ProcessPriorityClass.Idle),
                               TaskExecutionPolicy.RunAsBackgroundTask
                               ))
                        yield return(rp);

                    using (Finally.Do(() => {
                        try {
                            File.Delete(infile);
                        } catch {
                        }
                        try {
                            File.Delete(outfile);
                        } catch {
                        }
                    })) {
                        var rtc = new RunToCompletion <HeapDiff>(
                            HeapDiff.FromFile(outfile, nullProgress)
                            );

                        using (rtc)
                            yield return(rtc);

                        var fProcess = Future.RunInThread(() => {
                            var cacheBatch = Database.SymbolCache.CreateBatch(batch.Count);

                            DecisionUpdateCallback <HashSet <UInt32> > updateCallback = (ref HashSet <UInt32> oldValue, ref HashSet <UInt32> newValue) => {
                                newValue.UnionWith(oldValue);
                                return(true);
                            };

                            foreach (var traceback in rtc.Result.Tracebacks)
                            {
                                var index = (int)(traceback.Key) - 1;

                                var key   = batch[index].Frame;
                                var frame = traceback.Value.Frames.Array[traceback.Value.Frames.Offset];
                                batch[index].Result.Complete(frame);

                                lock (SymbolResolveLock) {
                                    ResolvedSymbolCache[key] = frame;
                                    PendingSymbolResolves.Remove(key);
                                }

                                cacheBatch.Add(key, frame);
                                if (frame.Function != null)
                                {
                                    var tempHash = new HashSet <uint>();
                                    tempHash.Add(key);
                                }
                            }

                            foreach (var frame in batch)
                            {
                                if (frame.Result.Completed)
                                {
                                    continue;
                                }

                                Interlocked.Increment(ref TotalFrameResolveFailures);

                                var tf = new TracebackFrame(frame.Frame);

                                frame.Result.Complete(tf);

                                lock (SymbolResolveLock) {
                                    ResolvedSymbolCache[frame.Frame] = tf;
                                    PendingSymbolResolves.Remove(frame.Frame);
                                }

                                cacheBatch.Add(frame.Frame, tf);

                                // Console.WriteLine("Could not resolve: {0:X8}", frame.Frame);
                            }

                            return(new IBatch[] { cacheBatch });
                        });

                        yield return(fProcess);

                        foreach (var manglerBatch in fProcess.Result)
                        {
                            yield return(manglerBatch.Execute());
                        }

                        Interlocked.Add(ref SymbolResolveState.Count, batch.Count);
                        batch.Clear();
                    }
                }
            }
        }