Fix typo, restore unintended HOWTO deletion
[fio.git] / stat.c
diff --git a/stat.c b/stat.c
index 96af94ba683deb5b4de2420e7fd04cf10e7b7d88..765c2b20249b8588d438e357c33f5165e02b2666 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1255,6 +1255,36 @@ static struct json_object *show_thread_status_json(struct thread_stat *ts,
                }
        }
 
+       /* steady state detection; move this behind json+? */
+       if (ts->ss) {
+               struct json_array *cache;
+               struct steadystate_data *ss = ts->ss;
+               int i, x;
+               char ss_option[64];
+
+               snprintf(ss_option, sizeof(ss_option), "%s%s:%f%s", 
+                       ss->check_iops ? "iops" : "bw",
+                       ss->check_slope ? "_slope" : "",
+                       (float) ss->limit,
+                       ss->pct ? "%" : "");
+
+               tmp = json_create_object();
+               json_object_add_value_object(root, "steadystate", tmp);
+               json_object_add_value_string(tmp, "ss", ss_option);
+               json_object_add_value_float(tmp, "limit", (float)ss->limit);
+               json_object_add_value_int(tmp, "duration", (int)ss->dur);
+               json_object_add_value_int(tmp, "steadystate_ramptime", ss->ramp_time / 1000000L);
+               json_object_add_value_int(tmp, "attained", ss->attained);
+               json_object_add_value_float(tmp, "criterion", ss->criterion);
+
+               cache = json_create_array();
+               json_object_add_value_array(tmp, "data", cache);
+               for (i = 0; i < ss->dur; i++) {
+                       x = (ss->head + i) % ss->dur;
+                       json_array_add_value_int(cache, ss->cache[x]);
+               }
+       }
+
        return root;
 }
 
@@ -1578,6 +1608,11 @@ void __show_run_stats(void)
                        ts->block_infos[k] = td->ts.block_infos[k];
 
                sum_thread_stats(ts, &td->ts, idx == 1);
+
+               if (td->o.ss_dur)
+                       ts->ss = &td->ss;
+               else
+                       ts->ss = NULL;
        }
 
        for (i = 0; i < nr_ts; i++) {
@@ -2211,28 +2246,36 @@ void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
                add_clat_percentile_sample(ts, usec, ddir);
 
        if (iolog && iolog->hist_msec) {
-               struct io_hist *hw = &(iolog->hist_window[ddir]);
-               (hw->samples)++;
+               struct io_hist *hw = &iolog->hist_window[ddir];
+
+               hw->samples++;
                elapsed = mtime_since_now(&td->epoch);
-               if (! hw->hist_last)
+               if (!hw->hist_last)
                        hw->hist_last = elapsed;
                this_window = elapsed - hw->hist_last;
                
                if (this_window >= iolog->hist_msec) {
+                       unsigned int *io_u_plat;
+                       unsigned int *dst;
+
                        /*
-                        * Make a byte-for-byte copy of the latency histogram stored in
-                        * td->ts.io_u_plat[ddir], recording it in a log sample. Note that
-                        * the matching call to free() is located in iolog.c after printing
-                        * this sample to the log file.
+                        * Make a byte-for-byte copy of the latency histogram
+                        * stored in td->ts.io_u_plat[ddir], recording it in a
+                        * log sample. Note that the matching call to free() is
+                        * located in iolog.c after printing this sample to the
+                        * log file.
                         */
-                       unsigned int *io_u_plat = (unsigned int *)(td->ts.io_u_plat[ddir]);
-                       unsigned int *dst = malloc(FIO_IO_U_PLAT_NR * sizeof(unsigned int));
-                       memcpy(dst, io_u_plat, FIO_IO_U_PLAT_NR * sizeof(unsigned int));
-                       __add_log_sample(iolog, (uint64_t)dst, ddir, bs, elapsed, offset);
+                       io_u_plat = (unsigned int *) td->ts.io_u_plat[ddir];
+                       dst = malloc(FIO_IO_U_PLAT_NR * sizeof(unsigned int));
+                       memcpy(dst, io_u_plat,
+                               FIO_IO_U_PLAT_NR * sizeof(unsigned int));
+                       __add_log_sample(iolog, (unsigned long )dst, ddir, bs,
+                                               elapsed, offset);
 
                        /*
-                        * Update the last time we recorded as being now, minus any drift
-                        * in time we encountered before actually making the record.
+                        * Update the last time we recorded as being now, minus
+                        * any drift in time we encountered before actually
+                        * making the record.
                         */
                        hw->hist_last = elapsed - (this_window - iolog->hist_msec);
                        hw->samples = 0;