]> granicus.if.org Git - sysstat/commitdiff
mpstat: Check for possible division by zero
authorSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 1 Apr 2018 06:18:56 +0000 (08:18 +0200)
committerSebastien GODARD <sysstat@users.noreply.github.com>
Sun, 1 Apr 2018 06:18:56 +0000 (08:18 +0200)
Reassure Coverity by making sure that the total number of jiffies spent
by all processors/nodes is not zero.
This would be possible only if all processors were tickless.

Signed-off-by: Sebastien GODARD <sysstat@users.noreply.github.com>
mpstat.c

index 98e7a36cf49a6c74faaf4f9c49fc7a655460d3a0..d0e3059f177eadfe0dedc2159535575785b2dbaa 100644 (file)
--- a/mpstat.c
+++ b/mpstat.c
@@ -755,6 +755,11 @@ void write_cpu_stats(int dis, unsigned long long deltot_jiffies, int prev, int c
                     char *prev_string, char *curr_string, int tab, int *next,
                     unsigned char offline_cpu_bitmap[])
 {
+       if (!deltot_jiffies) {
+               /* CPU "all" cannot be tickless */
+               deltot_jiffies = 1;
+       }
+
        if (DISPLAY_JSON_OUTPUT(flags)) {
                if (*next) {
                        printf(",\n");
@@ -1014,6 +1019,11 @@ void write_json_node_stats(int tab, unsigned long long deltot_jiffies,
 void write_node_stats(int dis, unsigned long long deltot_jiffies, int prev, int curr,
                      char *prev_string, char *curr_string, int tab, int *next)
 {
+       if (!deltot_jiffies) {
+               /* CPU "all" cannot be tickless */
+               deltot_jiffies = 1;
+       }
+
        if (DISPLAY_JSON_OUTPUT(flags)) {
                if (*next) {
                        printf(",\n");