Skip to content

Commit 4ccfc44

Browse files
author
fremag
committed
Process: dump the memory of selected process (ref clrMd 0.8.31 beta)
Closes #2
1 parent 960ff13 commit 4ccfc44

File tree

4 files changed

+114
-9
lines changed

4 files changed

+114
-9
lines changed

MemoScope/MemoScope.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@
4848
<HintPath>..\packages\ObjectListView.2.7.1\lib\ListViewPrinter.dll</HintPath>
4949
<Private>True</Private>
5050
</Reference>
51+
<Reference Include="Microsoft.Diagnostics.Runtime, Version=0.8.31.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
52+
<HintPath>..\packages\Microsoft.Diagnostics.Runtime.0.8.31-beta\lib\net40\Microsoft.Diagnostics.Runtime.dll</HintPath>
53+
<Private>True</Private>
54+
</Reference>
5155
<Reference Include="ObjectListView, Version=2.8.1.33936, Culture=neutral, PublicKeyToken=b1c5bf581481bcd4, processorArchitecture=MSIL">
5256
<HintPath>..\packages\ObjectListView.Official.2.8.1\lib\net20\ObjectListView.dll</HintPath>
5357
<Private>True</Private>

MemoScope/Modules/Process/ProcessModule.Designer.cs

+49-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

MemoScope/Modules/Process/ProcessModule.cs

+59
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Windows.Forms;
56
using System.Windows.Forms.DataVisualization.Charting;
7+
using Microsoft.Diagnostics.Runtime;
8+
using Microsoft.Diagnostics.Runtime.Interop;
69
using WinFwk.UIModules;
10+
using WinFwk.UITools.Log;
711

812
namespace MemoScope.Modules.Process
913
{
@@ -56,6 +60,8 @@ public ProcessModule()
5660
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss";
5761
chart1.ChartAreas[0].AxisY.LabelStyle.Format = "###,###,###,##0";
5862
chart1.ChartAreas[0].AxisY.IsStartedFromZero = false;
63+
64+
tbRootDir.Text = MemoScopeSettings.Instance.RootDir;
5965
}
6066

6167
private void AddValue(string name, string group, Func<ProcessWrapper, object> func, bool visible = false, string format = "{0:###,###,###,##0}", bool addSeries = true)
@@ -136,5 +142,58 @@ public void Init()
136142
proc = (ProcessWrapper) lastProcess;
137143
}
138144
}
145+
146+
private void btnDump_Click(object sender, EventArgs e)
147+
{
148+
if (proc == null)
149+
{
150+
Log("Can't dump: no process selected !", LogLevelType.Error);
151+
return;
152+
}
153+
154+
if (proc.Process.HasExited)
155+
{
156+
Log("Can't dump: process has exited !", LogLevelType.Error);
157+
return;
158+
}
159+
160+
if (!Directory.Exists(tbRootDir.Text))
161+
{
162+
try
163+
{
164+
Directory.CreateDirectory(tbRootDir.Text);
165+
}
166+
catch (Exception ex)
167+
{
168+
Log("Can't create directory: " + tbRootDir.Text, ex);
169+
return;
170+
}
171+
}
172+
DataTarget target = null;
173+
try
174+
{
175+
target = DataTarget.AttachToProcess(proc.Process.Id, 5000, AttachFlag.NonInvasive);
176+
string dumpFileName = string.Format("{0}_{1:yyyy_MM_dd_HH_mm_ss}.dmp", proc.Process.ProcessName, DateTime.Now);
177+
string dumpPath = Path.Combine(tbRootDir.Text, dumpFileName);
178+
179+
int r = target.DebuggerInterface.WriteDumpFile(dumpPath, DEBUG_DUMP.DEFAULT);
180+
if (r == 0)
181+
{
182+
Log("Process dumped ! "+Environment.NewLine+ dumpPath, LogLevelType.Notify);
183+
}
184+
185+
}
186+
catch (Exception ex)
187+
{
188+
Log("Can't dump process !", ex);
189+
}
190+
finally
191+
{
192+
if (target != null)
193+
{
194+
target.DebuggerInterface?.DetachProcesses();
195+
}
196+
}
197+
}
139198
}
140199
}

MemoScope/packages.config

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<packages>
33
<package id="Antlr" version="3.5.0.2" targetFramework="net46" />
44
<package id="ExpressionEvaluator" version="2.0.3.0" targetFramework="net46" />
5+
<package id="Microsoft.Diagnostics.Runtime" version="0.8.31-beta" targetFramework="net46" />
56
<package id="ObjectListView" version="2.7.1" targetFramework="net46" />
67
<package id="ObjectListView.Official" version="2.8.1" targetFramework="net46" />
8+
<package id="System.Diagnostics.Debug" version="4.0.11-beta-23409" targetFramework="net46" />
79
</packages>

0 commit comments

Comments
 (0)