Skip to content

Commit

Permalink
Treat enable with interval as 0 as disable
Browse files Browse the repository at this point in the history
  • Loading branch information
davmason committed Mar 23, 2023
1 parent 0313b10 commit 5b39139
Showing 1 changed file with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,26 @@ private void OnEventSourceCommand(object? sender, EventCommandEventArgs e)
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;
}

EnableTimer(intervalValue);
if (intervalValue > 0)
{
Debug.Assert(_refCount >= 0);
++_refCount;
EnableTimer(intervalValue);
}
else
{
Debug.Assert(_refCount >= 1);
--_refCount;
DisableTimer();
}
}
else if (e.Command == EventCommand.Disable)
{
Expand Down Expand Up @@ -140,11 +149,7 @@ internal static CounterGroup GetCounterGroup(EventSource eventSource)
private void EnableTimer(float pollingIntervalInSeconds)
{
Debug.Assert(Monitor.IsEntered(s_counterGroupLock));
if (pollingIntervalInSeconds <= 0)
{
DisableTimer();
}
else if (_pollingIntervalInMilliseconds == 0 || pollingIntervalInSeconds * 1000 < _pollingIntervalInMilliseconds)
if (pollingIntervalInSeconds * 1000 < _pollingIntervalInMilliseconds)
{
_pollingIntervalInMilliseconds = (int)(pollingIntervalInSeconds * 1000);
ResetCounters(); // Reset statistics for counters before we start the thread.
Expand Down

0 comments on commit 5b39139

Please sign in to comment.