Wrong performance counters?

Probably a rookie mistake, but I'm getting something weird. I am trying to weave a .NET performance counter into an application.

When I call a method incrementBy(value)on my avg performance counter, it also changes the RawValue of my base counter to a value. I checked the variable names and thought that everything was correct.

Then, when I call increment()on my base counter, it adds 1 to the original avgcounter value, and also increments the base counter ... adding insult to injury!

Has anyone else seen this behavior? Any suggestions on what is happening and how to fix it?

In the code, I use two different counters to measure the merge sort time I wrote. I have an instant counter for elapsed sorting time and an average counter.

Dim timePiece As New Stopwatch()

timePiece.Start()
MergeSort()
timePiece.Stop()

ElapsedCounter.RawValue = timePiece.ElapsedMilliseconds
AvgCounter.IncrementBy(timePiece.ElapsedMilliseconds)
AvgCounterBase.Increment()

What I see is:

'Elapsed counter works as expected  
'AvgCounter RawValue is 7, AvgCounterBase RawValue is also 7 before incrementing
 AvgCounter.IncrementBy (value) 'AvgCounter.RV is 7 + value, AvgCounterBase is 7 + value   
 AvgCounterBase.Increment () 'AvgCounter.RV is 7 + value + 1, AvgCounterBase is 7 + value + 1  

I think that I can use the counters incorrectly, but why does changing the initial value of the average also seem to change the original value of the base? I do not think this should happen.

+3
source share
1 answer

. Increment IncrementBy - , , , , RawValue. , :

counterVariable.RawValue++;
counterVariable.RawValue += 2;

:

counterVariable.Increment();
counterVariable.IncrementBy(2);

, RawValue .

+1

Source: https://habr.com/ru/post/1713369/


All Articles