Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Ref count EventCounters
  • Loading branch information
davmason committed Mar 14, 2023
commit 8d03d71ef7c85d70b638c92fa4c6a77c985a6a03
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ internal sealed class CounterGroup
{
private readonly EventSource _eventSource;
private readonly List<DiagnosticCounter> _counters;
private int _refCount;
private static readonly object s_counterGroupLock = new object();

internal CounterGroup(EventSource eventSource)
{
_eventSource = eventSource;
_counters = new List<DiagnosticCounter>();
_refCount = 0;
RegisterCommandCallback();
}

Expand All @@ -46,23 +48,36 @@ private void RegisterCommandCallback()

private void OnEventSourceCommand(object? sender, EventCommandEventArgs e)
{
if (e.Command == EventCommand.Enable || e.Command == EventCommand.Update)
lock (s_counterGroupLock) // Lock the CounterGroup
{
Debug.Assert(e.Arguments != null);
if (e.Command == EventCommand.Enable)
{
Debug.Assert(e.Arguments != null);
Debug.Assert(_refCount >= 0);

++_refCount;
float intervalValue = 1.0f;
if (e.Arguments.TryGetValue("EventCounterIntervalSec", out string? valueStr)
&& float.TryParse(valueStr, out float value))
{
intervalValue = value;
}

if (e.Arguments.TryGetValue("EventCounterIntervalSec", out string? valueStr) && float.TryParse(valueStr, out float value))
EnableTimer(intervalValue);
}
else if (e.Command == EventCommand.Disable)
{
lock (s_counterGroupLock) // Lock the CounterGroup
Debug.Assert(_refCount >= 1);
--_refCount;
if (_refCount == 0)
{
EnableTimer(value);
DisableTimer();
}
}
}
else if (e.Command == EventCommand.Disable)
{
lock (s_counterGroupLock)
else
{
DisableTimer();
// Should only be enable or disable
Debug.Assert(false);
}
}
}
Expand Down