Skip to content

Commit 0b1f89a

Browse files
jkotasdirecthex
authored andcommitted
Use ConcurrentDictionary in runtimecounters test (#105520)
* Use ConcurrentDictionary in runtimecounters test Fixes #105443 * Fix build break
1 parent 27dd261 commit 0b1f89a

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

src/tests/tracing/eventcounter/runtimecounters.cs

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Collections.Concurrent;
67
using System.Diagnostics;
78
using System.Diagnostics.Tracing;
89
using System.Threading;
@@ -15,35 +16,38 @@ public class RuntimeCounterListener : EventListener
1516
{
1617
public RuntimeCounterListener()
1718
{
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+
}
4549
}
46-
private Dictionary<string, bool> observedRuntimeCounters;
50+
private ConcurrentDictionary<string, bool> observedRuntimeCounters;
4751

4852
protected override void OnEventSourceCreated(EventSource source)
4953
{
@@ -59,7 +63,6 @@ protected override void OnEventSourceCreated(EventSource source)
5963

6064
protected override void OnEventWritten(EventWrittenEventArgs eventData)
6165
{
62-
6366
for (int i = 0; i < eventData.Payload.Count; i++)
6467
{
6568
IDictionary<string, object> eventPayload = eventData.Payload[i] as IDictionary<string, object>;

0 commit comments

Comments
 (0)