Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit c7ebac4

Browse files
committed
fix(measurements): guard from negative cpu usage
1 parent f53b6f8 commit c7ebac4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

bindings/cpu_profiler.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,16 @@ void MeasurementsTicker::cpu_callback() {
169169
idle_total += core->cpu_times.idle;
170170
}
171171

172-
double total_avg = total / count;
173172
double idle_avg = idle_total / count;
173+
double total_avg = total / count;
174174
double rate = 1.0 - idle_avg / total_avg;
175175

176176
auto it = cpu_listeners.begin();
177+
178+
if(rate < 0.0) {
179+
rate = 0.0;
180+
}
181+
177182
while (it != cpu_listeners.end()) {
178183
if (it->second(ts, rate)) {
179184
it = cpu_listeners.erase(it);

0 commit comments

Comments
 (0)