From: Christian Heinrich Date: Fri, 10 Mar 2017 10:36:25 +0000 (+0100) Subject: [ENERGY] Use a local variable instead of making the same call twice X-Git-Tag: v3_15~160 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/700d4eee4a8f298501562f8a55686b371763d0ed [ENERGY] Use a local variable instead of making the same call twice --- diff --git a/src/surf/plugins/host_energy.cpp b/src/surf/plugins/host_energy.cpp index a84acc799b..47b3f50d2e 100644 --- a/src/surf/plugins/host_energy.cpp +++ b/src/surf/plugins/host_energy.cpp @@ -104,12 +104,13 @@ void HostEnergy::update() double start_time = this->last_updated; double finish_time = surf_get_clock(); double cpu_load; - if (host->pimpl_cpu->getPstateSpeedCurrent() <= 0) + double current_speed = host->pimpl_cpu->getPstateSpeedCurrent(); + if (current_speed <= 0) // Some users declare a pstate of speed 0 flops (e.g., to model boot time). // We consider that the machine is then fully loaded. That's arbitrary but it avoids a NaN cpu_load = 1; else - cpu_load = lmm_constraint_get_usage(host->pimpl_cpu->constraint()) / host->pimpl_cpu->getPstateSpeedCurrent(); + cpu_load = lmm_constraint_get_usage(host->pimpl_cpu->constraint()) / current_speed; /** Divide by the number of cores here **/ cpu_load /= host->pimpl_cpu->coreCount();