Get rid of fio_version.h
[fio.git] / stat.c
diff --git a/stat.c b/stat.c
index e72148b49ad0825f3e154bda0a1a303715f70764..542e910606ff16043547aa57272bca45aa002b90 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\n", 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,12 +1102,59 @@ void show_run_stats(void)
        else if (!terse_output)
                show_disk_util(0);
 
-       free_disk_util();
-
        free(runstats);
        free(threadstats);
 }
 
+static void *__show_running_run_stats(void *arg)
+{
+       struct thread_data *td;
+       unsigned long long *rt;
+       struct timeval tv;
+       int i;
+
+       rt = malloc(thread_number * sizeof(unsigned long long));
+       fio_gettime(&tv, NULL);
+
+       for_each_td(td, i) {
+               rt[i] = mtime_since(&td->start, &tv);
+               if (td_read(td) && td->io_bytes[DDIR_READ])
+                       td->ts.runtime[DDIR_READ] += rt[i];
+               if (td_write(td) && td->io_bytes[DDIR_WRITE])
+                       td->ts.runtime[DDIR_WRITE] += rt[i];
+
+               update_rusage_stat(td);
+               td->ts.io_bytes[0] = td->io_bytes[0];
+               td->ts.io_bytes[1] = td->io_bytes[1];
+               td->ts.total_run_time = mtime_since(&td->epoch, &tv);
+       }
+
+       show_run_stats();
+
+       for_each_td(td, i) {
+               if (td_read(td) && td->io_bytes[DDIR_READ])
+                       td->ts.runtime[DDIR_READ] -= rt[i];
+               if (td_write(td) && td->io_bytes[DDIR_WRITE])
+                       td->ts.runtime[DDIR_WRITE] -= rt[i];
+       }
+
+       free(rt);
+       return NULL;
+}
+
+/*
+ * Called from signal handler. It _should_ be safe to just run this inline
+ * in the sig handler, but we should be disturbing the system less by just
+ * creating a thread to do it.
+ */
+void show_running_run_stats(void)
+{
+       pthread_t thread;
+
+       pthread_create(&thread, NULL, __show_running_run_stats, NULL);
+       pthread_detach(thread);
+}
+
 static inline void add_stat_sample(struct io_stat *is, unsigned long data)
 {
        double val = data;