Skip to content

Commit fb98ef9

Browse files
committed
Reset counters within Timer thread
1 parent 81976ed commit fb98ef9

File tree

1 file changed

+7
-1
lines changed
  • src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing

1 file changed

+7
-1
lines changed

src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/CounterGroup.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ internal sealed class CounterGroup
1717
private readonly EventSource _eventSource;
1818
private readonly List<DiagnosticCounter> _counters;
1919
private static readonly object s_counterGroupLock = new object();
20+
private bool _resetCounters = true;
2021

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

160160
_timeStampSinceCollectionStarted = DateTime.UtcNow;
161161
_nextPollingTimeStamp = DateTime.UtcNow + new TimeSpan(0, 0, (int)pollingIntervalInSeconds);
@@ -223,6 +223,12 @@ private void OnTimer()
223223
DiagnosticCounter[] counters;
224224
lock (s_counterGroupLock)
225225
{
226+
if (_resetCounters)
227+
{
228+
ResetCounters();
229+
_resetCounters = false;
230+
}
231+
226232
now = DateTime.UtcNow;
227233
elapsed = now - _timeStampSinceCollectionStarted;
228234
pollingIntervalInMilliseconds = _pollingIntervalInMilliseconds;

0 commit comments

Comments
 (0)