microsoft / perfview

PerfView is a CPU and memory performance-analysis tool
http://channel9.msdn.com/Series/PerfView-Tutorial
MIT License
4.06k stars 696 forks source link

A bug in Histogram? #2006

Open JJLovesLife opened 4 months ago

JJLovesLife commented 4 months ago

I was looking around the source code and the following piece of code seems a bit buggy to me: https://github.com/microsoft/perfview/blob/c671d460fdd4abd915a96beb1410c8c7748432fb/src/TraceEvent/Stacks/Histogram.cs#L48-L68 Let's say the following sequence of AddMetric is called:

AddMetric(1.0f, 0);
AddMetric(2.0f, 1);
AddMetric(3.0f, 0);

The second time will cause the array to be constructed, and m_singleBucketValue is populated into the array. But within the third call, if (m_singleBucketNum == bucket) will still be true, and the metric is still added into m_singleBucketValue instead of the array. Inside the indexer: https://github.com/microsoft/perfview/blob/c671d460fdd4abd915a96beb1410c8c7748432fb/src/TraceEvent/Stacks/Histogram.cs#L119-L126 the m_singleBucketValue isn't used when the array is not null, causing the entry for m_singleBucketNum to be returned with incorrected value.

I don't have the whole knowledge of how Histogram is used, so I don't sure if this is really a bug. And this problem might not be a big issue due to the usage pattern, cause I don't see any bucket to be obviously wrong in the GUI.