Merge branch 'cufile' of https://github.com/SystemFabricWorks/fio
[fio.git] / stat.c
diff --git a/stat.c b/stat.c
index 23657cee6a7702c3aacd81783acb1516b3960a1b..b723795301cc4c9bb3e71ad31450b6a6af97366b 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1078,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);
 
@@ -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,6 +2350,8 @@ void __show_running_run_stats(void)
 
        free(rt);
        fio_sem_up(stat_sem);
+
+       return 0;
 }
 
 static bool status_file_disabled;
@@ -2536,6 +2536,14 @@ void regrow_logs(struct thread_data *td)
        td->flags &= ~TD_F_REGROW_LOGS;
 }
 
+void regrow_agg_logs(void)
+{
+       enum fio_ddir ddir;
+
+       for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++)
+               regrow_log(agg_io_log[ddir]);
+}
+
 static struct io_logs *get_cur_log(struct io_log *iolog)
 {
        struct io_logs *cur_log;
@@ -2739,7 +2747,8 @@ static unsigned long add_log_sample(struct thread_data *td,
 
        __add_stat_to_log(iolog, ddir, elapsed, td->o.log_max != 0, priority_bit);
 
-       iolog->avg_last[ddir] = elapsed - (this_window - iolog->avg_msec);
+       iolog->avg_last[ddir] = elapsed - (elapsed % iolog->avg_msec);
+
        return iolog->avg_msec;
 }
 
@@ -2977,7 +2986,7 @@ static int __add_samples(struct thread_data *td, struct timespec *parent_tv,
        next_log = avg_time;
 
        spent = mtime_since(parent_tv, t);
-       if (spent < avg_time && avg_time - spent >= LOG_MSEC_SLACK)
+       if (spent < avg_time && avg_time - spent > LOG_MSEC_SLACK)
                return avg_time - spent;
 
        if (needs_lock)
@@ -3070,13 +3079,16 @@ static int add_iops_samples(struct thread_data *td, struct timespec *t)
 int calc_log_samples(void)
 {
        struct thread_data *td;
-       unsigned int next = ~0U, tmp;
+       unsigned int next = ~0U, tmp = 0, next_mod = 0, log_avg_msec_min = -1U;
        struct timespec now;
        int i;
+       long elapsed_time = 0;
 
        fio_gettime(&now, NULL);
 
        for_each_td(td, i) {
+               elapsed_time = mtime_since_now(&td->epoch);
+
                if (!td->o.stats)
                        continue;
                if (in_ramp_time(td) ||
@@ -3087,17 +3099,34 @@ int calc_log_samples(void)
                if (!td->bw_log ||
                        (td->bw_log && !per_unit_log(td->bw_log))) {
                        tmp = add_bw_samples(td, &now);
-                       if (tmp < next)
-                               next = tmp;
+
+                       if (td->bw_log)
+                               log_avg_msec_min = min(log_avg_msec_min, (unsigned int)td->bw_log->avg_msec);
                }
                if (!td->iops_log ||
                        (td->iops_log && !per_unit_log(td->iops_log))) {
                        tmp = add_iops_samples(td, &now);
-                       if (tmp < next)
-                               next = tmp;
+
+                       if (td->iops_log)
+                               log_avg_msec_min = min(log_avg_msec_min, (unsigned int)td->iops_log->avg_msec);
                }
+
+               if (tmp < next)
+                       next = tmp;
        }
 
+       /* if log_avg_msec_min has not been changed, set it to 0 */
+       if (log_avg_msec_min == -1U)
+               log_avg_msec_min = 0;
+
+       if (log_avg_msec_min == 0)
+               next_mod = elapsed_time;
+       else
+               next_mod = elapsed_time % log_avg_msec_min;
+
+       /* correction to keep the time on the log avg msec boundary */
+       next = min(next, (log_avg_msec_min - next_mod));
+
        return next == ~0U ? 0 : next;
 }