From ef1ccabecb0296528443eefbd390c648ab59876b Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 25 Jul 2024 22:57:44 -0700 Subject: [PATCH] Use ConcurrentDictionary in runtimecounters test (#105520) * Use ConcurrentDictionary in runtimecounters test Fixes #105443 * Fix build break --- .../tracing/eventcounter/runtimecounters.cs | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/tests/tracing/eventcounter/runtimecounters.cs b/src/tests/tracing/eventcounter/runtimecounters.cs index 35ed40ad58817..ccdaf02f0c776 100644 --- a/src/tests/tracing/eventcounter/runtimecounters.cs +++ b/src/tests/tracing/eventcounter/runtimecounters.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Collections.Concurrent; using System.Diagnostics; using System.Diagnostics.Tracing; using System.Threading; @@ -15,35 +16,38 @@ public class RuntimeCounterListener : EventListener { public RuntimeCounterListener() { - observedRuntimeCounters = new Dictionary() { - { "cpu-usage" , false }, - { "working-set", false }, - { "gc-heap-size", false }, - { "gen-0-gc-count", false }, - { "gen-1-gc-count", false }, - { "gen-2-gc-count", false }, - { "threadpool-thread-count", false }, - { "monitor-lock-contention-count", false }, - { "threadpool-queue-length", false }, - { "threadpool-completed-items-count", false }, - { "alloc-rate", false }, - { "active-timer-count", false }, - { "gc-fragmentation", false }, - { "gc-committed", false }, - { "exception-count", false }, - { "time-in-gc", false }, - { "gen-0-size", false }, - { "gen-1-size", false }, - { "gen-2-size", false }, - { "loh-size", false }, - { "poh-size", false }, - { "assembly-count", false }, - { "il-bytes-jitted", false }, - { "methods-jitted-count", false }, - { "time-in-jit", false } - }; + observedRuntimeCounters = new ConcurrentDictionary(); + foreach (string counter in new string[] { + "cpu-usage", + "working-set", + "gc-heap-size", + "gen-0-gc-count", + "gen-1-gc-count", + "gen-2-gc-count", + "threadpool-thread-count", + "monitor-lock-contention-count", + "threadpool-queue-length", + "threadpool-completed-items-count", + "alloc-rate", + "active-timer-count", + "gc-fragmentation", + "gc-committed", + "exception-count", + "time-in-gc", + "gen-0-size", + "gen-1-size", + "gen-2-size", + "loh-size", + "poh-size", + "assembly-count", + "il-bytes-jitted", + "methods-jitted-count", + "time-in-jit" }) + { + observedRuntimeCounters[counter] = false; + } } - private Dictionary observedRuntimeCounters; + private ConcurrentDictionary observedRuntimeCounters; protected override void OnEventSourceCreated(EventSource source) { @@ -59,7 +63,6 @@ protected override void OnEventSourceCreated(EventSource source) protected override void OnEventWritten(EventWrittenEventArgs eventData) { - for (int i = 0; i < eventData.Payload.Count; i++) { IDictionary eventPayload = eventData.Payload[i] as IDictionary;