3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Collections . Concurrent ;
6
7
using System . Diagnostics ;
7
8
using System . Diagnostics . Tracing ;
8
9
using System . Threading ;
@@ -15,35 +16,38 @@ public class RuntimeCounterListener : EventListener
15
16
{
16
17
public RuntimeCounterListener ( )
17
18
{
18
- observedRuntimeCounters = new Dictionary < string , bool > ( ) {
19
- { "cpu-usage" , false } ,
20
- { "working-set" , false } ,
21
- { "gc-heap-size" , false } ,
22
- { "gen-0-gc-count" , false } ,
23
- { "gen-1-gc-count" , false } ,
24
- { "gen-2-gc-count" , false } ,
25
- { "threadpool-thread-count" , false } ,
26
- { "monitor-lock-contention-count" , false } ,
27
- { "threadpool-queue-length" , false } ,
28
- { "threadpool-completed-items-count" , false } ,
29
- { "alloc-rate" , false } ,
30
- { "active-timer-count" , false } ,
31
- { "gc-fragmentation" , false } ,
32
- { "gc-committed" , false } ,
33
- { "exception-count" , false } ,
34
- { "time-in-gc" , false } ,
35
- { "gen-0-size" , false } ,
36
- { "gen-1-size" , false } ,
37
- { "gen-2-size" , false } ,
38
- { "loh-size" , false } ,
39
- { "poh-size" , false } ,
40
- { "assembly-count" , false } ,
41
- { "il-bytes-jitted" , false } ,
42
- { "methods-jitted-count" , false } ,
43
- { "time-in-jit" , false }
44
- } ;
19
+ observedRuntimeCounters = new ConcurrentDictionary < string , bool > ( ) ;
20
+ foreach ( string counter in new string [ ] {
21
+ "cpu-usage" ,
22
+ "working-set" ,
23
+ "gc-heap-size" ,
24
+ "gen-0-gc-count" ,
25
+ "gen-1-gc-count" ,
26
+ "gen-2-gc-count" ,
27
+ "threadpool-thread-count" ,
28
+ "monitor-lock-contention-count" ,
29
+ "threadpool-queue-length" ,
30
+ "threadpool-completed-items-count" ,
31
+ "alloc-rate" ,
32
+ "active-timer-count" ,
33
+ "gc-fragmentation" ,
34
+ "gc-committed" ,
35
+ "exception-count" ,
36
+ "time-in-gc" ,
37
+ "gen-0-size" ,
38
+ "gen-1-size" ,
39
+ "gen-2-size" ,
40
+ "loh-size" ,
41
+ "poh-size" ,
42
+ "assembly-count" ,
43
+ "il-bytes-jitted" ,
44
+ "methods-jitted-count" ,
45
+ "time-in-jit" } )
46
+ {
47
+ observedRuntimeCounters [ counter ] = false ;
48
+ }
45
49
}
46
- private Dictionary < string , bool > observedRuntimeCounters ;
50
+ private ConcurrentDictionary < string , bool > observedRuntimeCounters ;
47
51
48
52
protected override void OnEventSourceCreated ( EventSource source )
49
53
{
@@ -59,7 +63,6 @@ protected override void OnEventSourceCreated(EventSource source)
59
63
60
64
protected override void OnEventWritten ( EventWrittenEventArgs eventData )
61
65
{
62
-
63
66
for ( int i = 0 ; i < eventData . Payload . Count ; i ++ )
64
67
{
65
68
IDictionary < string , object > eventPayload = eventData . Payload [ i ] as IDictionary < string , object > ;
0 commit comments