37
37
using System . Windows ;
38
38
using System . Windows . Media ;
39
39
using System . Xml ;
40
+ using Microsoft . Diagnostics . Tracing . Computers ;
40
41
using Microsoft . Diagnostics . Tracing . Parsers . Tpl ;
41
42
using Utilities ;
42
43
using Address = System . UInt64 ;
@@ -994,6 +995,19 @@ protected bool IsMyFormat(string fileName)
994
995
995
996
private static Dictionary < string , PerfViewFile > s_internTable = new Dictionary < string , PerfViewFile > ( ) ;
996
997
#endregion
998
+
999
+ protected static void ConfigureStackWindowForStartStopThreadTime ( StackWindow stackWindow )
1000
+ {
1001
+ var foldPats = StartStopLatencyComputer . GetDefaultFoldPatterns ( ) ;
1002
+ for ( var i = 0 ; i < foldPats . Length ; i ++ )
1003
+ {
1004
+ if ( i == 0 )
1005
+ {
1006
+ stackWindow . FoldRegExTextBox . Text = foldPats [ i ] ;
1007
+ }
1008
+ stackWindow . FoldRegExTextBox . Items . Insert ( 0 , foldPats [ i ] ) ;
1009
+ }
1010
+ }
997
1011
}
998
1012
999
1013
// Used for new user defined file formats.
@@ -6289,6 +6303,28 @@ string GetAllocationType(CallStackIndex csi)
6289
6303
6290
6304
return stackSource ;
6291
6305
}
6306
+ else if ( streamName == "Contention" )
6307
+ {
6308
+ var contentionSource = new MutableTraceEventStackSource ( eventLog ) ;
6309
+ contentionSource . ShowUnknownAddresses = App . CommandLineArgs . ShowUnknownAddresses ;
6310
+ contentionSource . ShowOptimizationTiers = App . CommandLineArgs . ShowOptimizationTiers ;
6311
+
6312
+ var computer = new ContentionLatencyComputer ( eventLog , contentionSource ) ;
6313
+ computer . GenerateStacks ( ) ;
6314
+
6315
+ return contentionSource ;
6316
+ }
6317
+ else if ( streamName == "WaitHandleWait" )
6318
+ {
6319
+ var waitHandleWaitSource = new MutableTraceEventStackSource ( eventLog ) ;
6320
+ waitHandleWaitSource . ShowUnknownAddresses = App . CommandLineArgs . ShowUnknownAddresses ;
6321
+ waitHandleWaitSource . ShowOptimizationTiers = App . CommandLineArgs . ShowOptimizationTiers ;
6322
+
6323
+ var computer = new WaitHandleWaitLatencyComputer ( eventLog , waitHandleWaitSource ) ;
6324
+ computer . GenerateStacks ( ) ;
6325
+
6326
+ return waitHandleWaitSource ;
6327
+ }
6292
6328
else
6293
6329
{
6294
6330
throw new Exception ( "Unknown stream " + streamName ) ;
@@ -7010,6 +7046,11 @@ protected internal override void ConfigureStackWindow(string stackSourceName, St
7010
7046
stackWindow . FoldRegExTextBox . Text = prev ;
7011
7047
stackWindow . FoldRegExTextBox . Items . Insert ( 0 , prev ) ;
7012
7048
}
7049
+
7050
+ if ( stackSourceName == "Contention" || stackSourceName == "WaitHandleWait" )
7051
+ {
7052
+ ConfigureStackWindowForStartStopThreadTime ( stackWindow ) ;
7053
+ }
7013
7054
7014
7055
if ( m_extraTopStats != null )
7015
7056
{
@@ -7033,6 +7074,7 @@ protected internal override void ConfigureStackWindow(string stackSourceName, St
7033
7074
}
7034
7075
}
7035
7076
}
7077
+
7036
7078
public override bool SupportsProcesses { get { return true ; } }
7037
7079
7038
7080
/// <summary>
@@ -7160,6 +7202,8 @@ protected override Action<Action> OpenImpl(Window parentWindow, StatusBar worker
7160
7202
bool hasAssemblyLoad = false ;
7161
7203
bool hasJIT = false ;
7162
7204
bool hasUserCrit = false ;
7205
+ bool hasContention = false ;
7206
+ bool hasWaitHandle = false ;
7163
7207
7164
7208
var stackEvents = new List < TraceEventCounts > ( ) ;
7165
7209
foreach ( var counts in tracelog . Stats )
@@ -7237,6 +7281,16 @@ protected override Action<Action> OpenImpl(Window parentWindow, StatusBar worker
7237
7281
hasUserCrit = true ;
7238
7282
}
7239
7283
7284
+ if ( name . StartsWith ( "Contention/Start" ) )
7285
+ {
7286
+ hasContention = true ;
7287
+ }
7288
+
7289
+ if ( name . StartsWith ( "WaitHandleWait/Start" ) )
7290
+ {
7291
+ hasWaitHandle = true ;
7292
+ }
7293
+
7240
7294
if ( counts . StackCount > 0 )
7241
7295
{
7242
7296
hasAnyStacks = true ;
@@ -7495,6 +7549,16 @@ protected override Action<Action> OpenImpl(Window parentWindow, StatusBar worker
7495
7549
}
7496
7550
}
7497
7551
7552
+ if ( hasContention )
7553
+ {
7554
+ advanced . Children . Add ( new PerfViewStackSource ( this , "Contention" ) ) ;
7555
+ }
7556
+
7557
+ if ( hasWaitHandle )
7558
+ {
7559
+ advanced . Children . Add ( new PerfViewStackSource ( this , "WaitHandleWait" ) ) ;
7560
+ }
7561
+
7498
7562
if ( hasAnyStacks )
7499
7563
{
7500
7564
advanced . Children . Add ( new PerfViewStackSource ( this , "Any" ) ) ;
@@ -8920,6 +8984,8 @@ protected override Action<Action> OpenImpl(Window parentWindow, StatusBar worker
8920
8984
bool hasMemAllocStacks = false ;
8921
8985
bool hasTypeLoad = false ;
8922
8986
bool hasAssemblyLoad = false ;
8987
+ bool hasContention = false ;
8988
+ bool hasWaitHandle = false ;
8923
8989
if ( m_traceLog != null )
8924
8990
{
8925
8991
foreach ( TraceEventCounts eventStats in m_traceLog . Stats )
@@ -8961,6 +9027,14 @@ protected override Action<Action> OpenImpl(Window parentWindow, StatusBar worker
8961
9027
{
8962
9028
hasAssemblyLoad = true ;
8963
9029
}
9030
+ else if ( eventStats . EventName . StartsWith ( "Contention/Start" ) )
9031
+ {
9032
+ hasContention = true ;
9033
+ }
9034
+ else if ( eventStats . EventName . StartsWith ( "WaitHandleWait/Start" ) )
9035
+ {
9036
+ hasWaitHandle = true ;
9037
+ }
8964
9038
}
8965
9039
}
8966
9040
@@ -9012,6 +9086,16 @@ protected override Action<Action> OpenImpl(Window parentWindow, StatusBar worker
9012
9086
{
9013
9087
advanced . AddChild ( new PerfViewRuntimeLoaderStats ( this ) ) ;
9014
9088
}
9089
+
9090
+ if ( hasContention )
9091
+ {
9092
+ advanced . AddChild ( new PerfViewStackSource ( this , "Contention" ) ) ;
9093
+ }
9094
+
9095
+ if ( hasWaitHandle )
9096
+ {
9097
+ advanced . AddChild ( new PerfViewStackSource ( this , "WaitHandleWait" ) ) ;
9098
+ }
9015
9099
}
9016
9100
9017
9101
if ( memory . Children . Count > 0 )
@@ -9144,6 +9228,36 @@ protected internal override StackSource OpenStackSourceImpl(string streamName, T
9144
9228
stackSource . DoneAddingSamples ( ) ;
9145
9229
return stackSource ;
9146
9230
}
9231
+ case "Contention" :
9232
+ {
9233
+ var eventLog = GetTraceLog ( log ) ;
9234
+
9235
+ var contentionSource = new MutableTraceEventStackSource ( eventLog ) ;
9236
+ // EventPipe currently only has managed code stacks.
9237
+ contentionSource . OnlyManagedCodeStacks = true ;
9238
+ contentionSource . ShowUnknownAddresses = App . CommandLineArgs . ShowUnknownAddresses ;
9239
+ contentionSource . ShowOptimizationTiers = App . CommandLineArgs . ShowOptimizationTiers ;
9240
+
9241
+ var computer = new ContentionLatencyComputer ( eventLog , contentionSource ) ;
9242
+ computer . GenerateStacks ( ) ;
9243
+
9244
+ return contentionSource ;
9245
+ }
9246
+ case "WaitHandleWait" :
9247
+ {
9248
+ var eventLog = GetTraceLog ( log ) ;
9249
+
9250
+ var waitHandleWaitSource = new MutableTraceEventStackSource ( eventLog ) ;
9251
+ // EventPipe currently only has managed code stacks.
9252
+ waitHandleWaitSource . OnlyManagedCodeStacks = true ;
9253
+ waitHandleWaitSource . ShowUnknownAddresses = App . CommandLineArgs . ShowUnknownAddresses ;
9254
+ waitHandleWaitSource . ShowOptimizationTiers = App . CommandLineArgs . ShowOptimizationTiers ;
9255
+
9256
+ var computer = new WaitHandleWaitLatencyComputer ( eventLog , waitHandleWaitSource ) ;
9257
+ computer . GenerateStacks ( ) ;
9258
+
9259
+ return waitHandleWaitSource ;
9260
+ }
9147
9261
case "Thread Time (with StartStop Activities)" :
9148
9262
{
9149
9263
var eventLog = GetTraceLog ( log ) ;
@@ -9351,6 +9465,11 @@ protected internal override void ConfigureStackWindow(string stackSourceName, St
9351
9465
stackWindow . ComputeMaxInTopStats = true ;
9352
9466
}
9353
9467
9468
+ if ( stackSourceName == "Contention" || stackSourceName == "WaitHandleWait" )
9469
+ {
9470
+ ConfigureStackWindowForStartStopThreadTime ( stackWindow ) ;
9471
+ }
9472
+
9354
9473
if ( m_extraTopStats != null )
9355
9474
{
9356
9475
stackWindow . ExtraTopStats += " " + m_extraTopStats ;
0 commit comments