Skip to content

Commit

Permalink
Use ConcurrentDictionary in runtimecounters test (#105520)
Browse files Browse the repository at this point in the history
* Use ConcurrentDictionary in runtimecounters test

Fixes #105443

* Fix build break
  • Loading branch information
jkotas authored and pull[bot] committed Nov 27, 2024
1 parent 64654da commit 2021051
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions src/tests/tracing/eventcounter/runtimecounters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.Diagnostics.Tracing;
using System.Threading;
Expand All @@ -15,35 +16,38 @@ public class RuntimeCounterListener : EventListener
{
public RuntimeCounterListener()
{
observedRuntimeCounters = new Dictionary<string, bool>() {
{ "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<string, bool>();
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<string, bool> observedRuntimeCounters;
private ConcurrentDictionary<string, bool> observedRuntimeCounters;

protected override void OnEventSourceCreated(EventSource source)
{
Expand All @@ -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<string, object> eventPayload = eventData.Payload[i] as IDictionary<string, object>;
Expand Down

0 comments on commit 2021051

Please sign in to comment.