Before the integer arithmetic is performed to obtain
percentage of aggregation this conversion of rs->agg[ddir] into KBytes
could potentially turn out to be 0.
Adjust stat.c to no longer trigger division by zero on bandwidths
greater than 0 but less than 1kilobyte a second. The fact that this
is performed on multiple occasions, a function is preferred
Signed-off-by: sribs <sribs@microsoft.com>
+static double convert_agg_kbytes_percent(struct group_run_stats *rs, int ddir, int mean)
+{
+ double p_of_agg = 100.0;
+ if (rs && rs->agg[ddir] > 1024) {
+ p_of_agg = mean * 100 / (double) (rs->agg[ddir] / 1024.0);
+
+ if (p_of_agg > 100.0)
+ p_of_agg = 100.0;
+ }
+ return p_of_agg;
+}
+
static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
int ddir, struct buf_output *out)
{
static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
int ddir, struct buf_output *out)
{
- if (rs->agg[ddir]) {
- p_of_agg = mean * 100 / (double) (rs->agg[ddir] / 1024);
- if (p_of_agg > 100.0)
- p_of_agg = 100.0;
- }
+ p_of_agg = convert_agg_kbytes_percent(rs, ddir, mean);
if (rs->unit_base == 1) {
min *= 8.0;
if (rs->unit_base == 1) {
min *= 8.0;
}
if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
}
if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
- if (rs->agg[ddir]) {
- p_of_agg = mean * 100 / (double) (rs->agg[ddir] / 1024);
- if (p_of_agg > 100.0)
- p_of_agg = 100.0;
- }
+ p_of_agg = convert_agg_kbytes_percent(rs, ddir, mean);
} else {
min = max = 0;
p_of_agg = mean = dev = 0.0;
} else {
min = max = 0;
p_of_agg = mean = dev = 0.0;
assert(idx < td->ts.nr_block_infos);
return info;
}
assert(idx < td->ts.nr_block_infos);
return info;
}