51509777e8
from upstream git
26 lines
1.3 KiB
Plaintext
26 lines
1.3 KiB
Plaintext
$OpenBSD: patch-src_print_cpu_usage_c,v 1.3 2012/07/07 09:43:54 jasper Exp $
|
|
|
|
Avoid division by zero when calculating CPU usage.
|
|
Upstream git 859a7690a6472ca6d700d29693d986125d11e4b6
|
|
|
|
--- src/print_cpu_usage.c.orig Fri May 11 22:38:26 2012
|
|
+++ src/print_cpu_usage.c Sat Jul 7 11:41:55 2012
|
|
@@ -40,7 +40,7 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer,
|
|
curr_total = curr_user + curr_nice + curr_system + curr_idle;
|
|
diff_idle = curr_idle - prev_idle;
|
|
diff_total = curr_total - prev_total;
|
|
- diff_usage = (1000 * (diff_total - diff_idle)/diff_total + 5)/10;
|
|
+ diff_usage = (diff_total ? (1000 * (diff_total - diff_idle)/diff_total + 5)/10 : 0);
|
|
prev_total = curr_total;
|
|
prev_idle = curr_idle;
|
|
#elif defined(__FreeBSD__) || defined(__OpenBSD__)
|
|
@@ -71,7 +71,7 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer,
|
|
curr_total = curr_user + curr_nice + curr_system + curr_idle;
|
|
diff_idle = curr_idle - prev_idle;
|
|
diff_total = curr_total - prev_total;
|
|
- diff_usage = (1000 * (diff_total - diff_idle)/diff_total + 5)/10;
|
|
+ diff_usage = (diff_total ? (1000 * (diff_total - diff_idle)/diff_total + 5)/10 : 0);
|
|
prev_total = curr_total;
|
|
prev_idle = curr_idle;
|
|
#else
|