static VMMapData StartVMMap(int pid, string existingVMmapFile) { VMMap map = pid != 0 ? new VMMap(pid) : new VMMap(existingVMmapFile); var lret = map.GetMappingData(); if (pid != 0) { lret.Pid = pid; } return(lret); }
/// <summary> /// Create a memory dump with procdump and then call VMMap to dump the memory constituents into a csv file besides the dump. /// </summary> /// <param name="procdumpArgs"></param> /// <returns></returns> public string Dump(string[] procdumpArgs) { string args = GetProcDumpArgs(procdumpArgs); ProcessStartInfo info = new ProcessStartInfo(ProcDumpExe, $"-accepteula {args}") { CreateNoWindow = true, RedirectStandardOutput = true, UseShellExecute = false, }; var p = Process.Start(info); string line; string dumpFileName = null; List <string> lines = new List <string>(); bool procDumpError = false; while ((line = p.StandardOutput.ReadLine()) != null) { lines.Add(line); if (ShowOutput) { Console.WriteLine(line); } if (line.Contains("Error creating dump file")) { procDumpError = true; } if (dumpFileName == null && procDumpError == false) { dumpFileName = GetDumpFileName(line); } } if (dumpFileName == null) { if (!ShowOutput) { lines.ForEach(Console.WriteLine); } Console.WriteLine($"Error: Could not create dump file with procdump args: {args}!"); return(null); } else { Console.WriteLine($"Dump file {dumpFileName} created."); } int pid = FindPidInProcDumpArgs(procdumpArgs, out string exeName); if (pid == 0) { ProcessFilter filter = new ProcessFilter(exeName ?? ""); pid = filter.GetMatchingPids().FirstOrDefault(); } if (pid != 0) { string outFile = TargetInformation.GetAssociatedVMMapFile(dumpFileName); VMMap.SaveVMmapDataToFile(pid, outFile); } else { Console.WriteLine($"Error: Could not create find process id of dumped process {exeName}. No VMMap information is saved. "); } if (VerifyDump && !CanLoadDump(dumpFileName)) { Console.WriteLine($"Error: Dump file cannot be parsed with MemAnalyzer. Managed Heap might be in an inconsistent state."); dumpFileName = null; } return(dumpFileName); }