Merge branch 'master' of https://github.com/bvanassche/fio into master
[fio.git] / stat.c
diff --git a/stat.c b/stat.c
index efa811d2b70e5c23dd48ace87d19eb925fc31916..eb40bd7f44bb7c4c40c84fc5c70fa9648f996772 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -414,6 +414,18 @@ static void display_lat(const char *name, unsigned long long min,
        free(maxp);
 }
 
+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)
 {
@@ -551,11 +563,7 @@ static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
                else
                        bw_str = "kB";
 
-               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;
@@ -1070,12 +1078,10 @@ static void show_thread_status_normal(struct thread_stat *ts,
        if (strlen(ts->description))
                log_buf(out, "  Description  : [%s]\n", ts->description);
 
-       if (ts->io_bytes[DDIR_READ])
-               show_ddir_status(rs, ts, DDIR_READ, out);
-       if (ts->io_bytes[DDIR_WRITE])
-               show_ddir_status(rs, ts, DDIR_WRITE, out);
-       if (ts->io_bytes[DDIR_TRIM])
-               show_ddir_status(rs, ts, DDIR_TRIM, out);
+       for_each_rw_ddir(ddir) {
+               if (ts->io_bytes[ddir])
+                       show_ddir_status(rs, ts, ddir, out);
+       }
 
        show_latencies(ts, out);
 
@@ -1376,11 +1382,7 @@ static void add_ddir_status_json(struct thread_stat *ts,
        }
 
        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;
@@ -1506,12 +1508,8 @@ static void json_add_job_opts(struct json_object *root, const char *name,
        json_object_add_value_object(root, name, dir_object);
 
        flist_for_each(entry, opt_list) {
-               const char *pos = "";
-
                p = flist_entry(entry, struct print_option, list);
-               if (p->value)
-                       pos = p->value;
-               json_object_add_value_string(dir_object, p->name, pos);
+               json_object_add_value_string(dir_object, p->name, p->value);
        }
 }
 
@@ -2301,7 +2299,7 @@ void __show_run_stats(void)
        free(opt_lists);
 }
 
-void __show_running_run_stats(void)
+int __show_running_run_stats(void)
 {
        struct thread_data *td;
        unsigned long long *rt;
@@ -2315,9 +2313,9 @@ void __show_running_run_stats(void)
 
        for_each_td(td, i) {
                td->update_rusage = 1;
-               td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ];
-               td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
-               td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
+               for_each_rw_ddir(ddir) {
+                       td->ts.io_bytes[ddir] = td->io_bytes[ddir];
+               }
                td->ts.total_run_time = mtime_since(&td->epoch, &ts);
 
                rt[i] = mtime_since(&td->start, &ts);
@@ -2352,10 +2350,10 @@ void __show_running_run_stats(void)
 
        free(rt);
        fio_sem_up(stat_sem);
+
+       return 0;
 }
 
-static bool status_interval_init;
-static struct timespec status_time;
 static bool status_file_disabled;
 
 #define FIO_STATUS_FILE                "fio-dump-status"
@@ -2398,16 +2396,6 @@ static int check_status_file(void)
 
 void check_for_running_stats(void)
 {
-       if (status_interval) {
-               if (!status_interval_init) {
-                       fio_gettime(&status_time, NULL);
-                       status_interval_init = true;
-               } else if (mtime_since_now(&status_time) >= status_interval) {
-                       show_running_run_stats();
-                       fio_gettime(&status_time, NULL);
-                       return;
-               }
-       }
        if (check_status_file()) {
                show_running_run_stats();
                return;
@@ -3146,3 +3134,4 @@ uint32_t *io_u_block_info(struct thread_data *td, struct io_u *io_u)
        assert(idx < td->ts.nr_block_infos);
        return info;
 }
+