]> xenbits.xensource.com Git - people/dariof/xen.git/commitdiff
xenbaked.c: Avoid divide by zero issue
authorJoe Jin <joe.jin@ORACLE.COM>
Wed, 14 Mar 2018 17:14:03 +0000 (10:14 -0700)
committerWei Liu <wei.liu2@citrix.com>
Thu, 22 Mar 2018 09:04:23 +0000 (09:04 +0000)
xenbaked.c -> dump_stats(), run_time = time(&end_time) - time(&start_time),
time() returns the value in seconds. If one cancels xenmon.py immediately
after started, run_time can be zero, and then xenbaked will hit divide by
zero fault.

Signed-off-by: Joe Jin <joe.jin@oracle.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
tools/xenmon/xenbaked.c

index 3d9e0ed90043ef775bcf03d3363f16b2ca6218a5..d3f940a26bb27599e4c81e20e90526c05573c91f 100644 (file)
@@ -243,10 +243,12 @@ static void dump_stats(void)
     }
 
     printf("processed %d total records in %d seconds (%ld per second)\n",
-           rec_count, (int)run_time, (long)(rec_count/run_time));
+           rec_count, (int)run_time,
+           run_time ? (long)(rec_count/run_time) : 0L);
 
-    printf("woke up %d times in %d seconds (%ld per second)\n", wakeups,
-          (int) run_time, (long)(wakeups/run_time));
+    printf("woke up %d times in %d seconds (%ld per second)\n",
+           wakeups, (int) run_time,
+           run_time ? (long)(wakeups/run_time) : 0L);
 
     check_gotten_sum();
 }