bde icon indicating copy to clipboard operation
bde copied to clipboard

PerformanceMonitor::Statistics::d_minData[e_CPU_UTIL_*] is always 0.0

Open jilinzhou opened this issue 5 months ago • 1 comments

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<double>::max());
...
}

int PerformanceMonitor::Collector<bsls::Platform::OsLinux>
::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];
        }
    }

jilinzhou avatar Aug 29 '25 14:08 jilinzhou