blob: 7e2feea25bc907ee41bf776bd4053ebfa01112bc [file] [log] [blame]
Jens Axboe3c39a372006-06-06 20:56:12 +02001#include <stdio.h>
2#include <string.h>
3#include <sys/time.h>
4#include <sys/types.h>
Jens Axboe5c4e1db2006-06-07 14:17:08 +02005#include <sys/stat.h>
Jens Axboe3c39a372006-06-06 20:56:12 +02006#include <dirent.h>
7#include <libgen.h>
8#include <math.h>
9
10#include "fio.h"
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020011#include "diskutil.h"
Jens Axboec7c6cb42011-10-13 14:12:40 +020012#include "lib/ieee754.h"
Shaohua Licc372b12012-09-17 09:12:18 +020013#include "json.h"
Jens Axboe44404c52013-01-24 14:20:09 -070014#include "lib/getrusage.h"
Huadong Liuf2a2ce02013-01-30 13:22:24 +010015#include "idletime.h"
Jens Axboe3c39a372006-06-06 20:56:12 +020016
Jens Axboe3c39a372006-06-06 20:56:12 +020017void update_rusage_stat(struct thread_data *td)
18{
Jens Axboe756867b2007-03-06 15:19:24 +010019 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +020020
Jens Axboe44404c52013-01-24 14:20:09 -070021 fio_getrusage(&td->ru_end);
Jens Axboec8aaba12011-10-03 12:14:19 +020022 ts->usr_time += mtime_since(&td->ru_start.ru_utime,
23 &td->ru_end.ru_utime);
24 ts->sys_time += mtime_since(&td->ru_start.ru_stime,
25 &td->ru_end.ru_stime);
26 ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw
27 - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw);
28 ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt;
29 ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010030
Jens Axboec8aaba12011-10-03 12:14:19 +020031 memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end));
Jens Axboe3c39a372006-06-06 20:56:12 +020032}
33
Yu-ju Hong83349192011-08-13 00:53:44 +020034/*
35 * Given a latency, return the index of the corresponding bucket in
36 * the structure tracking percentiles.
37 *
38 * (1) find the group (and error bits) that the value (latency)
39 * belongs to by looking at its MSB. (2) find the bucket number in the
40 * group by looking at the index bits.
41 *
42 */
43static unsigned int plat_val_to_idx(unsigned int val)
44{
45 unsigned int msb, error_bits, base, offset, idx;
46
47 /* Find MSB starting from bit 0 */
48 if (val == 0)
49 msb = 0;
50 else
51 msb = (sizeof(val)*8) - __builtin_clz(val) - 1;
52
Jens Axboe716050f2011-08-16 08:43:45 +020053 /*
54 * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
55 * all bits of the sample as index
56 */
Yu-ju Hong83349192011-08-13 00:53:44 +020057 if (msb <= FIO_IO_U_PLAT_BITS)
58 return val;
59
60 /* Compute the number of error bits to discard*/
61 error_bits = msb - FIO_IO_U_PLAT_BITS;
62
63 /* Compute the number of buckets before the group */
64 base = (error_bits + 1) << FIO_IO_U_PLAT_BITS;
65
Jens Axboe716050f2011-08-16 08:43:45 +020066 /*
67 * Discard the error bits and apply the mask to find the
68 * index for the buckets in the group
69 */
Yu-ju Hong83349192011-08-13 00:53:44 +020070 offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits);
71
72 /* Make sure the index does not exceed (array size - 1) */
73 idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1)?
74 (base + offset) : (FIO_IO_U_PLAT_NR - 1);
75
76 return idx;
77}
78
79/*
80 * Convert the given index of the bucket array to the value
81 * represented by the bucket
82 */
83static unsigned int plat_idx_to_val(unsigned int idx)
84{
85 unsigned int error_bits, k, base;
86
87 assert(idx < FIO_IO_U_PLAT_NR);
88
89 /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
90 * all bits of the sample as index */
91 if (idx < (FIO_IO_U_PLAT_VAL << 1) )
92 return idx;
93
94 /* Find the group and compute the minimum value of that group */
95 error_bits = (idx >> FIO_IO_U_PLAT_BITS) -1;
96 base = 1 << (error_bits + FIO_IO_U_PLAT_BITS);
97
98 /* Find its bucket number of the group */
99 k = idx % FIO_IO_U_PLAT_VAL;
100
101 /* Return the mean of the range of the bucket */
102 return base + ((k + 0.5) * (1 << error_bits));
103}
104
105static int double_cmp(const void *a, const void *b)
106{
Jens Axboe802ad4a2011-10-05 09:51:58 +0200107 const fio_fp64_t fa = *(const fio_fp64_t *) a;
108 const fio_fp64_t fb = *(const fio_fp64_t *) b;
Yu-ju Hong83349192011-08-13 00:53:44 +0200109 int cmp = 0;
110
Jens Axboe802ad4a2011-10-05 09:51:58 +0200111 if (fa.u.f > fb.u.f)
Yu-ju Hong83349192011-08-13 00:53:44 +0200112 cmp = 1;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200113 else if (fa.u.f < fb.u.f)
Yu-ju Hong83349192011-08-13 00:53:44 +0200114 cmp = -1;
115
116 return cmp;
117}
118
Jens Axboe1db92cb2011-10-13 13:43:36 +0200119static unsigned int calc_clat_percentiles(unsigned int *io_u_plat,
120 unsigned long nr, fio_fp64_t *plist,
121 unsigned int **output,
122 unsigned int *maxv,
123 unsigned int *minv)
Yu-ju Hong83349192011-08-13 00:53:44 +0200124{
125 unsigned long sum = 0;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200126 unsigned int len, i, j = 0;
127 unsigned int oval_len = 0;
128 unsigned int *ovals = NULL;
129 int is_last;
130
131 *minv = -1U;
132 *maxv = 0;
Yu-ju Hong83349192011-08-13 00:53:44 +0200133
Jens Axboe802ad4a2011-10-05 09:51:58 +0200134 len = 0;
135 while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0)
136 len++;
Jens Axboe716050f2011-08-16 08:43:45 +0200137
Jens Axboe351de8d2011-10-12 21:03:45 +0200138 if (!len)
Jens Axboe1db92cb2011-10-13 13:43:36 +0200139 return 0;
Jens Axboe351de8d2011-10-12 21:03:45 +0200140
Jens Axboe716050f2011-08-16 08:43:45 +0200141 /*
Jens Axboe802ad4a2011-10-05 09:51:58 +0200142 * Sort the percentile list. Note that it may already be sorted if
143 * we are using the default values, but since it's a short list this
144 * isn't a worry. Also note that this does not work for NaN values.
Jens Axboe716050f2011-08-16 08:43:45 +0200145 */
Jens Axboe802ad4a2011-10-05 09:51:58 +0200146 if (len > 1)
147 qsort((void*)plist, len, sizeof(plist[0]), double_cmp);
Yu-ju Hong83349192011-08-13 00:53:44 +0200148
Jens Axboe4f6f8292011-10-13 09:28:21 +0200149 /*
150 * Calculate bucket values, note down max and min values
151 */
Jens Axboe07511a62011-10-13 12:00:24 +0200152 is_last = 0;
153 for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) {
Yu-ju Hong83349192011-08-13 00:53:44 +0200154 sum += io_u_plat[i];
Jens Axboe802ad4a2011-10-05 09:51:58 +0200155 while (sum >= (plist[j].u.f / 100.0 * nr)) {
156 assert(plist[j].u.f <= 100.0);
Yu-ju Hong83349192011-08-13 00:53:44 +0200157
Jens Axboe4f6f8292011-10-13 09:28:21 +0200158 if (j == oval_len) {
159 oval_len += 100;
160 ovals = realloc(ovals, oval_len * sizeof(unsigned int));
161 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200162
Jens Axboe4f6f8292011-10-13 09:28:21 +0200163 ovals[j] = plat_idx_to_val(i);
Jens Axboe1db92cb2011-10-13 13:43:36 +0200164 if (ovals[j] < *minv)
165 *minv = ovals[j];
166 if (ovals[j] > *maxv)
167 *maxv = ovals[j];
Jens Axboe07511a62011-10-13 12:00:24 +0200168
169 is_last = (j == len - 1);
170 if (is_last)
171 break;
172
Jens Axboe4f6f8292011-10-13 09:28:21 +0200173 j++;
Yu-ju Hong83349192011-08-13 00:53:44 +0200174 }
175 }
Jens Axboe4f6f8292011-10-13 09:28:21 +0200176
Jens Axboe1db92cb2011-10-13 13:43:36 +0200177 *output = ovals;
178 return len;
179}
180
181/*
182 * Find and display the p-th percentile of clat
183 */
184static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
185 fio_fp64_t *plist)
186{
187 unsigned int len, j = 0, minv, maxv;
188 unsigned int *ovals;
189 int is_last, scale_down;
190
191 len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
192 if (!len)
193 goto out;
194
Jens Axboe4f6f8292011-10-13 09:28:21 +0200195 /*
196 * We default to usecs, but if the value range is such that we
197 * should scale down to msecs, do that.
198 */
199 if (minv > 2000 && maxv > 99999) {
200 scale_down = 1;
201 log_info(" clat percentiles (msec):\n |");
202 } else {
203 scale_down = 0;
204 log_info(" clat percentiles (usec):\n |");
205 }
206
207 for (j = 0; j < len; j++) {
208 char fbuf[8];
209
210 /* for formatting */
211 if (j != 0 && (j % 4) == 0)
212 log_info(" |");
213
214 /* end of the list */
215 is_last = (j == len - 1);
216
217 if (plist[j].u.f < 10.0)
218 sprintf(fbuf, " %2.2f", plist[j].u.f);
219 else
220 sprintf(fbuf, "%2.2f", plist[j].u.f);
221
222 if (scale_down)
223 ovals[j] = (ovals[j] + 999) / 1000;
224
225 log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ',');
226
227 if (is_last)
228 break;
229
230 if (j % 4 == 3) /* for formatting */
231 log_info("\n");
232 }
233
Jens Axboe1db92cb2011-10-13 13:43:36 +0200234out:
Jens Axboe4f6f8292011-10-13 09:28:21 +0200235 if (ovals)
236 free(ovals);
Yu-ju Hong83349192011-08-13 00:53:44 +0200237}
238
Jens Axboe3c39a372006-06-06 20:56:12 +0200239static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
240 double *mean, double *dev)
241{
Jens Axboe68704082007-01-10 19:56:37 +0100242 double n = is->samples;
Jens Axboe3c39a372006-06-06 20:56:12 +0200243
244 if (is->samples == 0)
245 return 0;
246
247 *min = is->min_val;
248 *max = is->max_val;
249
250 n = (double) is->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200251 *mean = is->mean.u.f;
Jens Axboe3c39a372006-06-06 20:56:12 +0200252
Jens Axboe68704082007-01-10 19:56:37 +0100253 if (n > 1.0)
Jens Axboe802ad4a2011-10-05 09:51:58 +0200254 *dev = sqrt(is->S.u.f / (n - 1.0));
Jens Axboeef9c5c42007-01-03 14:21:13 +0100255 else
Jens Axboe4b43f542007-07-19 21:38:35 +0200256 *dev = 0;
Jens Axboeef9c5c42007-01-03 14:21:13 +0100257
Jens Axboe3c39a372006-06-06 20:56:12 +0200258 return 1;
259}
260
Jens Axboea64e88d2011-10-03 14:20:01 +0200261void show_group_stats(struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200262{
Jens Axboedbe11252007-02-11 00:19:51 +0100263 char *p1, *p2, *p3, *p4;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200264 const char *ddir_str[] = { " READ", " WRITE" , " TRIM"};
Jens Axboedbe11252007-02-11 00:19:51 +0100265 int i;
266
Jens Axboe7e1773b2011-10-14 12:47:56 +0200267 log_info("\nRun status group %d (all jobs):\n", rs->groupid);
Jens Axboe3c39a372006-06-06 20:56:12 +0200268
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200269 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200270 const int i2p = is_power_of_2(rs->kb_base);
271
Jens Axboedbe11252007-02-11 00:19:51 +0100272 if (!rs->max_run[i])
273 continue;
274
Jens Axboe90fef2d2009-07-17 22:33:32 +0200275 p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p);
276 p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p);
277 p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p);
278 p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p);
Jens Axboedbe11252007-02-11 00:19:51 +0100279
Jens Axboeb22989b2009-07-17 22:29:23 +0200280 log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s,"
Jens Axboe771e58b2013-01-30 12:56:23 +0100281 " mint=%llumsec, maxt=%llumsec\n",
282 rs->unified_rw_rep ? " MIXED" : ddir_str[i],
283 p1, p2, p3, p4, rs->min_run[i], rs->max_run[i]);
Jens Axboedbe11252007-02-11 00:19:51 +0100284
285 free(p1);
286 free(p2);
287 free(p3);
288 free(p4);
289 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200290}
291
Jens Axboeb3605062007-03-12 14:19:47 +0100292#define ts_total_io_u(ts) \
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200293 ((ts)->total_io_u[DDIR_READ] + (ts)->total_io_u[DDIR_WRITE] +\
294 (ts)->total_io_u[DDIR_TRIM])
Jens Axboeb3605062007-03-12 14:19:47 +0100295
Jens Axboe838bc702008-05-22 13:08:23 +0200296static void stat_calc_dist(unsigned int *map, unsigned long total,
297 double *io_u_dist)
Jens Axboe22708902007-03-06 17:05:32 +0100298{
299 int i;
300
301 /*
302 * Do depth distribution calculations
303 */
304 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200305 if (total) {
306 io_u_dist[i] = (double) map[i] / (double) total;
307 io_u_dist[i] *= 100.0;
308 if (io_u_dist[i] < 0.1 && map[i])
309 io_u_dist[i] = 0.1;
310 } else
311 io_u_dist[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100312 }
313}
314
Jens Axboe04a0fea2007-06-19 12:48:41 +0200315static void stat_calc_lat(struct thread_stat *ts, double *dst,
316 unsigned int *src, int nr)
Jens Axboe22708902007-03-06 17:05:32 +0100317{
Jens Axboe838bc702008-05-22 13:08:23 +0200318 unsigned long total = ts_total_io_u(ts);
Jens Axboe22708902007-03-06 17:05:32 +0100319 int i;
320
321 /*
322 * Do latency distribution calculations
323 */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200324 for (i = 0; i < nr; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200325 if (total) {
326 dst[i] = (double) src[i] / (double) total;
327 dst[i] *= 100.0;
328 if (dst[i] < 0.01 && src[i])
329 dst[i] = 0.01;
330 } else
331 dst[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100332 }
333}
334
Jens Axboe04a0fea2007-06-19 12:48:41 +0200335static void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
336{
337 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
338}
339
340static void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
341{
342 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
343}
344
Jens Axboeea2accc2007-06-19 09:48:44 +0200345static int usec_to_msec(unsigned long *min, unsigned long *max, double *mean,
346 double *dev)
347{
348 if (*min > 1000 && *max > 1000 && *mean > 1000.0 && *dev > 1000.0) {
349 *min /= 1000;
350 *max /= 1000;
351 *mean /= 1000.0;
352 *dev /= 1000.0;
353 return 0;
354 }
355
356 return 1;
357}
358
Jens Axboe756867b2007-03-06 15:19:24 +0100359static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
Jens Axboe3c39a372006-06-06 20:56:12 +0200360 int ddir)
361{
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200362 const char *ddir_str[] = { "read ", "write", "trim" };
Jens Axboe8879fd12009-04-20 10:06:02 +0200363 unsigned long min, max, runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100364 unsigned long long bw, iops;
Jens Axboe3c39a372006-06-06 20:56:12 +0200365 double mean, dev;
Jens Axboeb3605062007-03-12 14:19:47 +0100366 char *io_p, *bw_p, *iops_p;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200367 int i2p;
Jens Axboe3c39a372006-06-06 20:56:12 +0200368
Jens Axboeff58fce2010-08-25 12:02:08 +0200369 assert(ddir_rw(ddir));
370
Jens Axboe756867b2007-03-06 15:19:24 +0100371 if (!ts->runtime[ddir])
Jens Axboe3c39a372006-06-06 20:56:12 +0200372 return;
373
Jens Axboe90fef2d2009-07-17 22:33:32 +0200374 i2p = is_power_of_2(rs->kb_base);
Jens Axboe8879fd12009-04-20 10:06:02 +0200375 runt = ts->runtime[ddir];
376
377 bw = (1000 * ts->io_bytes[ddir]) / runt;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200378 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
379 bw_p = num2str(bw, 6, 1, i2p);
Jens Axboe8879fd12009-04-20 10:06:02 +0200380
Bruce Cran0aacc502011-07-09 08:19:53 +0200381 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100382 iops_p = num2str(iops, 6, 1, 0);
Jens Axboedbe11252007-02-11 00:19:51 +0100383
Signed-off-by Steven Prattcda99fa2010-12-14 08:31:36 +0100384 log_info(" %s: io=%sB, bw=%sB/s, iops=%s, runt=%6llumsec\n",
Jens Axboe771e58b2013-01-30 12:56:23 +0100385 rs->unified_rw_rep ? "mixed" : ddir_str[ddir],
386 io_p, bw_p, iops_p, ts->runtime[ddir]);
Jens Axboedbe11252007-02-11 00:19:51 +0100387
388 free(io_p);
389 free(bw_p);
Jens Axboeb3605062007-03-12 14:19:47 +0100390 free(iops_p);
Jens Axboe3c39a372006-06-06 20:56:12 +0200391
Jens Axboed85f5112007-06-18 09:41:23 +0200392 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
393 const char *base = "(usec)";
Jens Axboed9309cb2007-08-16 13:07:46 +0200394 char *minp, *maxp;
Jens Axboe3c39a372006-06-06 20:56:12 +0200395
Jens Axboeea2accc2007-06-19 09:48:44 +0200396 if (!usec_to_msec(&min, &max, &mean, &dev))
Jens Axboed85f5112007-06-18 09:41:23 +0200397 base = "(msec)";
Jens Axboeea2accc2007-06-19 09:48:44 +0200398
Jens Axboed9309cb2007-08-16 13:07:46 +0200399 minp = num2str(min, 6, 1, 0);
400 maxp = num2str(max, 6, 1, 0);
401
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100402 log_info(" slat %s: min=%s, max=%s, avg=%5.02f,"
403 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
Jens Axboed9309cb2007-08-16 13:07:46 +0200404
405 free(minp);
406 free(maxp);
Jens Axboed85f5112007-06-18 09:41:23 +0200407 }
408 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
409 const char *base = "(usec)";
Jens Axboed9309cb2007-08-16 13:07:46 +0200410 char *minp, *maxp;
Jens Axboe3c39a372006-06-06 20:56:12 +0200411
Jens Axboeea2accc2007-06-19 09:48:44 +0200412 if (!usec_to_msec(&min, &max, &mean, &dev))
413 base = "(msec)";
414
Jens Axboed9309cb2007-08-16 13:07:46 +0200415 minp = num2str(min, 6, 1, 0);
416 maxp = num2str(max, 6, 1, 0);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100417
418 log_info(" clat %s: min=%s, max=%s, avg=%5.02f,"
419 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
Jens Axboed9309cb2007-08-16 13:07:46 +0200420
421 free(minp);
422 free(maxp);
Jens Axboed85f5112007-06-18 09:41:23 +0200423 }
Jens Axboe02af0982010-06-24 09:59:34 +0200424 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) {
425 const char *base = "(usec)";
426 char *minp, *maxp;
427
428 if (!usec_to_msec(&min, &max, &mean, &dev))
429 base = "(msec)";
430
431 minp = num2str(min, 6, 1, 0);
432 maxp = num2str(max, 6, 1, 0);
433
434 log_info(" lat %s: min=%s, max=%s, avg=%5.02f,"
435 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
436
437 free(minp);
438 free(maxp);
439 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200440 if (ts->clat_percentiles) {
441 show_clat_percentiles(ts->io_u_plat[ddir],
442 ts->clat_stat[ddir].samples,
443 ts->percentile_list);
444 }
Jens Axboe079ad092007-02-20 13:58:20 +0100445 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100446 double p_of_agg = 100.0;
Jens Axboeb7017e32011-10-14 09:30:01 +0200447 const char *bw_str = "KB";
Jens Axboe3c39a372006-06-06 20:56:12 +0200448
Jens Axboe2f2c6922012-02-07 16:42:43 +0100449 if (rs->agg[ddir]) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100450 p_of_agg = mean * 100 / (double) rs->agg[ddir];
451 if (p_of_agg > 100.0)
452 p_of_agg = 100.0;
453 }
Jens Axboeb7017e32011-10-14 09:30:01 +0200454
455 if (mean > 999999.9) {
456 min /= 1000.0;
457 max /= 1000.0;
458 mean /= 1000.0;
459 dev /= 1000.0;
460 bw_str = "MB";
461 }
462
Jens Axboe7e1773b2011-10-14 12:47:56 +0200463 log_info(" bw (%s/s) : min=%5lu, max=%5lu, per=%3.2f%%,"
Jens Axboeb7017e32011-10-14 09:30:01 +0200464 " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max,
465 p_of_agg, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200466 }
467}
468
Jens Axboe7e1773b2011-10-14 12:47:56 +0200469static int show_lat(double *io_u_lat, int nr, const char **ranges,
470 const char *msg)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200471{
Jens Axboe7e1773b2011-10-14 12:47:56 +0200472 int new_line = 1, i, line = 0, shown = 0;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200473
474 for (i = 0; i < nr; i++) {
475 if (io_u_lat[i] <= 0.0)
476 continue;
Jens Axboe7e1773b2011-10-14 12:47:56 +0200477 shown = 1;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200478 if (new_line) {
Jens Axboe4539ed72007-07-23 14:21:17 +0200479 if (line)
480 log_info("\n");
Jens Axboe7e1773b2011-10-14 12:47:56 +0200481 log_info(" lat (%s) : ", msg);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200482 new_line = 0;
483 line = 0;
484 }
485 if (line)
486 log_info(", ");
487 log_info("%s%3.2f%%", ranges[i], io_u_lat[i]);
488 line++;
489 if (line == 5)
490 new_line = 1;
491 }
Jens Axboe7e1773b2011-10-14 12:47:56 +0200492
493 if (shown)
494 log_info("\n");
495
496 return shown;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200497}
498
499static void show_lat_u(double *io_u_lat_u)
500{
501 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
502 "250=", "500=", "750=", "1000=", };
503
504 show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec");
505}
506
507static void show_lat_m(double *io_u_lat_m)
508{
509 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
510 "250=", "500=", "750=", "1000=", "2000=",
511 ">=2000=", };
512
513 show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec");
514}
515
516static void show_latencies(double *io_u_lat_u, double *io_u_lat_m)
517{
518 show_lat_u(io_u_lat_u);
519 show_lat_m(io_u_lat_m);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200520}
521
Jens Axboea64e88d2011-10-03 14:20:01 +0200522void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200523{
524 double usr_cpu, sys_cpu;
Jens Axboe69008992006-11-24 13:12:56 +0100525 unsigned long runtime;
Jens Axboe71619dc2007-01-13 23:56:33 +0100526 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200527 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
528 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboe57a64322012-06-14 15:11:15 +0200529 time_t time_p;
530 char time_buf[64];
Jens Axboe3c39a372006-06-06 20:56:12 +0200531
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200532 if (!(ts->io_bytes[DDIR_READ] + ts->io_bytes[DDIR_WRITE] +
533 ts->io_bytes[DDIR_TRIM]) && !(ts->total_io_u[DDIR_READ] +
534 ts->total_io_u[DDIR_WRITE] + ts->total_io_u[DDIR_TRIM]))
Jens Axboe3c39a372006-06-06 20:56:12 +0200535 return;
536
Jens Axboe57a64322012-06-14 15:11:15 +0200537 time(&time_p);
Saurabh De45054cb2012-10-09 14:46:24 -0600538 os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf));
Jens Axboe57a64322012-06-14 15:11:15 +0200539
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100540 if (!ts->error) {
Jens Axboe57a64322012-06-14 15:11:15 +0200541 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100542 ts->name, ts->groupid, ts->members,
Jens Axboe57a64322012-06-14 15:11:15 +0200543 ts->error, (int) ts->pid, time_buf);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100544 } else {
Jens Axboe57a64322012-06-14 15:11:15 +0200545 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100546 ts->name, ts->groupid, ts->members,
Jens Axboe57a64322012-06-14 15:11:15 +0200547 ts->error, ts->verror, (int) ts->pid,
548 time_buf);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100549 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200550
Jens Axboe259e47d2011-10-13 21:05:59 +0200551 if (strlen(ts->description))
Jens Axboe6d861442007-03-15 09:22:23 +0100552 log_info(" Description : [%s]\n", ts->description);
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100553
Jens Axboe756867b2007-03-06 15:19:24 +0100554 if (ts->io_bytes[DDIR_READ])
555 show_ddir_status(rs, ts, DDIR_READ);
556 if (ts->io_bytes[DDIR_WRITE])
557 show_ddir_status(rs, ts, DDIR_WRITE);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200558 if (ts->io_bytes[DDIR_TRIM])
559 show_ddir_status(rs, ts, DDIR_TRIM);
Jens Axboe3c39a372006-06-06 20:56:12 +0200560
Jens Axboe7e1773b2011-10-14 12:47:56 +0200561 stat_calc_lat_u(ts, io_u_lat_u);
562 stat_calc_lat_m(ts, io_u_lat_m);
563 show_latencies(io_u_lat_u, io_u_lat_m);
564
Jens Axboe756867b2007-03-06 15:19:24 +0100565 runtime = ts->total_run_time;
Jens Axboe69008992006-11-24 13:12:56 +0100566 if (runtime) {
Jens Axboe1e97cce2006-12-05 11:44:16 +0100567 double runt = (double) runtime;
Jens Axboe3c39a372006-06-06 20:56:12 +0200568
Jens Axboe756867b2007-03-06 15:19:24 +0100569 usr_cpu = (double) ts->usr_time * 100 / runt;
570 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboe3c39a372006-06-06 20:56:12 +0200571 } else {
572 usr_cpu = 0;
573 sys_cpu = 0;
574 }
575
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100576 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu,"
577 " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf);
Jens Axboe71619dc2007-01-13 23:56:33 +0100578
Jens Axboe838bc702008-05-22 13:08:23 +0200579 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100580 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%,"
581 " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
582 io_u_dist[1], io_u_dist[2],
583 io_u_dist[3], io_u_dist[4],
584 io_u_dist[5], io_u_dist[6]);
Jens Axboe838bc702008-05-22 13:08:23 +0200585
586 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
587 log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
588 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
589 io_u_dist[1], io_u_dist[2],
590 io_u_dist[3], io_u_dist[4],
591 io_u_dist[5], io_u_dist[6]);
592 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
593 log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
594 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
595 io_u_dist[1], io_u_dist[2],
596 io_u_dist[3], io_u_dist[4],
597 io_u_dist[5], io_u_dist[6]);
Jens Axboe7e1773b2011-10-14 12:47:56 +0200598 log_info(" issued : total=r=%lu/w=%lu/d=%lu,"
599 " short=r=%lu/w=%lu/d=%lu\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100600 ts->total_io_u[0], ts->total_io_u[1],
Jens Axboe0d29de82010-09-01 13:54:15 +0200601 ts->total_io_u[2],
602 ts->short_io_u[0], ts->short_io_u[1],
603 ts->short_io_u[2]);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200604 if (ts->continue_on_error) {
Jens Axboe1ec99ee2009-06-15 12:37:30 +0200605 log_info(" errors : total=%lu, first_error=%d/<%s>\n",
606 ts->total_err_count,
607 ts->first_error,
608 strerror(ts->first_error));
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200609 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200610}
611
Jens Axboe756867b2007-03-06 15:19:24 +0100612static void show_ddir_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200613 struct group_run_stats *rs, int ddir)
614{
615 unsigned long min, max;
Jens Axboe312b4af2011-10-13 13:11:42 +0200616 unsigned long long bw, iops;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200617 unsigned int *ovals = NULL;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200618 double mean, dev;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200619 unsigned int len, minv, maxv;
620 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200621
Jens Axboeff58fce2010-08-25 12:02:08 +0200622 assert(ddir_rw(ddir));
623
Jens Axboe312b4af2011-10-13 13:11:42 +0200624 iops = bw = 0;
625 if (ts->runtime[ddir]) {
626 uint64_t runt = ts->runtime[ddir];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200627
Jens Axboe033bbb52012-05-07 09:46:40 +0200628 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
Jens Axboe312b4af2011-10-13 13:11:42 +0200629 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
630 }
631
632 log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops,
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100633 ts->runtime[ddir]);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200634
Jens Axboe079ad092007-02-20 13:58:20 +0100635 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100636 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200637 else
Jens Axboe6d861442007-03-15 09:22:23 +0100638 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200639
Jens Axboe079ad092007-02-20 13:58:20 +0100640 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100641 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200642 else
Jens Axboe6d861442007-03-15 09:22:23 +0100643 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200644
Jens Axboe1db92cb2011-10-13 13:43:36 +0200645 if (ts->clat_percentiles) {
646 len = calc_clat_percentiles(ts->io_u_plat[ddir],
647 ts->clat_stat[ddir].samples,
648 ts->percentile_list, &ovals, &maxv,
649 &minv);
650 } else
651 len = 0;
652
653 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
654 if (i >= len) {
655 log_info(";0%%=0");
656 continue;
657 }
658 log_info(";%2.2f%%=%u", ts->percentile_list[i].u.f, ovals[i]);
659 }
Keplar kramer2341a372011-10-19 21:31:27 +0200660
661 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
662 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
663 else
664 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
665
Jens Axboe1db92cb2011-10-13 13:43:36 +0200666 if (ovals)
667 free(ovals);
668
Jens Axboe079ad092007-02-20 13:58:20 +0100669 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100670 double p_of_agg = 100.0;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200671
Jens Axboe19d3e962012-02-07 12:27:28 +0100672 if (rs->agg[ddir]) {
673 p_of_agg = mean * 100 / (double) rs->agg[ddir];
674 if (p_of_agg > 100.0)
675 p_of_agg = 100.0;
676 }
677
Jens Axboe6d861442007-03-15 09:22:23 +0100678 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200679 } else
Jens Axboe6d861442007-03-15 09:22:23 +0100680 log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200681}
682
Shaohua Licc372b12012-09-17 09:12:18 +0200683static void add_ddir_status_json(struct thread_stat *ts,
684 struct group_run_stats *rs, int ddir, struct json_object *parent)
685{
686 unsigned long min, max;
687 unsigned long long bw, iops;
688 unsigned int *ovals = NULL;
689 double mean, dev;
690 unsigned int len, minv, maxv;
691 int i;
692 const char *ddirname[] = {"read", "write", "trim"};
693 struct json_object *dir_object, *tmp_object, *percentile_object;
694 char buf[120];
695 double p_of_agg = 100.0;
696
697 assert(ddir_rw(ddir));
698
Jens Axboe771e58b2013-01-30 12:56:23 +0100699 if (ts->unified_rw_rep && ddir != DDIR_READ)
700 return;
701
Shaohua Licc372b12012-09-17 09:12:18 +0200702 dir_object = json_create_object();
Jens Axboe771e58b2013-01-30 12:56:23 +0100703 json_object_add_value_object(parent,
704 ts->unified_rw_rep ? "mixed" : ddirname[ddir], dir_object);
Shaohua Licc372b12012-09-17 09:12:18 +0200705
706 iops = bw = 0;
707 if (ts->runtime[ddir]) {
708 uint64_t runt = ts->runtime[ddir];
709
710 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
711 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
712 }
713
714 json_object_add_value_int(dir_object, "io_bytes", ts->io_bytes[ddir] >> 10);
715 json_object_add_value_int(dir_object, "bw", bw);
716 json_object_add_value_int(dir_object, "iops", iops);
717 json_object_add_value_int(dir_object, "runtime", ts->runtime[ddir]);
718
719 if (!calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
720 min = max = 0;
721 mean = dev = 0.0;
722 }
723 tmp_object = json_create_object();
724 json_object_add_value_object(dir_object, "slat", tmp_object);
725 json_object_add_value_int(tmp_object, "min", min);
726 json_object_add_value_int(tmp_object, "max", max);
727 json_object_add_value_float(tmp_object, "mean", mean);
728 json_object_add_value_float(tmp_object, "stddev", dev);
729
730 if (!calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
731 min = max = 0;
732 mean = dev = 0.0;
733 }
734 tmp_object = json_create_object();
735 json_object_add_value_object(dir_object, "clat", tmp_object);
736 json_object_add_value_int(tmp_object, "min", min);
737 json_object_add_value_int(tmp_object, "max", max);
738 json_object_add_value_float(tmp_object, "mean", mean);
739 json_object_add_value_float(tmp_object, "stddev", dev);
740
741 if (ts->clat_percentiles) {
742 len = calc_clat_percentiles(ts->io_u_plat[ddir],
743 ts->clat_stat[ddir].samples,
744 ts->percentile_list, &ovals, &maxv,
745 &minv);
746 } else
747 len = 0;
748
749 percentile_object = json_create_object();
750 json_object_add_value_object(tmp_object, "percentile", percentile_object);
751 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
752 if (i >= len) {
753 json_object_add_value_int(percentile_object, "0.00", 0);
754 continue;
755 }
756 snprintf(buf, sizeof(buf) - 1, "%2.2f", ts->percentile_list[i].u.f);
757 json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]);
758 }
759
760 if (!calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) {
761 min = max = 0;
762 mean = dev = 0.0;
763 }
764 tmp_object = json_create_object();
765 json_object_add_value_object(dir_object, "lat", tmp_object);
766 json_object_add_value_int(tmp_object, "min", min);
767 json_object_add_value_int(tmp_object, "max", max);
768 json_object_add_value_float(tmp_object, "mean", mean);
769 json_object_add_value_float(tmp_object, "stddev", dev);
770 if (ovals)
771 free(ovals);
772
773 if (!calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
774 if (rs->agg[ddir]) {
775 p_of_agg = mean * 100 / (double) rs->agg[ddir];
776 if (p_of_agg > 100.0)
777 p_of_agg = 100.0;
778 }
779 } else {
780 min = max = 0;
781 p_of_agg = mean = dev = 0.0;
782 }
783 json_object_add_value_int(dir_object, "bw_min", min);
784 json_object_add_value_int(dir_object, "bw_max", max);
785 json_object_add_value_float(dir_object, "bw_agg", mean);
786 json_object_add_value_float(dir_object, "bw_mean", mean);
787 json_object_add_value_float(dir_object, "bw_dev", dev);
788}
789
Jens Axboe4d658652011-10-17 15:05:47 +0200790static void show_thread_status_terse_v2(struct thread_stat *ts,
791 struct group_run_stats *rs)
792{
793 double io_u_dist[FIO_IO_U_MAP_NR];
794 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
795 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
796 double usr_cpu, sys_cpu;
797 int i;
798
799 /* General Info */
800 log_info("2;%s;%d;%d", ts->name, ts->groupid, ts->error);
801 /* Log Read Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200802 show_ddir_status_terse(ts, rs, DDIR_READ);
Jens Axboe4d658652011-10-17 15:05:47 +0200803 /* Log Write Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200804 show_ddir_status_terse(ts, rs, DDIR_WRITE);
805 /* Log Trim Status */
806 show_ddir_status_terse(ts, rs, DDIR_TRIM);
Jens Axboe4d658652011-10-17 15:05:47 +0200807
808 /* CPU Usage */
809 if (ts->total_run_time) {
810 double runt = (double) ts->total_run_time;
811
812 usr_cpu = (double) ts->usr_time * 100 / runt;
813 sys_cpu = (double) ts->sys_time * 100 / runt;
814 } else {
815 usr_cpu = 0;
816 sys_cpu = 0;
817 }
818
819 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
820 ts->minf);
821
822 /* Calc % distribution of IO depths, usecond, msecond latency */
823 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
824 stat_calc_lat_u(ts, io_u_lat_u);
825 stat_calc_lat_m(ts, io_u_lat_m);
826
827 /* Only show fixed 7 I/O depth levels*/
828 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
829 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
830 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
831
832 /* Microsecond latency */
833 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
834 log_info(";%3.2f%%", io_u_lat_u[i]);
835 /* Millisecond latency */
836 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
837 log_info(";%3.2f%%", io_u_lat_m[i]);
838 /* Additional output if continue_on_error set - default off*/
839 if (ts->continue_on_error)
840 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
841 log_info("\n");
842
843 /* Additional output if description is set */
844 if (ts->description)
845 log_info(";%s", ts->description);
846
847 log_info("\n");
848}
849
Jens Axboe3449ab82012-09-14 23:35:08 +0200850static void show_thread_status_terse_v3_v4(struct thread_stat *ts,
851 struct group_run_stats *rs, int ver)
Jens Axboec6ae0a52006-06-12 11:04:44 +0200852{
Jens Axboe22708902007-03-06 17:05:32 +0100853 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200854 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
855 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200856 double usr_cpu, sys_cpu;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200857 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200858
David Nellans562c2d22010-09-23 08:38:17 +0200859 /* General Info */
Jens Axboef3afa572012-09-17 13:34:16 +0200860 log_info("%d;%s;%s;%d;%d", ver, fio_version_string,
Jens Axboe5e726d02011-10-14 08:08:10 +0200861 ts->name, ts->groupid, ts->error);
David Nellans562c2d22010-09-23 08:38:17 +0200862 /* Log Read Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200863 show_ddir_status_terse(ts, rs, DDIR_READ);
David Nellans562c2d22010-09-23 08:38:17 +0200864 /* Log Write Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200865 show_ddir_status_terse(ts, rs, DDIR_WRITE);
866 /* Log Trim Status */
Jens Axboe3449ab82012-09-14 23:35:08 +0200867 if (ver == 4)
868 show_ddir_status_terse(ts, rs, DDIR_TRIM);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200869
David Nellans562c2d22010-09-23 08:38:17 +0200870 /* CPU Usage */
Jens Axboe756867b2007-03-06 15:19:24 +0100871 if (ts->total_run_time) {
872 double runt = (double) ts->total_run_time;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200873
Jens Axboe756867b2007-03-06 15:19:24 +0100874 usr_cpu = (double) ts->usr_time * 100 / runt;
875 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200876 } else {
877 usr_cpu = 0;
878 sys_cpu = 0;
879 }
880
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100881 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
882 ts->minf);
Jens Axboe22708902007-03-06 17:05:32 +0100883
David Nellans562c2d22010-09-23 08:38:17 +0200884 /* Calc % distribution of IO depths, usecond, msecond latency */
Jens Axboe838bc702008-05-22 13:08:23 +0200885 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200886 stat_calc_lat_u(ts, io_u_lat_u);
887 stat_calc_lat_m(ts, io_u_lat_m);
Jens Axboe22708902007-03-06 17:05:32 +0100888
David Nellans562c2d22010-09-23 08:38:17 +0200889 /* Only show fixed 7 I/O depth levels*/
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100890 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
891 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
892 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
Jens Axboe22708902007-03-06 17:05:32 +0100893
David Nellans562c2d22010-09-23 08:38:17 +0200894 /* Microsecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200895 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
896 log_info(";%3.2f%%", io_u_lat_u[i]);
David Nellans562c2d22010-09-23 08:38:17 +0200897 /* Millisecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200898 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
899 log_info(";%3.2f%%", io_u_lat_m[i]);
Jens Axboef2f788d2011-10-13 14:03:52 +0200900
901 /* disk util stats, if any */
Shaohua Licc372b12012-09-17 09:12:18 +0200902 show_disk_util(1, NULL);
Jens Axboef2f788d2011-10-13 14:03:52 +0200903
David Nellans562c2d22010-09-23 08:38:17 +0200904 /* Additional output if continue_on_error set - default off*/
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200905 if (ts->continue_on_error)
906 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
Jens Axboe22708902007-03-06 17:05:32 +0100907
David Nellans562c2d22010-09-23 08:38:17 +0200908 /* Additional output if description is set */
Jens Axboe4b0f2252011-10-13 15:03:25 +0200909 if (strlen(ts->description))
Jens Axboe946e4272012-03-23 19:22:21 +0100910 log_info(";%s", ts->description);
911
912 log_info("\n");
Jens Axboe756867b2007-03-06 15:19:24 +0100913}
914
Shaohua Licc372b12012-09-17 09:12:18 +0200915static struct json_object *show_thread_status_json(struct thread_stat *ts,
916 struct group_run_stats *rs)
917{
918 struct json_object *root, *tmp;
919 double io_u_dist[FIO_IO_U_MAP_NR];
920 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
921 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
922 double usr_cpu, sys_cpu;
923 int i;
924
925 root = json_create_object();
926 json_object_add_value_string(root, "jobname", ts->name);
927 json_object_add_value_int(root, "groupid", ts->groupid);
928 json_object_add_value_int(root, "error", ts->error);
929
930 add_ddir_status_json(ts, rs, DDIR_READ, root);
931 add_ddir_status_json(ts, rs, DDIR_WRITE, root);
Jens Axboef3afa572012-09-17 13:34:16 +0200932 add_ddir_status_json(ts, rs, DDIR_TRIM, root);
Shaohua Licc372b12012-09-17 09:12:18 +0200933
934 /* CPU Usage */
935 if (ts->total_run_time) {
936 double runt = (double) ts->total_run_time;
937
938 usr_cpu = (double) ts->usr_time * 100 / runt;
939 sys_cpu = (double) ts->sys_time * 100 / runt;
940 } else {
941 usr_cpu = 0;
942 sys_cpu = 0;
943 }
944 json_object_add_value_float(root, "usr_cpu", usr_cpu);
945 json_object_add_value_float(root, "sys_cpu", sys_cpu);
946 json_object_add_value_int(root, "ctx", ts->ctx);
947 json_object_add_value_int(root, "majf", ts->majf);
948 json_object_add_value_int(root, "minf", ts->minf);
949
950
951 /* Calc % distribution of IO depths, usecond, msecond latency */
952 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
953 stat_calc_lat_u(ts, io_u_lat_u);
954 stat_calc_lat_m(ts, io_u_lat_m);
955
956 tmp = json_create_object();
957 json_object_add_value_object(root, "iodepth_level", tmp);
958 /* Only show fixed 7 I/O depth levels*/
959 for (i = 0; i < 7; i++) {
960 char name[20];
961 if (i < 6)
962 snprintf(name, 19, "%d", 1 << i);
963 else
964 snprintf(name, 19, ">=%d", 1 << i);
965 json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]);
966 }
967
968 tmp = json_create_object();
969 json_object_add_value_object(root, "latency_us", tmp);
970 /* Microsecond latency */
971 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
972 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
973 "250", "500", "750", "1000", };
974 json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]);
975 }
976 /* Millisecond latency */
977 tmp = json_create_object();
978 json_object_add_value_object(root, "latency_ms", tmp);
979 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) {
980 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
981 "250", "500", "750", "1000", "2000",
982 ">=2000", };
983 json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]);
984 }
985
986 /* Additional output if continue_on_error set - default off*/
987 if (ts->continue_on_error) {
988 json_object_add_value_int(root, "total_err", ts->total_err_count);
989 json_object_add_value_int(root, "total_err", ts->first_error);
990 }
991
992 /* Additional output if description is set */
993 if (strlen(ts->description))
994 json_object_add_value_string(root, "desc", ts->description);
995
996 return root;
997}
998
Jens Axboe4d658652011-10-17 15:05:47 +0200999static void show_thread_status_terse(struct thread_stat *ts,
1000 struct group_run_stats *rs)
1001{
1002 if (terse_version == 2)
1003 show_thread_status_terse_v2(ts, rs);
Jens Axboe3449ab82012-09-14 23:35:08 +02001004 else if (terse_version == 3 || terse_version == 4)
1005 show_thread_status_terse_v3_v4(ts, rs, terse_version);
Jens Axboe4d658652011-10-17 15:05:47 +02001006 else
1007 log_err("fio: bad terse version!? %d\n", terse_version);
1008}
1009
Jens Axboe197574e2007-03-08 15:35:11 +01001010static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
Jens Axboe756867b2007-03-06 15:19:24 +01001011{
1012 double mean, S;
1013
Zheng Liue09231c2011-09-16 08:20:12 +02001014 if (src->samples == 0)
1015 return;
1016
Jens Axboe756867b2007-03-06 15:19:24 +01001017 dst->min_val = min(dst->min_val, src->min_val);
1018 dst->max_val = max(dst->max_val, src->max_val);
Jens Axboe756867b2007-03-06 15:19:24 +01001019
1020 /*
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001021 * Compute new mean and S after the merge
1022 * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
1023 * #Parallel_algorithm>
Jens Axboe756867b2007-03-06 15:19:24 +01001024 */
1025 if (nr == 1) {
Jens Axboe802ad4a2011-10-05 09:51:58 +02001026 mean = src->mean.u.f;
1027 S = src->S.u.f;
Jens Axboe756867b2007-03-06 15:19:24 +01001028 } else {
Jens Axboe802ad4a2011-10-05 09:51:58 +02001029 double delta = src->mean.u.f - dst->mean.u.f;
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001030
Jens Axboe802ad4a2011-10-05 09:51:58 +02001031 mean = ((src->mean.u.f * src->samples) +
1032 (dst->mean.u.f * dst->samples)) /
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001033 (dst->samples + src->samples);
1034
Jens Axboe802ad4a2011-10-05 09:51:58 +02001035 S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) *
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001036 (dst->samples * src->samples) /
1037 (dst->samples + src->samples);
Jens Axboe756867b2007-03-06 15:19:24 +01001038 }
1039
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001040 dst->samples += src->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +02001041 dst->mean.u.f = mean;
1042 dst->S.u.f = S;
Jens Axboe756867b2007-03-06 15:19:24 +01001043}
1044
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001045void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src)
1046{
1047 int i;
1048
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001049 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001050 if (dst->max_run[i] < src->max_run[i])
1051 dst->max_run[i] = src->max_run[i];
1052 if (dst->min_run[i] && dst->min_run[i] > src->min_run[i])
1053 dst->min_run[i] = src->min_run[i];
1054 if (dst->max_bw[i] < src->max_bw[i])
1055 dst->max_bw[i] = src->max_bw[i];
1056 if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i])
1057 dst->min_bw[i] = src->min_bw[i];
1058
1059 dst->io_kb[i] += src->io_kb[i];
1060 dst->agg[i] += src->agg[i];
1061 }
1062
1063}
1064
Jens Axboe5b9babb2011-10-10 12:14:30 +02001065void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr)
1066{
1067 int l, k;
1068
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001069 for (l = 0; l < DDIR_RWDIR_CNT; l++) {
Jens Axboe771e58b2013-01-30 12:56:23 +01001070 if (!dst->unified_rw_rep) {
1071 sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr);
1072 sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr);
1073 sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr);
1074 sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr);
Jens Axboe5b9babb2011-10-10 12:14:30 +02001075
Jens Axboe771e58b2013-01-30 12:56:23 +01001076 dst->io_bytes[l] += src->io_bytes[l];
Jens Axboe5b9babb2011-10-10 12:14:30 +02001077
Jens Axboe771e58b2013-01-30 12:56:23 +01001078 if (dst->runtime[l] < src->runtime[l])
1079 dst->runtime[l] = src->runtime[l];
1080 } else {
1081 sum_stat(&dst->clat_stat[0], &src->clat_stat[l], nr);
1082 sum_stat(&dst->slat_stat[0], &src->slat_stat[l], nr);
1083 sum_stat(&dst->lat_stat[0], &src->lat_stat[l], nr);
1084 sum_stat(&dst->bw_stat[0], &src->bw_stat[l], nr);
1085
1086 dst->io_bytes[0] += src->io_bytes[l];
1087
1088 if (dst->runtime[0] < src->runtime[l])
1089 dst->runtime[0] = src->runtime[l];
1090 }
Jens Axboe5b9babb2011-10-10 12:14:30 +02001091 }
1092
1093 dst->usr_time += src->usr_time;
1094 dst->sys_time += src->sys_time;
1095 dst->ctx += src->ctx;
1096 dst->majf += src->majf;
1097 dst->minf += src->minf;
1098
1099 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1100 dst->io_u_map[k] += src->io_u_map[k];
1101 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1102 dst->io_u_submit[k] += src->io_u_submit[k];
1103 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1104 dst->io_u_complete[k] += src->io_u_complete[k];
1105 for (k = 0; k < FIO_IO_U_LAT_U_NR; k++)
1106 dst->io_u_lat_u[k] += src->io_u_lat_u[k];
1107 for (k = 0; k < FIO_IO_U_LAT_M_NR; k++)
1108 dst->io_u_lat_m[k] += src->io_u_lat_m[k];
1109
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001110 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
Jens Axboe771e58b2013-01-30 12:56:23 +01001111 if (!dst->unified_rw_rep) {
1112 dst->total_io_u[k] += src->total_io_u[k];
1113 dst->short_io_u[k] += src->short_io_u[k];
1114 } else {
1115 dst->total_io_u[0] += src->total_io_u[k];
1116 dst->short_io_u[0] += src->short_io_u[k];
1117 }
Jens Axboe5b9babb2011-10-10 12:14:30 +02001118 }
1119
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001120 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
Jens Axboe5b9babb2011-10-10 12:14:30 +02001121 int m;
Jens Axboe771e58b2013-01-30 12:56:23 +01001122
1123 for (m = 0; m < FIO_IO_U_PLAT_NR; m++) {
1124 if (!dst->unified_rw_rep)
1125 dst->io_u_plat[k][m] += src->io_u_plat[k][m];
1126 else
1127 dst->io_u_plat[0][m] += src->io_u_plat[k][m];
1128 }
Jens Axboe5b9babb2011-10-10 12:14:30 +02001129 }
1130
1131 dst->total_run_time += src->total_run_time;
1132 dst->total_submit += src->total_submit;
1133 dst->total_complete += src->total_complete;
1134}
1135
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001136void init_group_run_stat(struct group_run_stats *gs)
1137{
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001138 int i;
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001139 memset(gs, 0, sizeof(*gs));
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001140
1141 for (i = 0; i < DDIR_RWDIR_CNT; i++)
1142 gs->min_bw[i] = gs->min_run[i] = ~0UL;
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001143}
1144
1145void init_thread_stat(struct thread_stat *ts)
1146{
1147 int j;
1148
1149 memset(ts, 0, sizeof(*ts));
1150
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001151 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001152 ts->lat_stat[j].min_val = -1UL;
1153 ts->clat_stat[j].min_val = -1UL;
1154 ts->slat_stat[j].min_val = -1UL;
1155 ts->bw_stat[j].min_val = -1UL;
1156 }
1157 ts->groupid = -1;
1158}
1159
Jens Axboe3c39a372006-06-06 20:56:12 +02001160void show_run_stats(void)
1161{
1162 struct group_run_stats *runstats, *rs;
1163 struct thread_data *td;
Jens Axboe756867b2007-03-06 15:19:24 +01001164 struct thread_stat *threadstats, *ts;
Jens Axboe5b9babb2011-10-10 12:14:30 +02001165 int i, j, nr_ts, last_ts, idx;
Jens Axboe90fef2d2009-07-17 22:33:32 +02001166 int kb_base_warned = 0;
Shaohua Licc372b12012-09-17 09:12:18 +02001167 struct json_object *root = NULL;
1168 struct json_array *array = NULL;
Jens Axboe3c39a372006-06-06 20:56:12 +02001169
1170 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
1171
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001172 for (i = 0; i < groupid + 1; i++)
1173 init_group_run_stat(&runstats[i]);
Jens Axboe3c39a372006-06-06 20:56:12 +02001174
Jens Axboe756867b2007-03-06 15:19:24 +01001175 /*
1176 * find out how many threads stats we need. if group reporting isn't
1177 * enabled, it's one-per-td.
1178 */
1179 nr_ts = 0;
1180 last_ts = -1;
Jens Axboe34572e22006-10-20 09:33:18 +02001181 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001182 if (!td->o.group_reporting) {
Jens Axboe756867b2007-03-06 15:19:24 +01001183 nr_ts++;
1184 continue;
1185 }
1186 if (last_ts == td->groupid)
1187 continue;
1188
1189 last_ts = td->groupid;
1190 nr_ts++;
1191 }
1192
1193 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
1194
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001195 for (i = 0; i < nr_ts; i++)
1196 init_thread_stat(&threadstats[i]);
Jens Axboe756867b2007-03-06 15:19:24 +01001197
1198 j = 0;
1199 last_ts = -1;
Jens Axboe197574e2007-03-08 15:35:11 +01001200 idx = 0;
Jens Axboe756867b2007-03-06 15:19:24 +01001201 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001202 if (idx && (!td->o.group_reporting ||
1203 (td->o.group_reporting && last_ts != td->groupid))) {
Jens Axboe7abd0e32007-03-12 15:24:43 +01001204 idx = 0;
1205 j++;
1206 }
1207
1208 last_ts = td->groupid;
1209
Jens Axboe756867b2007-03-06 15:19:24 +01001210 ts = &threadstats[j];
1211
Yu-ju Hong83349192011-08-13 00:53:44 +02001212 ts->clat_percentiles = td->o.clat_percentiles;
1213 if (td->o.overwrite_plist)
Jens Axboe802ad4a2011-10-05 09:51:58 +02001214 memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +02001215 else
Jens Axboe802ad4a2011-10-05 09:51:58 +02001216 memcpy(ts->percentile_list, def_percentile_list, sizeof(def_percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +02001217
Jens Axboe197574e2007-03-08 15:35:11 +01001218 idx++;
Jens Axboe6586ee82007-03-06 19:46:09 +01001219 ts->members++;
Jens Axboe756867b2007-03-06 15:19:24 +01001220
Jens Axboe7abd0e32007-03-12 15:24:43 +01001221 if (ts->groupid == -1) {
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001222 /*
1223 * These are per-group shared already
1224 */
Jens Axboef6bb5b82011-10-03 12:21:25 +02001225 strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE);
Jens Axboea64e88d2011-10-03 14:20:01 +02001226 if (td->o.description)
1227 strncpy(ts->description, td->o.description,
1228 FIO_JOBNAME_SIZE);
1229 else
1230 memset(ts->description, 0, FIO_JOBNAME_SIZE);
1231
Jens Axboe756867b2007-03-06 15:19:24 +01001232 ts->groupid = td->groupid;
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001233
1234 /*
1235 * first pid in group, not very useful...
1236 */
Jens Axboe756867b2007-03-06 15:19:24 +01001237 ts->pid = td->pid;
Jens Axboe90fef2d2009-07-17 22:33:32 +02001238
1239 ts->kb_base = td->o.kb_base;
Jens Axboe771e58b2013-01-30 12:56:23 +01001240 ts->unified_rw_rep = td->o.unified_rw_rep;
Jens Axboe90fef2d2009-07-17 22:33:32 +02001241 } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) {
1242 log_info("fio: kb_base differs for jobs in group, using"
1243 " %u as the base\n", ts->kb_base);
1244 kb_base_warned = 1;
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001245 }
1246
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001247 ts->continue_on_error = td->o.continue_on_error;
1248 ts->total_err_count += td->total_err_count;
1249 ts->first_error = td->first_error;
1250 if (!ts->error) {
1251 if (!td->error && td->o.continue_on_error &&
1252 td->first_error) {
1253 ts->error = td->first_error;
Jens Axboef6bb5b82011-10-03 12:21:25 +02001254 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001255 } else if (td->error) {
1256 ts->error = td->error;
Jens Axboef6bb5b82011-10-03 12:21:25 +02001257 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001258 }
Jens Axboe756867b2007-03-06 15:19:24 +01001259 }
1260
Jens Axboe5b9babb2011-10-10 12:14:30 +02001261 sum_thread_stats(ts, &td->ts, idx);
Jens Axboe756867b2007-03-06 15:19:24 +01001262 }
1263
1264 for (i = 0; i < nr_ts; i++) {
Jens Axboe94370ac2007-03-08 15:28:10 +01001265 unsigned long long bw;
Jens Axboe3c39a372006-06-06 20:56:12 +02001266
Jens Axboe756867b2007-03-06 15:19:24 +01001267 ts = &threadstats[i];
1268 rs = &runstats[ts->groupid];
Jens Axboe90fef2d2009-07-17 22:33:32 +02001269 rs->kb_base = ts->kb_base;
Jens Axboe771e58b2013-01-30 12:56:23 +01001270 rs->unified_rw_rep += ts->unified_rw_rep;
Jens Axboe3c39a372006-06-06 20:56:12 +02001271
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001272 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
Jens Axboe94370ac2007-03-08 15:28:10 +01001273 if (!ts->runtime[j])
1274 continue;
1275 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
1276 rs->min_run[j] = ts->runtime[j];
1277 if (ts->runtime[j] > rs->max_run[j])
1278 rs->max_run[j] = ts->runtime[j];
Jens Axboe3c39a372006-06-06 20:56:12 +02001279
Jens Axboe94370ac2007-03-08 15:28:10 +01001280 bw = 0;
Jens Axboe8879fd12009-04-20 10:06:02 +02001281 if (ts->runtime[j]) {
Jens Axboec857cfe2012-04-05 08:42:11 -06001282 unsigned long runt = ts->runtime[j];
1283 unsigned long long kb;
Jens Axboe8879fd12009-04-20 10:06:02 +02001284
Jens Axboec857cfe2012-04-05 08:42:11 -06001285 kb = ts->io_bytes[j] / rs->kb_base;
1286 bw = kb * 1000 / runt;
Jens Axboe8879fd12009-04-20 10:06:02 +02001287 }
Jens Axboe94370ac2007-03-08 15:28:10 +01001288 if (bw < rs->min_bw[j])
1289 rs->min_bw[j] = bw;
1290 if (bw > rs->max_bw[j])
1291 rs->max_bw[j] = bw;
Jens Axboe3c39a372006-06-06 20:56:12 +02001292
Jens Axboe90fef2d2009-07-17 22:33:32 +02001293 rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base;
Jens Axboe94370ac2007-03-08 15:28:10 +01001294 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001295 }
1296
1297 for (i = 0; i < groupid + 1; i++) {
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001298 int ddir;
1299
Jens Axboe3c39a372006-06-06 20:56:12 +02001300 rs = &runstats[i];
1301
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001302 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
1303 if (rs->max_run[ddir])
1304 rs->agg[ddir] = (rs->io_kb[ddir] * 1000) /
1305 rs->max_run[ddir];
1306 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001307 }
1308
1309 /*
1310 * don't overwrite last signal output
1311 */
Jens Axboef3afa572012-09-17 13:34:16 +02001312 if (output_format == FIO_OUTPUT_NORMAL)
Jens Axboe4ceb30d2010-02-24 09:19:14 +01001313 log_info("\n");
Jens Axboef3afa572012-09-17 13:34:16 +02001314 else if (output_format == FIO_OUTPUT_JSON) {
Shaohua Licc372b12012-09-17 09:12:18 +02001315 root = json_create_object();
1316 json_object_add_value_string(root, "fio version", fio_version_string);
1317 array = json_create_array();
1318 json_object_add_value_array(root, "jobs", array);
1319 }
1320
Jens Axboe756867b2007-03-06 15:19:24 +01001321 for (i = 0; i < nr_ts; i++) {
1322 ts = &threadstats[i];
1323 rs = &runstats[ts->groupid];
Jens Axboe3c39a372006-06-06 20:56:12 +02001324
Jens Axboea64e88d2011-10-03 14:20:01 +02001325 if (is_backend)
1326 fio_server_send_ts(ts, rs);
Jens Axboef3afa572012-09-17 13:34:16 +02001327 else if (output_format == FIO_OUTPUT_TERSE)
1328 show_thread_status_terse(ts, rs);
1329 else if (output_format == FIO_OUTPUT_JSON) {
1330 struct json_object *tmp = show_thread_status_json(ts, rs);
1331 json_array_add_value_object(array, tmp);
Shaohua Licc372b12012-09-17 09:12:18 +02001332 } else
Jens Axboe756867b2007-03-06 15:19:24 +01001333 show_thread_status(ts, rs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001334 }
Jens Axboef3afa572012-09-17 13:34:16 +02001335 if (output_format == FIO_OUTPUT_JSON) {
Shaohua Licc372b12012-09-17 09:12:18 +02001336 /* disk util stats, if any */
1337 show_disk_util(1, root);
1338
Huadong Liuf2a2ce02013-01-30 13:22:24 +01001339 show_idle_prof_stats(FIO_OUTPUT_JSON, root);
1340
Shaohua Licc372b12012-09-17 09:12:18 +02001341 json_print_object(root);
1342 log_info("\n");
1343 json_free_object(root);
1344 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001345
Jens Axboe72c27ff2011-10-16 11:50:31 +02001346 for (i = 0; i < groupid + 1; i++) {
1347 rs = &runstats[i];
Jens Axboea64e88d2011-10-03 14:20:01 +02001348
Jens Axboe72c27ff2011-10-16 11:50:31 +02001349 rs->groupid = i;
Jens Axboed09a64a2011-10-13 11:38:56 +02001350 if (is_backend)
Jens Axboe72c27ff2011-10-16 11:50:31 +02001351 fio_server_send_gs(rs);
Jens Axboef3afa572012-09-17 13:34:16 +02001352 else if (output_format == FIO_OUTPUT_NORMAL)
Jens Axboe72c27ff2011-10-16 11:50:31 +02001353 show_group_stats(rs);
Jens Axboec6ae0a52006-06-12 11:04:44 +02001354 }
Jens Axboeeecf2722006-10-20 14:00:36 +02001355
Jens Axboe72c27ff2011-10-16 11:50:31 +02001356 if (is_backend)
1357 fio_server_send_du();
Jens Axboef3afa572012-09-17 13:34:16 +02001358 else if (output_format == FIO_OUTPUT_NORMAL)
Shaohua Licc372b12012-09-17 09:12:18 +02001359 show_disk_util(0, NULL);
Jens Axboe72c27ff2011-10-16 11:50:31 +02001360
Huadong Liuf2a2ce02013-01-30 13:22:24 +01001361 show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL);
1362
Jens Axboeeecf2722006-10-20 14:00:36 +02001363 free(runstats);
Jens Axboe756867b2007-03-06 15:19:24 +01001364 free(threadstats);
Jens Axboe3c39a372006-06-06 20:56:12 +02001365}
1366
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001367static void *__show_running_run_stats(void *arg)
1368{
1369 struct thread_data *td;
1370 unsigned long long *rt;
1371 struct timeval tv;
1372 int i;
1373
1374 rt = malloc(thread_number * sizeof(unsigned long long));
1375 fio_gettime(&tv, NULL);
1376
1377 for_each_td(td, i) {
1378 rt[i] = mtime_since(&td->start, &tv);
1379 if (td_read(td) && td->io_bytes[DDIR_READ])
1380 td->ts.runtime[DDIR_READ] += rt[i];
1381 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1382 td->ts.runtime[DDIR_WRITE] += rt[i];
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001383 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1384 td->ts.runtime[DDIR_TRIM] += rt[i];
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001385
1386 update_rusage_stat(td);
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001387 td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ];
1388 td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
1389 td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001390 td->ts.total_run_time = mtime_since(&td->epoch, &tv);
1391 }
1392
1393 show_run_stats();
1394
1395 for_each_td(td, i) {
1396 if (td_read(td) && td->io_bytes[DDIR_READ])
1397 td->ts.runtime[DDIR_READ] -= rt[i];
1398 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1399 td->ts.runtime[DDIR_WRITE] -= rt[i];
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001400 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1401 td->ts.runtime[DDIR_TRIM] -= rt[i];
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001402 }
1403
1404 free(rt);
1405 return NULL;
1406}
1407
1408/*
1409 * Called from signal handler. It _should_ be safe to just run this inline
1410 * in the sig handler, but we should be disturbing the system less by just
1411 * creating a thread to do it.
1412 */
1413void show_running_run_stats(void)
1414{
1415 pthread_t thread;
1416
1417 pthread_create(&thread, NULL, __show_running_run_stats, NULL);
1418 pthread_detach(thread);
1419}
1420
Jens Axboe68704082007-01-10 19:56:37 +01001421static inline void add_stat_sample(struct io_stat *is, unsigned long data)
Jens Axboe3c39a372006-06-06 20:56:12 +02001422{
Jens Axboe68704082007-01-10 19:56:37 +01001423 double val = data;
Jens Axboe6660cc62007-03-06 15:48:38 +01001424 double delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001425
Jens Axboe68704082007-01-10 19:56:37 +01001426 if (data > is->max_val)
1427 is->max_val = data;
1428 if (data < is->min_val)
1429 is->min_val = data;
1430
Jens Axboe802ad4a2011-10-05 09:51:58 +02001431 delta = val - is->mean.u.f;
Jens Axboeef11d732007-03-29 15:36:29 +02001432 if (delta) {
Jens Axboe802ad4a2011-10-05 09:51:58 +02001433 is->mean.u.f += delta / (is->samples + 1.0);
1434 is->S.u.f += delta * (val - is->mean.u.f);
Jens Axboeef11d732007-03-29 15:36:29 +02001435 }
Jens Axboe68704082007-01-10 19:56:37 +01001436
Jens Axboe3c39a372006-06-06 20:56:12 +02001437 is->samples++;
1438}
1439
Jens Axboebb3884d2007-01-17 17:23:11 +11001440static void __add_log_sample(struct io_log *iolog, unsigned long val,
Jens Axboe306ddc92009-05-18 13:08:12 +02001441 enum fio_ddir ddir, unsigned int bs,
Jens Axboe2b13e712011-01-19 14:04:16 -07001442 unsigned long t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001443{
Jens Axboe306ddc92009-05-18 13:08:12 +02001444 const int nr_samples = iolog->nr_samples;
1445
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001446 if (!iolog->nr_samples)
1447 iolog->avg_last = t;
1448
Jens Axboe3c39a372006-06-06 20:56:12 +02001449 if (iolog->nr_samples == iolog->max_samples) {
1450 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
1451
1452 iolog->log = realloc(iolog->log, new_size);
1453 iolog->max_samples <<= 1;
1454 }
1455
Jens Axboe306ddc92009-05-18 13:08:12 +02001456 iolog->log[nr_samples].val = val;
Jens Axboe2b13e712011-01-19 14:04:16 -07001457 iolog->log[nr_samples].time = t;
Jens Axboe306ddc92009-05-18 13:08:12 +02001458 iolog->log[nr_samples].ddir = ddir;
1459 iolog->log[nr_samples].bs = bs;
Jens Axboe3c39a372006-06-06 20:56:12 +02001460 iolog->nr_samples++;
1461}
1462
Jens Axboe7fb28d32011-12-01 15:17:24 +01001463static inline void reset_io_stat(struct io_stat *ios)
1464{
1465 ios->max_val = ios->min_val = ios->samples = 0;
1466 ios->mean.u.f = ios->S.u.f = 0;
1467}
1468
Jens Axboebb3884d2007-01-17 17:23:11 +11001469static void add_log_sample(struct thread_data *td, struct io_log *iolog,
Jens Axboe306ddc92009-05-18 13:08:12 +02001470 unsigned long val, enum fio_ddir ddir,
1471 unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001472{
Jens Axboe7fb28d32011-12-01 15:17:24 +01001473 unsigned long elapsed, this_window;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001474
Jens Axboeff58fce2010-08-25 12:02:08 +02001475 if (!ddir_rw(ddir))
1476 return;
1477
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001478 elapsed = mtime_since_now(&td->epoch);
1479
1480 /*
1481 * If no time averaging, just add the log sample.
1482 */
1483 if (!iolog->avg_msec) {
1484 __add_log_sample(iolog, val, ddir, bs, elapsed);
1485 return;
1486 }
1487
1488 /*
1489 * Add the sample. If the time period has passed, then
1490 * add that entry to the log and clear.
1491 */
1492 add_stat_sample(&iolog->avg_window[ddir], val);
1493
Jens Axboe7fb28d32011-12-01 15:17:24 +01001494 /*
1495 * If period hasn't passed, adding the above sample is all we
1496 * need to do.
1497 */
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001498 this_window = elapsed - iolog->avg_last;
1499 if (this_window < iolog->avg_msec)
1500 return;
1501
Jens Axboe7fb28d32011-12-01 15:17:24 +01001502 /*
1503 * Note an entry in the log. Use the mean from the logged samples,
1504 * making sure to properly round up. Only write a log entry if we
1505 * had actual samples done.
1506 */
1507 if (iolog->avg_window[DDIR_READ].samples) {
1508 unsigned long mr;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001509
Jens Axboe7fb28d32011-12-01 15:17:24 +01001510 mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001511 __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed);
Jens Axboe7fb28d32011-12-01 15:17:24 +01001512 }
1513 if (iolog->avg_window[DDIR_WRITE].samples) {
1514 unsigned long mw;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001515
Jens Axboe7fb28d32011-12-01 15:17:24 +01001516 mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50;
1517 __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed);
1518 }
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001519 if (iolog->avg_window[DDIR_TRIM].samples) {
1520 unsigned long mw;
1521
1522 mw = iolog->avg_window[DDIR_TRIM].mean.u.f + 0.50;
1523 __add_log_sample(iolog, mw, DDIR_TRIM, 0, elapsed);
1524 }
1525
Jens Axboe7fb28d32011-12-01 15:17:24 +01001526
1527 reset_io_stat(&iolog->avg_window[DDIR_READ]);
1528 reset_io_stat(&iolog->avg_window[DDIR_WRITE]);
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001529 reset_io_stat(&iolog->avg_window[DDIR_TRIM]);
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001530 iolog->avg_last = elapsed;
Jens Axboebb3884d2007-01-17 17:23:11 +11001531}
1532
Jens Axboe306ddc92009-05-18 13:08:12 +02001533void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001534{
Jens Axboeff58fce2010-08-25 12:02:08 +02001535 struct io_log *iolog;
Jens Axboebb3884d2007-01-17 17:23:11 +11001536
Jens Axboeff58fce2010-08-25 12:02:08 +02001537 if (!ddir_rw(ddir))
1538 return;
1539
1540 iolog = agg_io_log[ddir];
Jens Axboe306ddc92009-05-18 13:08:12 +02001541 __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis());
Jens Axboebb3884d2007-01-17 17:23:11 +11001542}
1543
Yu-ju Hong83349192011-08-13 00:53:44 +02001544static void add_clat_percentile_sample(struct thread_stat *ts,
1545 unsigned long usec, enum fio_ddir ddir)
1546{
1547 unsigned int idx = plat_val_to_idx(usec);
1548 assert(idx < FIO_IO_U_PLAT_NR);
1549
1550 ts->io_u_plat[ddir][idx]++;
1551}
1552
Jens Axboe1e97cce2006-12-05 11:44:16 +01001553void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001554 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001555{
Jens Axboe756867b2007-03-06 15:19:24 +01001556 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001557
Jens Axboeff58fce2010-08-25 12:02:08 +02001558 if (!ddir_rw(ddir))
1559 return;
1560
Jens Axboed85f5112007-06-18 09:41:23 +02001561 add_stat_sample(&ts->clat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001562
Jens Axboe7b9f7332011-10-03 10:06:44 +02001563 if (td->clat_log)
1564 add_log_sample(td, td->clat_log, usec, ddir, bs);
Yu-ju Hong83349192011-08-13 00:53:44 +02001565
1566 if (ts->clat_percentiles)
1567 add_clat_percentile_sample(ts, usec, ddir);
Jens Axboe3c39a372006-06-06 20:56:12 +02001568}
1569
Jens Axboe1e97cce2006-12-05 11:44:16 +01001570void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001571 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001572{
Jens Axboe756867b2007-03-06 15:19:24 +01001573 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001574
Jens Axboeff58fce2010-08-25 12:02:08 +02001575 if (!ddir_rw(ddir))
1576 return;
1577
Jens Axboed85f5112007-06-18 09:41:23 +02001578 add_stat_sample(&ts->slat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001579
Jens Axboe7b9f7332011-10-03 10:06:44 +02001580 if (td->slat_log)
1581 add_log_sample(td, td->slat_log, usec, ddir, bs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001582}
1583
Jens Axboe02af0982010-06-24 09:59:34 +02001584void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
1585 unsigned long usec, unsigned int bs)
1586{
1587 struct thread_stat *ts = &td->ts;
1588
Jens Axboeff58fce2010-08-25 12:02:08 +02001589 if (!ddir_rw(ddir))
1590 return;
1591
Jens Axboe02af0982010-06-24 09:59:34 +02001592 add_stat_sample(&ts->lat_stat[ddir], usec);
1593
Jens Axboe7b9f7332011-10-03 10:06:44 +02001594 if (td->lat_log)
1595 add_log_sample(td, td->lat_log, usec, ddir, bs);
Jens Axboe02af0982010-06-24 09:59:34 +02001596}
1597
Jens Axboe306ddc92009-05-18 13:08:12 +02001598void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
Jens Axboe1e97cce2006-12-05 11:44:16 +01001599 struct timeval *t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001600{
Jens Axboe756867b2007-03-06 15:19:24 +01001601 struct thread_stat *ts = &td->ts;
Jens Axboeff58fce2010-08-25 12:02:08 +02001602 unsigned long spent, rate;
Jens Axboe3c39a372006-06-06 20:56:12 +02001603
Jens Axboeff58fce2010-08-25 12:02:08 +02001604 if (!ddir_rw(ddir))
1605 return;
1606
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001607 spent = mtime_since(&td->bw_sample_time, t);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001608 if (spent < td->o.bw_avg_time)
Jens Axboe3c39a372006-06-06 20:56:12 +02001609 return;
Jens Axboe9602d8d2012-02-20 20:19:28 +01001610
1611 /*
Josh Carter5daa4eb2012-02-20 10:12:22 +01001612 * Compute both read and write rates for the interval.
1613 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001614 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
Josh Carter5daa4eb2012-02-20 10:12:22 +01001615 uint64_t delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001616
Josh Carter5daa4eb2012-02-20 10:12:22 +01001617 delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir];
1618 if (!delta)
1619 continue; /* No entries for interval */
Jens Axboe3c39a372006-06-06 20:56:12 +02001620
Josh Carter5daa4eb2012-02-20 10:12:22 +01001621 rate = delta * 1000 / spent / 1024;
1622 add_stat_sample(&ts->bw_stat[ddir], rate);
1623
1624 if (td->bw_log)
1625 add_log_sample(td, td->bw_log, rate, ddir, bs);
1626
1627 td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
1628 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001629
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001630 fio_gettime(&td->bw_sample_time, NULL);
Jens Axboe3c39a372006-06-06 20:56:12 +02001631}
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001632
1633void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,
1634 struct timeval *t)
1635{
1636 struct thread_stat *ts = &td->ts;
1637 unsigned long spent, iops;
1638
1639 if (!ddir_rw(ddir))
1640 return;
1641
1642 spent = mtime_since(&td->iops_sample_time, t);
1643 if (spent < td->o.iops_avg_time)
1644 return;
1645
Jens Axboe9602d8d2012-02-20 20:19:28 +01001646 /*
1647 * Compute both read and write rates for the interval.
1648 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001649 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
Jens Axboe9602d8d2012-02-20 20:19:28 +01001650 uint64_t delta;
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001651
Jens Axboe9602d8d2012-02-20 20:19:28 +01001652 delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir];
1653 if (!delta)
1654 continue; /* No entries for interval */
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001655
Jens Axboe9602d8d2012-02-20 20:19:28 +01001656 iops = (delta * 1000) / spent;
1657 add_stat_sample(&ts->iops_stat[ddir], iops);
1658
1659 if (td->iops_log)
1660 add_log_sample(td, td->iops_log, iops, ddir, 0);
1661
Jens Axboe421f4a82012-02-28 08:20:26 +01001662 td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
Jens Axboe9602d8d2012-02-20 20:19:28 +01001663 }
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001664
1665 fio_gettime(&td->iops_sample_time, NULL);
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001666}