in_cpu: parenthesis to protect division by zero
@@ -106,13 +106,7 @@ static inline double CPU_METRIC_SYS_AVERAGE(unsigned long pre, unsigned long now
}
diff = ULL_ABS(now, pre);
-
- if (ctx->interval_sec > 0) {
- total = ((diff / ctx->cpu_ticks) * 100) / ctx->n_processors / ctx->interval_sec;
- }
- else {
- total = ((diff / ctx->cpu_ticks) * 100) / ctx->n_processors;
- }
+ total = (((diff / ctx->cpu_ticks) * 100) / ctx->n_processors) / ctx->interval_sec;
return total;
}
@@ -129,14 +123,7 @@ static inline double CPU_METRIC_USAGE(unsigned long pre, unsigned long now,
}
diff = ULL_ABS(now, pre);
-
- if (ctx->interval_sec > 0) {
- total = (diff * 100) / ctx->cpu_ticks / ctx->interval_sec;
- }
- else {
- total = (diff * 100) / ctx->cpu_ticks;
- }
-
+ total = ((diff * 100) / ctx->cpu_ticks) / ctx->interval_sec;
return total;
}
