1
1
using System ;
2
2
using System . Collections . Generic ;
3
+ using System . IO ;
3
4
using System . Linq ;
4
5
using System . Windows . Forms ;
5
6
using System . Windows . Forms . DataVisualization . Charting ;
7
+ using Microsoft . Diagnostics . Runtime ;
8
+ using Microsoft . Diagnostics . Runtime . Interop ;
6
9
using WinFwk . UIModules ;
10
+ using WinFwk . UITools . Log ;
7
11
8
12
namespace MemoScope . Modules . Process
9
13
{
@@ -56,6 +60,8 @@ public ProcessModule()
56
60
chart1 . ChartAreas [ 0 ] . AxisX . LabelStyle . Format = "HH:mm:ss" ;
57
61
chart1 . ChartAreas [ 0 ] . AxisY . LabelStyle . Format = "###,###,###,##0" ;
58
62
chart1 . ChartAreas [ 0 ] . AxisY . IsStartedFromZero = false ;
63
+
64
+ tbRootDir . Text = MemoScopeSettings . Instance . RootDir ;
59
65
}
60
66
61
67
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()
136
142
proc = ( ProcessWrapper ) lastProcess ;
137
143
}
138
144
}
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
+ }
139
198
}
140
199
}
0 commit comments