Skip to content

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

Description

@jilinzhou

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];
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions