4
4
namespace Microsoft . TestPlatform . Extensions . BlameDataCollector
5
5
{
6
6
using System ;
7
- using System . Collections . Generic ;
8
7
using System . Diagnostics ;
9
8
using System . IO ;
10
9
using System . Linq ;
11
- using System . Threading ;
12
- using System . Threading . Tasks ;
13
10
using Microsoft . Diagnostics . NETCore . Client ;
14
11
using Microsoft . VisualStudio . TestPlatform . ObjectModel ;
15
12
using Microsoft . VisualStudio . TestPlatform . Utilities ;
@@ -43,45 +40,35 @@ public void Dump(int processId, string outputDirectory, DumpTypeOption type)
43
40
44
41
var bottomUpTree = processTree . OrderByDescending ( t => t . Level ) . Select ( t => t . Process ) ;
45
42
46
- // Do not suspend processes with NetClient dumper it stops the diagnostic thread running in
47
- // them and hang dump request will get stuck forever, because the process is not co-operating.
48
- // Instead we start one task per dump asynchronously, and hope that the parent process will start dumping
49
- // before the child process is done dumping. This way if the parent is waiting for the children to exit,
50
- // we will be dumping it before it observes the child exiting and we get a more accurate results. If we did not
51
- // do this, then parent that is awaiting child might exit before we get to dumping it.
52
- var tasks = new List < Task > ( ) ;
53
- var timeout = new CancellationTokenSource ( ) ;
54
- timeout . CancelAfter ( TimeSpan . FromMinutes ( 5 ) ) ;
55
43
foreach ( var p in bottomUpTree )
56
44
{
57
- tasks . Add ( Task . Run (
58
- ( ) =>
59
- {
60
- try
61
- {
62
- var outputFile = Path . Combine ( outputDirectory , $ "{ p . ProcessName } _{ p . Id } _{ DateTime . Now : yyyyMMddTHHmmss} _hangdump.dmp") ;
63
- EqtTrace . Verbose ( $ "NetClientHangDumper.CollectDump: Selected dump type { type } . Dumping { process . Id } - { process . ProcessName } in { outputFile } . ") ;
64
-
65
- var client = new DiagnosticsClient ( p . Id ) ;
66
-
67
- // Connecting the dump generation logging to verbose output to avoid changing the interfaces again -> EqtTrace.IsVerboseEnabled
68
- // before we test this on some big repo.
69
- client . WriteDump ( type == DumpTypeOption . Full ? DumpType . Full : DumpType . Normal , outputFile , logDumpGeneration : false ) ;
70
- }
71
- catch ( Exception ex )
72
- {
73
- EqtTrace . Error ( $ "NetClientHangDumper.Dump: Error dumping process { p . Id } - { p . ProcessName } : { ex } .") ;
74
- }
75
- } , timeout . Token ) ) ;
45
+ try
46
+ {
47
+ p . Suspend ( ) ;
48
+ }
49
+ catch ( Exception ex )
50
+ {
51
+ EqtTrace . Error ( $ "NetClientHangDumper.Dump: Error suspending process { p . Id } - { p . ProcessName } : { ex } .") ;
52
+ }
76
53
}
77
54
78
- try
79
- {
80
- Task . WhenAll ( tasks ) . GetAwaiter ( ) . GetResult ( ) ;
81
- }
82
- catch ( TaskCanceledException )
55
+ foreach ( var p in bottomUpTree )
83
56
{
84
- EqtTrace . Error ( $ "NetClientHangDumper.Dump: Hang dump timed out.") ;
57
+ try
58
+ {
59
+ var outputFile = Path . Combine ( outputDirectory , $ "{ p . ProcessName } _{ p . Id } _{ DateTime . Now : yyyyMMddTHHmmss} _hangdump.dmp") ;
60
+ EqtTrace . Verbose ( $ "NetClientHangDumper.CollectDump: Selected dump type { type } . Dumping { process . Id } - { process . ProcessName } in { outputFile } . ") ;
61
+
62
+ var client = new DiagnosticsClient ( p . Id ) ;
63
+
64
+ // Connecting the dump generation logging to verbose output to avoid changing the interfaces again -> EqtTrace.IsVerboseEnabled
65
+ // before we test this on some big repo.
66
+ client . WriteDump ( type == DumpTypeOption . Full ? DumpType . Full : DumpType . Normal , outputFile , logDumpGeneration : false ) ;
67
+ }
68
+ catch ( Exception ex )
69
+ {
70
+ EqtTrace . Error ( $ "NetClientHangDumper.Dump: Error dumping process { p . Id } - { p . ProcessName } : { ex } .") ;
71
+ }
85
72
}
86
73
87
74
foreach ( var p in bottomUpTree )
@@ -96,6 +83,6 @@ public void Dump(int processId, string outputDirectory, DumpTypeOption type)
96
83
EqtTrace . Error ( $ "NetClientHangDumper.Dump: Error killing process { p . Id } - { p . ProcessName } : { ex } .") ;
97
84
}
98
85
}
99
- }
86
+ }
100
87
}
101
88
}
0 commit comments