Skip to content

Commit

Permalink
Reset counters within Timer thread
Browse files Browse the repository at this point in the history
  • Loading branch information
eterekhin committed Jul 27, 2024
1 parent 81976ed commit fb98ef9
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal sealed class CounterGroup
private readonly EventSource _eventSource;
private readonly List<DiagnosticCounter> _counters;
private static readonly object s_counterGroupLock = new object();
private bool _resetCounters = true;

internal CounterGroup(EventSource eventSource)
{
Expand Down Expand Up @@ -155,7 +156,6 @@ private void EnableTimer(float pollingIntervalInSeconds)
if (_pollingIntervalInMilliseconds == 0 || pollingIntervalInSeconds * 1000 < _pollingIntervalInMilliseconds)
{
_pollingIntervalInMilliseconds = (int)(pollingIntervalInSeconds * 1000);
ResetCounters(); // Reset statistics for counters before we start the thread.

_timeStampSinceCollectionStarted = DateTime.UtcNow;
_nextPollingTimeStamp = DateTime.UtcNow + new TimeSpan(0, 0, (int)pollingIntervalInSeconds);
Expand Down Expand Up @@ -223,6 +223,12 @@ private void OnTimer()
DiagnosticCounter[] counters;
lock (s_counterGroupLock)
{
if (_resetCounters)
{
ResetCounters();
_resetCounters = false;
}

now = DateTime.UtcNow;
elapsed = now - _timeStampSinceCollectionStarted;
pollingIntervalInMilliseconds = _pollingIntervalInMilliseconds;
Expand Down

0 comments on commit fb98ef9

Please sign in to comment.