Пример #1
0
        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);
            }
        }