Fix integer overflow in rate_iops
[fio.git] / stat.c
diff --git a/stat.c b/stat.c
index 533981fcc89ac20d9297808d8c88ec2b69617202..00eb75d7c6c2150254d51aa145ae97ca34679f22 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -13,6 +13,7 @@
 #include "json.h"
 #include "lib/getrusage.h"
 #include "idletime.h"
+#include "lib/pow2.h"
 
 struct fio_mutex *stat_mutex;
 
@@ -509,7 +510,9 @@ static int block_state_category(int block_state)
        case BLOCK_STATE_TRIM_FAILURE:
                return 2;
        default:
+               /* Silence compile warning on some BSDs and have a return */
                assert(0);
+               return -1;
        }
 }
 
@@ -1059,17 +1062,26 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
                                    struct group_run_stats *rs)
 {
        struct json_object *root, *tmp;
+       struct jobs_eta *je;
        double io_u_dist[FIO_IO_U_MAP_NR];
        double io_u_lat_u[FIO_IO_U_LAT_U_NR];
        double io_u_lat_m[FIO_IO_U_LAT_M_NR];
        double usr_cpu, sys_cpu;
        int i;
+       size_t size;
+
 
        root = json_create_object();
        json_object_add_value_string(root, "jobname", ts->name);
        json_object_add_value_int(root, "groupid", ts->groupid);
        json_object_add_value_int(root, "error", ts->error);
 
+       /* ETA Info */
+       je = get_jobs_eta(1, &size);
+       json_object_add_value_int(root, "eta", je->eta_sec);
+       json_object_add_value_int(root, "elapsed", je->elapsed_sec);
+
+
        add_ddir_status_json(ts, rs, DDIR_READ, root);
        add_ddir_status_json(ts, rs, DDIR_WRITE, root);
        add_ddir_status_json(ts, rs, DDIR_TRIM, root);
@@ -1369,7 +1381,7 @@ void __show_run_stats(void)
        struct group_run_stats *runstats, *rs;
        struct thread_data *td;
        struct thread_stat *threadstats, *ts;
-       int i, j, nr_ts, last_ts, idx;
+       int i, j, k, nr_ts, last_ts, idx;
        int kb_base_warned = 0;
        int unit_base_warned = 0;
        struct json_object *root = NULL;
@@ -1481,8 +1493,8 @@ void __show_run_stats(void)
                ts->latency_window = td->o.latency_window;
 
                ts->nr_block_infos = td->ts.nr_block_infos;
-               for (i = 0; i < ts->nr_block_infos; i++)
-                       ts->block_infos[i] = td->ts.block_infos[i];
+               for (k = 0; k < ts->nr_block_infos; k++)
+                       ts->block_infos[k] = td->ts.block_infos[k];
 
                sum_thread_stats(ts, &td->ts, idx);
        }
@@ -1959,6 +1971,8 @@ void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
        if (!ddir_rw(ddir))
                return;
 
+       td_io_u_lock(td);
+
        add_stat_sample(&ts->clat_stat[ddir], usec);
 
        if (td->clat_log)
@@ -1966,6 +1980,8 @@ void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
 
        if (ts->clat_percentiles)
                add_clat_percentile_sample(ts, usec, ddir);
+
+       td_io_u_unlock(td);
 }
 
 void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
@@ -1976,10 +1992,14 @@ void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
        if (!ddir_rw(ddir))
                return;
 
+       td_io_u_lock(td);
+
        add_stat_sample(&ts->slat_stat[ddir], usec);
 
        if (td->slat_log)
                add_log_sample(td, td->slat_log, usec, ddir, bs, offset);
+
+       td_io_u_unlock(td);
 }
 
 void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
@@ -1990,10 +2010,14 @@ void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
        if (!ddir_rw(ddir))
                return;
 
+       td_io_u_lock(td);
+
        add_stat_sample(&ts->lat_stat[ddir], usec);
 
        if (td->lat_log)
                add_log_sample(td, td->lat_log, usec, ddir, bs, offset);
+
+       td_io_u_unlock(td);
 }
 
 void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,