Free disk util on exit, not on stats display
[fio.git] / stat.c
diff --git a/stat.c b/stat.c
index 68744281a92de519cbb1f350fb459dfcca517cfd..7443e665deb6c5a2c1869920a5f022f25969e5d9 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -782,11 +782,12 @@ static void show_thread_status_terse_v3(struct thread_stat *ts,
        /* Additional output if continue_on_error set - default off*/
        if (ts->continue_on_error)
                log_info(";%lu;%d", ts->total_err_count, ts->first_error);
-       log_info("\n");
 
        /* Additional output if description is set */
        if (strlen(ts->description))
                log_info(";%s", ts->description);
+
+       log_info("\n");
 }
 
 static void show_thread_status_terse(struct thread_stat *ts,
@@ -1044,10 +1045,11 @@ void show_run_stats(void)
 
                        bw = 0;
                        if (ts->runtime[j]) {
-                               unsigned long runt;
+                               unsigned long runt = ts->runtime[j];
+                               unsigned long long kb;
 
-                               runt = ts->runtime[j];
-                               bw = ts->io_bytes[j] / runt;
+                               kb = ts->io_bytes[j] / rs->kb_base;
+                               bw = kb * 1000 / runt;
                        }
                        if (bw < rs->min_bw[j])
                                rs->min_bw[j] = bw;
@@ -1059,16 +1061,12 @@ void show_run_stats(void)
        }
 
        for (i = 0; i < groupid + 1; i++) {
-               unsigned long max_run[2];
-
                rs = &runstats[i];
-               max_run[0] = rs->max_run[0];
-               max_run[1] = rs->max_run[1];
 
                if (rs->max_run[0])
-                       rs->agg[0] = (rs->io_kb[0] * 1000) / max_run[0];
+                       rs->agg[0] = (rs->io_kb[0] * 1000) / rs->max_run[0];
                if (rs->max_run[1])
-                       rs->agg[1] = (rs->io_kb[1] * 1000) / max_run[1];
+                       rs->agg[1] = (rs->io_kb[1] * 1000) / rs->max_run[1];
        }
 
        /*
@@ -1104,8 +1102,6 @@ void show_run_stats(void)
        else if (!terse_output)
                show_disk_util(0);
 
-       free_disk_util();
-
        free(runstats);
        free(threadstats);
 }
@@ -1291,8 +1287,8 @@ void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
        spent = mtime_since(&td->bw_sample_time, t);
        if (spent < td->o.bw_avg_time)
                return;
-       
-       /* 
+
+       /*
         * Compute both read and write rates for the interval.
         */
        for (ddir = DDIR_READ; ddir <= DDIR_WRITE; ddir++) {
@@ -1327,13 +1323,24 @@ void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,
        if (spent < td->o.iops_avg_time)
                return;
 
-       iops = ((td->this_io_blocks[ddir] - td->stat_io_blocks[ddir]) * 1000) / spent;
+       /*
+        * Compute both read and write rates for the interval.
+        */
+       for (ddir = DDIR_READ; ddir <= DDIR_WRITE; ddir++) {
+               uint64_t delta;
+
+               delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir];
+               if (!delta)
+                       continue; /* No entries for interval */
 
-       add_stat_sample(&ts->iops_stat[ddir], iops);
+               iops = (delta * 1000) / spent;
+               add_stat_sample(&ts->iops_stat[ddir], iops);
 
-       if (td->iops_log)
-               add_log_sample(td, td->iops_log, iops, ddir, 0);
+               if (td->iops_log)
+                       add_log_sample(td, td->iops_log, iops, ddir, 0);
+
+               td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
+       }
 
        fio_gettime(&td->iops_sample_time, NULL);
-       td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
 }