/// <summary> /// Force a GC on process processID /// </summary> internal static void ForceGC(int processID, TextWriter log = null) { // We force a GC by turning on an ETW provider, which needs admin to do. if (!App.IsElevated) { throw new ApplicationException("Must be Administrator (elevated) to use Force GC option."); } var arch = GetArchForProcess(processID); if (log != null) { log.WriteLine("Starting Heap dump on Process {0} running architecture {1}.", processID, arch); } var heapDumpExe = Path.Combine(SupportFiles.SupportFileDir, arch + @"\HeapDump.exe"); var options = new CommandOptions().AddNoThrow().AddTimeout(1 * 3600 * 1000); if (log != null) { options.AddOutputStream(log); } var commandLine = string.Format("\"{0}\" /ForceGC {1}", heapDumpExe, processID.ToString()); log.WriteLine("Exec: {0}", commandLine); var cmd = Command.Run(commandLine, options); if (cmd.ExitCode != 0) { throw new ApplicationException("HeapDump failed with exit code " + cmd.ExitCode + ". See log for details."); } }
private static void DumpGCHeap(string qualifiers, string inputArg, string outputFile, TextWriter log, ProcessorArchitecture arch) { var directory = arch == ProcessorArchitecture.X86 ? "x86" : "amd64"; var heapDumpExe = Path.Combine(SupportFiles.SupportFileDir, Path.Combine(directory, "HeapDump.exe")); var options = new CommandOptions().AddNoThrow().AddTimeout(CommandOptions.Infinite); if (log != null) { options.AddOutputStream(log); } // TODO breaking abstraction to know about StackWindow. options.AddEnvironmentVariable("_NT_SYMBOL_PATH", App.SymbolPath); log.WriteLine("set _NT_SYMBOL_PATH={0}", App.SymbolPath); var commandLine = string.Format("\"{0}\" {1} \"{2}\" \"{3}\"", heapDumpExe, qualifiers, inputArg, outputFile); log.WriteLine("Exec: {0}", commandLine); PerfViewLogger.Log.TriggerHeapSnapshot(outputFile, inputArg, qualifiers); var cmd = Command.Run(commandLine, options); if (cmd.ExitCode != 0) { throw new ApplicationException("HeapDump failed with exit code " + cmd.ExitCode); } if (log != null) { log.WriteLine("Completed Heap Dump for {0} to {1}", inputArg, outputFile); } }