PerformanceMonitor::Statistics::d_minData[e_CPU_UTIL_*] is always 0.0
- Dominant language
- C++
- Stars
- 1.8k
- Forks
- 342
- PR merge metrics
- No merged PRs in 30d
Description
Here is the code snippet and the comments are inlined:
```
void PerformanceMonitor::Statistics::reset()
{
...
bsl::fill(d_minData,
d_minData + e_NUM_MEASURES,
bsl::numeric_limits::max());
...
}
int PerformanceMonitor::Collector
::collect(Statistics *stats)
{
...
if ((stats->d_numSamples != 0) && (dt > 0)) {
stats->d_lstData[e_CPU_UTIL] = deltaCpuTimeT / dt * 100.0;
stats->d_lstData[e_CPU_UTIL_USER] = deltaCpuTimeU / dt * 100.0;
stats->d_lstData[e_CPU_UTIL_SYSTEM] = deltaCpuTimeS / dt * 100.0;
}
else {
// comments: On the first call of the function, since d_numSamples is 0, these measures are set to 0.
stats->d_lstData[e_CPU_UTIL] = 0;
stats->d_lstData[e_CPU_UTIL_USER] = 0;
stats->d_lstData[e_CPU_UTIL_SYSTEM] = 0;
}
...
++stats->d_numSamples;
...
for (int i = 0; i < e_NUM_MEASURES; ++i) {
if (s_measureData[i].hasAverage) {
// Comments: Once d_minData[e_CPU_UTIL], d_minData[e_CPU_UTIL_USER], and d_minData[e_CPU_SYSTEM]
// are set to 0 on the first call of the function, they will remain 0 indefinitely, even if future measurements in
// d_lstData[e_CPU_UTIL_*] are non-zero.
stats->d_minData[i] = bsl::min(stats->d_minData[i],
stats->d_lstData[i]);
stats->d_maxData[i] = bsl::max(stats->d_maxData[i],
stats->d_lstData[i]);
stats->d_totData[i] += stats->d_lstData[i];
}
}
```
Contributor guide
Research direction
Start by locating PerformanceMonitor::Statistics::reset() and Collector::collect(). Trace the first collection and the min/max accumulation for e_CPU_UTIL, e_CPU_UTIL_USER, and e_CPU_UTIL_SYSTEM; done means later non-zero measurements can produce correct minimum values instead of remaining at zero.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100