summaryrefslogtreecommitdiff
path: root/blkparse.c
diff options
context:
space:
mode:
authorMing Zhang <blackmagic02881@gmail.com>2006-12-21 08:39:55 +0100
committerJens Axboe <jens.axboe@oracle.com>2006-12-21 08:39:55 +0100
commit8a82e321006f3a44d766a53d34f60a472375b8fc (patch)
treeaf15edb3e3bd71e1fc04e357c573982da2619eef /blkparse.c
parent67076cbc20112afd833a2d04cd8f1c8d2fbcfaeb (diff)
downloadblktrace-8a82e321006f3a44d766a53d34f60a472375b8fc.tar.gz
blktrace-8a82e321006f3a44d766a53d34f60a472375b8fc.tar.bz2
[PATCH] fix a divide by zero error
When pdi->events and pdi->seq_skips are both 0, current code will do 0/0. Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'blkparse.c')
-rw-r--r--blkparse.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/blkparse.c b/blkparse.c
index cbb422f..b4c371a 100644
--- a/blkparse.c
+++ b/blkparse.c
@@ -1615,6 +1615,7 @@ static void show_device_and_cpu_stats(void)
int i, j, pci_events;
char line[3 + 8/*cpu*/ + 2 + 32/*dev*/ + 3];
char name[32];
+ double ratio;
for (pdi = devices, i = 0; i < ndevices; i++, pdi++) {
@@ -1674,10 +1675,13 @@ static void show_device_and_cpu_stats(void)
get_dev_name(pdi, line, sizeof(line)), pdi->events);
collect_pdi_skips(pdi);
+ if (!pdi->skips && !pdi->events)
+ ratio = 0.0;
+ else
+ ratio = 100.0 * ((double)pdi->seq_skips /
+ (double)(pdi->events + pdi->seq_skips));
fprintf(ofp, "Skips: %'lu forward (%'llu - %5.1lf%%)\n",
- pdi->skips,pdi->seq_skips,
- 100.0 * ((double)pdi->seq_skips /
- (double)(pdi->events + pdi->seq_skips)));
+ pdi->skips, pdi->seq_skips, ratio);
}
}