Fixup json bandwidth output
[fio.git] / stat.c
diff --git a/stat.c b/stat.c
index c523f5c25a605759b055868e07d07d52a5a118fe..38c5d0238e33ef498c3edfceeca3bfd7740c7a4a 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -182,12 +182,12 @@ static unsigned int calc_clat_percentiles(unsigned int *io_u_plat,
  * Find and display the p-th percentile of clat
  */
 static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
  * Find and display the p-th percentile of clat
  */
 static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
-                                 fio_fp64_t *plist, uint64_t precision)
+                                 fio_fp64_t *plist, unsigned int precision)
 {
        unsigned int len, j = 0, minv, maxv;
        unsigned int *ovals;
 {
        unsigned int len, j = 0, minv, maxv;
        unsigned int *ovals;
-       int is_last, scale_down;
-       char buf1[32], buf2[32];
+       int is_last, per_line, scale_down;
+       char fmt[32];
 
        len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
        if (!len)
 
        len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
        if (!len)
@@ -205,22 +205,23 @@ static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
                log_info("    clat percentiles (usec):\n     |");
        }
 
                log_info("    clat percentiles (usec):\n     |");
        }
 
-       snprintf(buf1, sizeof(buf1), " %%1.%luf", precision);
-       snprintf(buf2, sizeof(buf1), "%%1.%luf", precision);
+       snprintf(fmt, sizeof(fmt), "%%1.%uf", precision);
+       per_line = (80 - 7) / (precision + 14);
+
        for (j = 0; j < len; j++) {
        for (j = 0; j < len; j++) {
-               char fbuf[16];
+               char fbuf[16], *ptr = fbuf;
 
                /* for formatting */
 
                /* for formatting */
-               if (j != 0 && (j % 4) == 0)
+               if (j != 0 && (j % per_line) == 0)
                        log_info("     |");
 
                /* end of the list */
                is_last = (j == len - 1);
 
                if (plist[j].u.f < 10.0)
                        log_info("     |");
 
                /* end of the list */
                is_last = (j == len - 1);
 
                if (plist[j].u.f < 10.0)
-                       snprintf(fbuf, sizeof(fbuf), buf1, plist[j].u.f);
-               else
-                       snprintf(fbuf, sizeof(fbuf), buf2, plist[j].u.f);
+                       ptr += sprintf(fbuf, " ");
+
+               snprintf(ptr, sizeof(fbuf), fmt, plist[j].u.f);
 
                if (scale_down)
                        ovals[j] = (ovals[j] + 999) / 1000;
 
                if (scale_down)
                        ovals[j] = (ovals[j] + 999) / 1000;
@@ -230,7 +231,7 @@ static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
                if (is_last)
                        break;
 
                if (is_last)
                        break;
 
-               if (j % 4 == 3) /* for formatting */
+               if ((j % per_line) == per_line - 1)     /* for formatting */
                        log_info("\n");
        }
 
                        log_info("\n");
        }
 
@@ -774,7 +775,7 @@ static void add_ddir_status_json(struct thread_stat *ts,
        if (ovals)
                free(ovals);
 
        if (ovals)
                free(ovals);
 
-       if (!calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
+       if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
                if (rs->agg[ddir]) {
                        p_of_agg = mean * 100 / (double) rs->agg[ddir];
                        if (p_of_agg > 100.0)
                if (rs->agg[ddir]) {
                        p_of_agg = mean * 100 / (double) rs->agg[ddir];
                        if (p_of_agg > 100.0)
@@ -1357,10 +1358,10 @@ void show_run_stats(void)
 
        if (is_backend)
                fio_server_send_du();
 
        if (is_backend)
                fio_server_send_du();
-       else if (output_format == FIO_OUTPUT_NORMAL)
+       else if (output_format == FIO_OUTPUT_NORMAL) {
                show_disk_util(0, NULL);
                show_disk_util(0, NULL);
-
-       show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL);
+               show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL);
+       }
 
        free(runstats);
        free(threadstats);
 
        free(runstats);
        free(threadstats);
@@ -1385,13 +1386,21 @@ static void *__show_running_run_stats(void *arg)
                if (td_trim(td) && td->io_bytes[DDIR_TRIM])
                        td->ts.runtime[DDIR_TRIM] += rt[i];
 
                if (td_trim(td) && td->io_bytes[DDIR_TRIM])
                        td->ts.runtime[DDIR_TRIM] += rt[i];
 
-               update_rusage_stat(td);
+               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];
                td->ts.total_run_time = mtime_since(&td->epoch, &tv);
        }
 
                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];
                td->ts.total_run_time = mtime_since(&td->epoch, &tv);
        }
 
+       for_each_td(td, i) {
+               if (td->rusage_sem) {
+                       td->update_rusage = 1;
+                       fio_mutex_down(td->rusage_sem);
+               }
+               td->update_rusage = 0;
+       }
+
        show_run_stats();
 
        for_each_td(td, i) {
        show_run_stats();
 
        for_each_td(td, i) {