blob: d041ef3c0bb56c770334d551061824113c8b5b2d [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 Axboe3c39a372006-06-06 20:56:12 +020014
Jens Axboe3c39a372006-06-06 20:56:12 +020015void update_rusage_stat(struct thread_data *td)
16{
Jens Axboe756867b2007-03-06 15:19:24 +010017 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +020018
Jens Axboec8aaba12011-10-03 12:14:19 +020019 getrusage(RUSAGE_SELF, &td->ru_end);
Jens Axboe079ad092007-02-20 13:58:20 +010020
Jens Axboec8aaba12011-10-03 12:14:19 +020021 ts->usr_time += mtime_since(&td->ru_start.ru_utime,
22 &td->ru_end.ru_utime);
23 ts->sys_time += mtime_since(&td->ru_start.ru_stime,
24 &td->ru_end.ru_stime);
25 ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw
26 - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw);
27 ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt;
28 ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010029
Jens Axboec8aaba12011-10-03 12:14:19 +020030 memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end));
Jens Axboe3c39a372006-06-06 20:56:12 +020031}
32
Yu-ju Hong83349192011-08-13 00:53:44 +020033/*
34 * Given a latency, return the index of the corresponding bucket in
35 * the structure tracking percentiles.
36 *
37 * (1) find the group (and error bits) that the value (latency)
38 * belongs to by looking at its MSB. (2) find the bucket number in the
39 * group by looking at the index bits.
40 *
41 */
42static unsigned int plat_val_to_idx(unsigned int val)
43{
44 unsigned int msb, error_bits, base, offset, idx;
45
46 /* Find MSB starting from bit 0 */
47 if (val == 0)
48 msb = 0;
49 else
50 msb = (sizeof(val)*8) - __builtin_clz(val) - 1;
51
Jens Axboe716050f2011-08-16 08:43:45 +020052 /*
53 * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
54 * all bits of the sample as index
55 */
Yu-ju Hong83349192011-08-13 00:53:44 +020056 if (msb <= FIO_IO_U_PLAT_BITS)
57 return val;
58
59 /* Compute the number of error bits to discard*/
60 error_bits = msb - FIO_IO_U_PLAT_BITS;
61
62 /* Compute the number of buckets before the group */
63 base = (error_bits + 1) << FIO_IO_U_PLAT_BITS;
64
Jens Axboe716050f2011-08-16 08:43:45 +020065 /*
66 * Discard the error bits and apply the mask to find the
67 * index for the buckets in the group
68 */
Yu-ju Hong83349192011-08-13 00:53:44 +020069 offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits);
70
71 /* Make sure the index does not exceed (array size - 1) */
72 idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1)?
73 (base + offset) : (FIO_IO_U_PLAT_NR - 1);
74
75 return idx;
76}
77
78/*
79 * Convert the given index of the bucket array to the value
80 * represented by the bucket
81 */
82static unsigned int plat_idx_to_val(unsigned int idx)
83{
84 unsigned int error_bits, k, base;
85
86 assert(idx < FIO_IO_U_PLAT_NR);
87
88 /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
89 * all bits of the sample as index */
90 if (idx < (FIO_IO_U_PLAT_VAL << 1) )
91 return idx;
92
93 /* Find the group and compute the minimum value of that group */
94 error_bits = (idx >> FIO_IO_U_PLAT_BITS) -1;
95 base = 1 << (error_bits + FIO_IO_U_PLAT_BITS);
96
97 /* Find its bucket number of the group */
98 k = idx % FIO_IO_U_PLAT_VAL;
99
100 /* Return the mean of the range of the bucket */
101 return base + ((k + 0.5) * (1 << error_bits));
102}
103
104static int double_cmp(const void *a, const void *b)
105{
Jens Axboe802ad4a2011-10-05 09:51:58 +0200106 const fio_fp64_t fa = *(const fio_fp64_t *) a;
107 const fio_fp64_t fb = *(const fio_fp64_t *) b;
Yu-ju Hong83349192011-08-13 00:53:44 +0200108 int cmp = 0;
109
Jens Axboe802ad4a2011-10-05 09:51:58 +0200110 if (fa.u.f > fb.u.f)
Yu-ju Hong83349192011-08-13 00:53:44 +0200111 cmp = 1;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200112 else if (fa.u.f < fb.u.f)
Yu-ju Hong83349192011-08-13 00:53:44 +0200113 cmp = -1;
114
115 return cmp;
116}
117
Jens Axboe1db92cb2011-10-13 13:43:36 +0200118static unsigned int calc_clat_percentiles(unsigned int *io_u_plat,
119 unsigned long nr, fio_fp64_t *plist,
120 unsigned int **output,
121 unsigned int *maxv,
122 unsigned int *minv)
Yu-ju Hong83349192011-08-13 00:53:44 +0200123{
124 unsigned long sum = 0;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200125 unsigned int len, i, j = 0;
126 unsigned int oval_len = 0;
127 unsigned int *ovals = NULL;
128 int is_last;
129
130 *minv = -1U;
131 *maxv = 0;
Yu-ju Hong83349192011-08-13 00:53:44 +0200132
Jens Axboe802ad4a2011-10-05 09:51:58 +0200133 len = 0;
134 while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0)
135 len++;
Jens Axboe716050f2011-08-16 08:43:45 +0200136
Jens Axboe351de8d2011-10-12 21:03:45 +0200137 if (!len)
Jens Axboe1db92cb2011-10-13 13:43:36 +0200138 return 0;
Jens Axboe351de8d2011-10-12 21:03:45 +0200139
Jens Axboe716050f2011-08-16 08:43:45 +0200140 /*
Jens Axboe802ad4a2011-10-05 09:51:58 +0200141 * Sort the percentile list. Note that it may already be sorted if
142 * we are using the default values, but since it's a short list this
143 * isn't a worry. Also note that this does not work for NaN values.
Jens Axboe716050f2011-08-16 08:43:45 +0200144 */
Jens Axboe802ad4a2011-10-05 09:51:58 +0200145 if (len > 1)
146 qsort((void*)plist, len, sizeof(plist[0]), double_cmp);
Yu-ju Hong83349192011-08-13 00:53:44 +0200147
Jens Axboe4f6f8292011-10-13 09:28:21 +0200148 /*
149 * Calculate bucket values, note down max and min values
150 */
Jens Axboe07511a62011-10-13 12:00:24 +0200151 is_last = 0;
152 for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) {
Yu-ju Hong83349192011-08-13 00:53:44 +0200153 sum += io_u_plat[i];
Jens Axboe802ad4a2011-10-05 09:51:58 +0200154 while (sum >= (plist[j].u.f / 100.0 * nr)) {
155 assert(plist[j].u.f <= 100.0);
Yu-ju Hong83349192011-08-13 00:53:44 +0200156
Jens Axboe4f6f8292011-10-13 09:28:21 +0200157 if (j == oval_len) {
158 oval_len += 100;
159 ovals = realloc(ovals, oval_len * sizeof(unsigned int));
160 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200161
Jens Axboe4f6f8292011-10-13 09:28:21 +0200162 ovals[j] = plat_idx_to_val(i);
Jens Axboe1db92cb2011-10-13 13:43:36 +0200163 if (ovals[j] < *minv)
164 *minv = ovals[j];
165 if (ovals[j] > *maxv)
166 *maxv = ovals[j];
Jens Axboe07511a62011-10-13 12:00:24 +0200167
168 is_last = (j == len - 1);
169 if (is_last)
170 break;
171
Jens Axboe4f6f8292011-10-13 09:28:21 +0200172 j++;
Yu-ju Hong83349192011-08-13 00:53:44 +0200173 }
174 }
Jens Axboe4f6f8292011-10-13 09:28:21 +0200175
Jens Axboe1db92cb2011-10-13 13:43:36 +0200176 *output = ovals;
177 return len;
178}
179
180/*
181 * Find and display the p-th percentile of clat
182 */
183static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
184 fio_fp64_t *plist)
185{
186 unsigned int len, j = 0, minv, maxv;
187 unsigned int *ovals;
188 int is_last, scale_down;
189
190 len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
191 if (!len)
192 goto out;
193
Jens Axboe4f6f8292011-10-13 09:28:21 +0200194 /*
195 * We default to usecs, but if the value range is such that we
196 * should scale down to msecs, do that.
197 */
198 if (minv > 2000 && maxv > 99999) {
199 scale_down = 1;
200 log_info(" clat percentiles (msec):\n |");
201 } else {
202 scale_down = 0;
203 log_info(" clat percentiles (usec):\n |");
204 }
205
206 for (j = 0; j < len; j++) {
207 char fbuf[8];
208
209 /* for formatting */
210 if (j != 0 && (j % 4) == 0)
211 log_info(" |");
212
213 /* end of the list */
214 is_last = (j == len - 1);
215
216 if (plist[j].u.f < 10.0)
217 sprintf(fbuf, " %2.2f", plist[j].u.f);
218 else
219 sprintf(fbuf, "%2.2f", plist[j].u.f);
220
221 if (scale_down)
222 ovals[j] = (ovals[j] + 999) / 1000;
223
224 log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ',');
225
226 if (is_last)
227 break;
228
229 if (j % 4 == 3) /* for formatting */
230 log_info("\n");
231 }
232
Jens Axboe1db92cb2011-10-13 13:43:36 +0200233out:
Jens Axboe4f6f8292011-10-13 09:28:21 +0200234 if (ovals)
235 free(ovals);
Yu-ju Hong83349192011-08-13 00:53:44 +0200236}
237
Jens Axboe3c39a372006-06-06 20:56:12 +0200238static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
239 double *mean, double *dev)
240{
Jens Axboe68704082007-01-10 19:56:37 +0100241 double n = is->samples;
Jens Axboe3c39a372006-06-06 20:56:12 +0200242
243 if (is->samples == 0)
244 return 0;
245
246 *min = is->min_val;
247 *max = is->max_val;
248
249 n = (double) is->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200250 *mean = is->mean.u.f;
Jens Axboe3c39a372006-06-06 20:56:12 +0200251
Jens Axboe68704082007-01-10 19:56:37 +0100252 if (n > 1.0)
Jens Axboe802ad4a2011-10-05 09:51:58 +0200253 *dev = sqrt(is->S.u.f / (n - 1.0));
Jens Axboeef9c5c42007-01-03 14:21:13 +0100254 else
Jens Axboe4b43f542007-07-19 21:38:35 +0200255 *dev = 0;
Jens Axboeef9c5c42007-01-03 14:21:13 +0100256
Jens Axboe3c39a372006-06-06 20:56:12 +0200257 return 1;
258}
259
Jens Axboea64e88d2011-10-03 14:20:01 +0200260void show_group_stats(struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200261{
Jens Axboedbe11252007-02-11 00:19:51 +0100262 char *p1, *p2, *p3, *p4;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200263 const char *ddir_str[] = { " READ", " WRITE" , " TRIM"};
Jens Axboedbe11252007-02-11 00:19:51 +0100264 int i;
265
Jens Axboe7e1773b2011-10-14 12:47:56 +0200266 log_info("\nRun status group %d (all jobs):\n", rs->groupid);
Jens Axboe3c39a372006-06-06 20:56:12 +0200267
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200268 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200269 const int i2p = is_power_of_2(rs->kb_base);
270
Jens Axboedbe11252007-02-11 00:19:51 +0100271 if (!rs->max_run[i])
272 continue;
273
Jens Axboe90fef2d2009-07-17 22:33:32 +0200274 p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p);
275 p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p);
276 p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p);
277 p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p);
Jens Axboedbe11252007-02-11 00:19:51 +0100278
Jens Axboeb22989b2009-07-17 22:29:23 +0200279 log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s,"
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100280 " mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2,
281 p3, p4, rs->min_run[i],
282 rs->max_run[i]);
Jens Axboedbe11252007-02-11 00:19:51 +0100283
284 free(p1);
285 free(p2);
286 free(p3);
287 free(p4);
288 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200289}
290
Jens Axboeb3605062007-03-12 14:19:47 +0100291#define ts_total_io_u(ts) \
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200292 ((ts)->total_io_u[DDIR_READ] + (ts)->total_io_u[DDIR_WRITE] +\
293 (ts)->total_io_u[DDIR_TRIM])
Jens Axboeb3605062007-03-12 14:19:47 +0100294
Jens Axboe838bc702008-05-22 13:08:23 +0200295static void stat_calc_dist(unsigned int *map, unsigned long total,
296 double *io_u_dist)
Jens Axboe22708902007-03-06 17:05:32 +0100297{
298 int i;
299
300 /*
301 * Do depth distribution calculations
302 */
303 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200304 if (total) {
305 io_u_dist[i] = (double) map[i] / (double) total;
306 io_u_dist[i] *= 100.0;
307 if (io_u_dist[i] < 0.1 && map[i])
308 io_u_dist[i] = 0.1;
309 } else
310 io_u_dist[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100311 }
312}
313
Jens Axboe04a0fea2007-06-19 12:48:41 +0200314static void stat_calc_lat(struct thread_stat *ts, double *dst,
315 unsigned int *src, int nr)
Jens Axboe22708902007-03-06 17:05:32 +0100316{
Jens Axboe838bc702008-05-22 13:08:23 +0200317 unsigned long total = ts_total_io_u(ts);
Jens Axboe22708902007-03-06 17:05:32 +0100318 int i;
319
320 /*
321 * Do latency distribution calculations
322 */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200323 for (i = 0; i < nr; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200324 if (total) {
325 dst[i] = (double) src[i] / (double) total;
326 dst[i] *= 100.0;
327 if (dst[i] < 0.01 && src[i])
328 dst[i] = 0.01;
329 } else
330 dst[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100331 }
332}
333
Jens Axboe04a0fea2007-06-19 12:48:41 +0200334static void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
335{
336 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
337}
338
339static void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
340{
341 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
342}
343
Jens Axboeea2accc2007-06-19 09:48:44 +0200344static int usec_to_msec(unsigned long *min, unsigned long *max, double *mean,
345 double *dev)
346{
347 if (*min > 1000 && *max > 1000 && *mean > 1000.0 && *dev > 1000.0) {
348 *min /= 1000;
349 *max /= 1000;
350 *mean /= 1000.0;
351 *dev /= 1000.0;
352 return 0;
353 }
354
355 return 1;
356}
357
Jens Axboe756867b2007-03-06 15:19:24 +0100358static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
Jens Axboe3c39a372006-06-06 20:56:12 +0200359 int ddir)
360{
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200361 const char *ddir_str[] = { "read ", "write", "trim" };
Jens Axboe8879fd12009-04-20 10:06:02 +0200362 unsigned long min, max, runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100363 unsigned long long bw, iops;
Jens Axboe3c39a372006-06-06 20:56:12 +0200364 double mean, dev;
Jens Axboeb3605062007-03-12 14:19:47 +0100365 char *io_p, *bw_p, *iops_p;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200366 int i2p;
Jens Axboe3c39a372006-06-06 20:56:12 +0200367
Jens Axboeff58fce2010-08-25 12:02:08 +0200368 assert(ddir_rw(ddir));
369
Jens Axboe756867b2007-03-06 15:19:24 +0100370 if (!ts->runtime[ddir])
Jens Axboe3c39a372006-06-06 20:56:12 +0200371 return;
372
Jens Axboe90fef2d2009-07-17 22:33:32 +0200373 i2p = is_power_of_2(rs->kb_base);
Jens Axboe8879fd12009-04-20 10:06:02 +0200374 runt = ts->runtime[ddir];
375
376 bw = (1000 * ts->io_bytes[ddir]) / runt;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200377 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
378 bw_p = num2str(bw, 6, 1, i2p);
Jens Axboe8879fd12009-04-20 10:06:02 +0200379
Bruce Cran0aacc502011-07-09 08:19:53 +0200380 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100381 iops_p = num2str(iops, 6, 1, 0);
Jens Axboedbe11252007-02-11 00:19:51 +0100382
Signed-off-by Steven Prattcda99fa2010-12-14 08:31:36 +0100383 log_info(" %s: io=%sB, bw=%sB/s, iops=%s, runt=%6llumsec\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100384 ddir_str[ddir], io_p, bw_p, iops_p,
385 ts->runtime[ddir]);
Jens Axboedbe11252007-02-11 00:19:51 +0100386
387 free(io_p);
388 free(bw_p);
Jens Axboeb3605062007-03-12 14:19:47 +0100389 free(iops_p);
Jens Axboe3c39a372006-06-06 20:56:12 +0200390
Jens Axboed85f5112007-06-18 09:41:23 +0200391 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
392 const char *base = "(usec)";
Jens Axboed9309cb2007-08-16 13:07:46 +0200393 char *minp, *maxp;
Jens Axboe3c39a372006-06-06 20:56:12 +0200394
Jens Axboeea2accc2007-06-19 09:48:44 +0200395 if (!usec_to_msec(&min, &max, &mean, &dev))
Jens Axboed85f5112007-06-18 09:41:23 +0200396 base = "(msec)";
Jens Axboeea2accc2007-06-19 09:48:44 +0200397
Jens Axboed9309cb2007-08-16 13:07:46 +0200398 minp = num2str(min, 6, 1, 0);
399 maxp = num2str(max, 6, 1, 0);
400
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100401 log_info(" slat %s: min=%s, max=%s, avg=%5.02f,"
402 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
Jens Axboed9309cb2007-08-16 13:07:46 +0200403
404 free(minp);
405 free(maxp);
Jens Axboed85f5112007-06-18 09:41:23 +0200406 }
407 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
408 const char *base = "(usec)";
Jens Axboed9309cb2007-08-16 13:07:46 +0200409 char *minp, *maxp;
Jens Axboe3c39a372006-06-06 20:56:12 +0200410
Jens Axboeea2accc2007-06-19 09:48:44 +0200411 if (!usec_to_msec(&min, &max, &mean, &dev))
412 base = "(msec)";
413
Jens Axboed9309cb2007-08-16 13:07:46 +0200414 minp = num2str(min, 6, 1, 0);
415 maxp = num2str(max, 6, 1, 0);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100416
417 log_info(" clat %s: min=%s, max=%s, avg=%5.02f,"
418 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
Jens Axboed9309cb2007-08-16 13:07:46 +0200419
420 free(minp);
421 free(maxp);
Jens Axboed85f5112007-06-18 09:41:23 +0200422 }
Jens Axboe02af0982010-06-24 09:59:34 +0200423 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) {
424 const char *base = "(usec)";
425 char *minp, *maxp;
426
427 if (!usec_to_msec(&min, &max, &mean, &dev))
428 base = "(msec)";
429
430 minp = num2str(min, 6, 1, 0);
431 maxp = num2str(max, 6, 1, 0);
432
433 log_info(" lat %s: min=%s, max=%s, avg=%5.02f,"
434 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
435
436 free(minp);
437 free(maxp);
438 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200439 if (ts->clat_percentiles) {
440 show_clat_percentiles(ts->io_u_plat[ddir],
441 ts->clat_stat[ddir].samples,
442 ts->percentile_list);
443 }
Jens Axboe079ad092007-02-20 13:58:20 +0100444 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100445 double p_of_agg = 100.0;
Jens Axboeb7017e32011-10-14 09:30:01 +0200446 const char *bw_str = "KB";
Jens Axboe3c39a372006-06-06 20:56:12 +0200447
Jens Axboe2f2c6922012-02-07 16:42:43 +0100448 if (rs->agg[ddir]) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100449 p_of_agg = mean * 100 / (double) rs->agg[ddir];
450 if (p_of_agg > 100.0)
451 p_of_agg = 100.0;
452 }
Jens Axboeb7017e32011-10-14 09:30:01 +0200453
454 if (mean > 999999.9) {
455 min /= 1000.0;
456 max /= 1000.0;
457 mean /= 1000.0;
458 dev /= 1000.0;
459 bw_str = "MB";
460 }
461
Jens Axboe7e1773b2011-10-14 12:47:56 +0200462 log_info(" bw (%s/s) : min=%5lu, max=%5lu, per=%3.2f%%,"
Jens Axboeb7017e32011-10-14 09:30:01 +0200463 " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max,
464 p_of_agg, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200465 }
466}
467
Jens Axboe7e1773b2011-10-14 12:47:56 +0200468static int show_lat(double *io_u_lat, int nr, const char **ranges,
469 const char *msg)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200470{
Jens Axboe7e1773b2011-10-14 12:47:56 +0200471 int new_line = 1, i, line = 0, shown = 0;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200472
473 for (i = 0; i < nr; i++) {
474 if (io_u_lat[i] <= 0.0)
475 continue;
Jens Axboe7e1773b2011-10-14 12:47:56 +0200476 shown = 1;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200477 if (new_line) {
Jens Axboe4539ed72007-07-23 14:21:17 +0200478 if (line)
479 log_info("\n");
Jens Axboe7e1773b2011-10-14 12:47:56 +0200480 log_info(" lat (%s) : ", msg);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200481 new_line = 0;
482 line = 0;
483 }
484 if (line)
485 log_info(", ");
486 log_info("%s%3.2f%%", ranges[i], io_u_lat[i]);
487 line++;
488 if (line == 5)
489 new_line = 1;
490 }
Jens Axboe7e1773b2011-10-14 12:47:56 +0200491
492 if (shown)
493 log_info("\n");
494
495 return shown;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200496}
497
498static void show_lat_u(double *io_u_lat_u)
499{
500 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
501 "250=", "500=", "750=", "1000=", };
502
503 show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec");
504}
505
506static void show_lat_m(double *io_u_lat_m)
507{
508 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
509 "250=", "500=", "750=", "1000=", "2000=",
510 ">=2000=", };
511
512 show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec");
513}
514
515static void show_latencies(double *io_u_lat_u, double *io_u_lat_m)
516{
517 show_lat_u(io_u_lat_u);
518 show_lat_m(io_u_lat_m);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200519}
520
Jens Axboea64e88d2011-10-03 14:20:01 +0200521void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200522{
523 double usr_cpu, sys_cpu;
Jens Axboe69008992006-11-24 13:12:56 +0100524 unsigned long runtime;
Jens Axboe71619dc2007-01-13 23:56:33 +0100525 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200526 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
527 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboe57a64322012-06-14 15:11:15 +0200528 time_t time_p;
529 char time_buf[64];
Jens Axboe3c39a372006-06-06 20:56:12 +0200530
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200531 if (!(ts->io_bytes[DDIR_READ] + ts->io_bytes[DDIR_WRITE] +
532 ts->io_bytes[DDIR_TRIM]) && !(ts->total_io_u[DDIR_READ] +
533 ts->total_io_u[DDIR_WRITE] + ts->total_io_u[DDIR_TRIM]))
Jens Axboe3c39a372006-06-06 20:56:12 +0200534 return;
535
Jens Axboe57a64322012-06-14 15:11:15 +0200536 time(&time_p);
Saurabh De45054cb2012-10-09 14:46:24 -0600537 os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf));
Jens Axboe57a64322012-06-14 15:11:15 +0200538
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100539 if (!ts->error) {
Jens Axboe57a64322012-06-14 15:11:15 +0200540 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100541 ts->name, ts->groupid, ts->members,
Jens Axboe57a64322012-06-14 15:11:15 +0200542 ts->error, (int) ts->pid, time_buf);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100543 } else {
Jens Axboe57a64322012-06-14 15:11:15 +0200544 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100545 ts->name, ts->groupid, ts->members,
Jens Axboe57a64322012-06-14 15:11:15 +0200546 ts->error, ts->verror, (int) ts->pid,
547 time_buf);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100548 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200549
Jens Axboe259e47d2011-10-13 21:05:59 +0200550 if (strlen(ts->description))
Jens Axboe6d861442007-03-15 09:22:23 +0100551 log_info(" Description : [%s]\n", ts->description);
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100552
Jens Axboe756867b2007-03-06 15:19:24 +0100553 if (ts->io_bytes[DDIR_READ])
554 show_ddir_status(rs, ts, DDIR_READ);
555 if (ts->io_bytes[DDIR_WRITE])
556 show_ddir_status(rs, ts, DDIR_WRITE);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200557 if (ts->io_bytes[DDIR_TRIM])
558 show_ddir_status(rs, ts, DDIR_TRIM);
Jens Axboe3c39a372006-06-06 20:56:12 +0200559
Jens Axboe7e1773b2011-10-14 12:47:56 +0200560 stat_calc_lat_u(ts, io_u_lat_u);
561 stat_calc_lat_m(ts, io_u_lat_m);
562 show_latencies(io_u_lat_u, io_u_lat_m);
563
Jens Axboe756867b2007-03-06 15:19:24 +0100564 runtime = ts->total_run_time;
Jens Axboe69008992006-11-24 13:12:56 +0100565 if (runtime) {
Jens Axboe1e97cce2006-12-05 11:44:16 +0100566 double runt = (double) runtime;
Jens Axboe3c39a372006-06-06 20:56:12 +0200567
Jens Axboe756867b2007-03-06 15:19:24 +0100568 usr_cpu = (double) ts->usr_time * 100 / runt;
569 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboe3c39a372006-06-06 20:56:12 +0200570 } else {
571 usr_cpu = 0;
572 sys_cpu = 0;
573 }
574
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100575 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu,"
576 " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf);
Jens Axboe71619dc2007-01-13 23:56:33 +0100577
Jens Axboe838bc702008-05-22 13:08:23 +0200578 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100579 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%,"
580 " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
581 io_u_dist[1], io_u_dist[2],
582 io_u_dist[3], io_u_dist[4],
583 io_u_dist[5], io_u_dist[6]);
Jens Axboe838bc702008-05-22 13:08:23 +0200584
585 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
586 log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
587 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
588 io_u_dist[1], io_u_dist[2],
589 io_u_dist[3], io_u_dist[4],
590 io_u_dist[5], io_u_dist[6]);
591 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
592 log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
593 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
594 io_u_dist[1], io_u_dist[2],
595 io_u_dist[3], io_u_dist[4],
596 io_u_dist[5], io_u_dist[6]);
Jens Axboe7e1773b2011-10-14 12:47:56 +0200597 log_info(" issued : total=r=%lu/w=%lu/d=%lu,"
598 " short=r=%lu/w=%lu/d=%lu\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100599 ts->total_io_u[0], ts->total_io_u[1],
Jens Axboe0d29de82010-09-01 13:54:15 +0200600 ts->total_io_u[2],
601 ts->short_io_u[0], ts->short_io_u[1],
602 ts->short_io_u[2]);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200603 if (ts->continue_on_error) {
Jens Axboe1ec99ee2009-06-15 12:37:30 +0200604 log_info(" errors : total=%lu, first_error=%d/<%s>\n",
605 ts->total_err_count,
606 ts->first_error,
607 strerror(ts->first_error));
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200608 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200609}
610
Jens Axboe756867b2007-03-06 15:19:24 +0100611static void show_ddir_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200612 struct group_run_stats *rs, int ddir)
613{
614 unsigned long min, max;
Jens Axboe312b4af2011-10-13 13:11:42 +0200615 unsigned long long bw, iops;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200616 unsigned int *ovals = NULL;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200617 double mean, dev;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200618 unsigned int len, minv, maxv;
619 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200620
Jens Axboeff58fce2010-08-25 12:02:08 +0200621 assert(ddir_rw(ddir));
622
Jens Axboe312b4af2011-10-13 13:11:42 +0200623 iops = bw = 0;
624 if (ts->runtime[ddir]) {
625 uint64_t runt = ts->runtime[ddir];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200626
Jens Axboe033bbb52012-05-07 09:46:40 +0200627 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
Jens Axboe312b4af2011-10-13 13:11:42 +0200628 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
629 }
630
631 log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops,
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100632 ts->runtime[ddir]);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200633
Jens Axboe079ad092007-02-20 13:58:20 +0100634 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100635 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200636 else
Jens Axboe6d861442007-03-15 09:22:23 +0100637 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200638
Jens Axboe079ad092007-02-20 13:58:20 +0100639 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100640 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200641 else
Jens Axboe6d861442007-03-15 09:22:23 +0100642 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200643
Jens Axboe1db92cb2011-10-13 13:43:36 +0200644 if (ts->clat_percentiles) {
645 len = calc_clat_percentiles(ts->io_u_plat[ddir],
646 ts->clat_stat[ddir].samples,
647 ts->percentile_list, &ovals, &maxv,
648 &minv);
649 } else
650 len = 0;
651
652 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
653 if (i >= len) {
654 log_info(";0%%=0");
655 continue;
656 }
657 log_info(";%2.2f%%=%u", ts->percentile_list[i].u.f, ovals[i]);
658 }
Keplar kramer2341a372011-10-19 21:31:27 +0200659
660 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
661 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
662 else
663 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
664
Jens Axboe1db92cb2011-10-13 13:43:36 +0200665 if (ovals)
666 free(ovals);
667
Jens Axboe079ad092007-02-20 13:58:20 +0100668 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100669 double p_of_agg = 100.0;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200670
Jens Axboe19d3e962012-02-07 12:27:28 +0100671 if (rs->agg[ddir]) {
672 p_of_agg = mean * 100 / (double) rs->agg[ddir];
673 if (p_of_agg > 100.0)
674 p_of_agg = 100.0;
675 }
676
Jens Axboe6d861442007-03-15 09:22:23 +0100677 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200678 } else
Jens Axboe6d861442007-03-15 09:22:23 +0100679 log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200680}
681
Shaohua Licc372b12012-09-17 09:12:18 +0200682static void add_ddir_status_json(struct thread_stat *ts,
683 struct group_run_stats *rs, int ddir, struct json_object *parent)
684{
685 unsigned long min, max;
686 unsigned long long bw, iops;
687 unsigned int *ovals = NULL;
688 double mean, dev;
689 unsigned int len, minv, maxv;
690 int i;
691 const char *ddirname[] = {"read", "write", "trim"};
692 struct json_object *dir_object, *tmp_object, *percentile_object;
693 char buf[120];
694 double p_of_agg = 100.0;
695
696 assert(ddir_rw(ddir));
697
698 dir_object = json_create_object();
699 json_object_add_value_object(parent, ddirname[ddir], dir_object);
700
701 iops = bw = 0;
702 if (ts->runtime[ddir]) {
703 uint64_t runt = ts->runtime[ddir];
704
705 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
706 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
707 }
708
709 json_object_add_value_int(dir_object, "io_bytes", ts->io_bytes[ddir] >> 10);
710 json_object_add_value_int(dir_object, "bw", bw);
711 json_object_add_value_int(dir_object, "iops", iops);
712 json_object_add_value_int(dir_object, "runtime", ts->runtime[ddir]);
713
714 if (!calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
715 min = max = 0;
716 mean = dev = 0.0;
717 }
718 tmp_object = json_create_object();
719 json_object_add_value_object(dir_object, "slat", tmp_object);
720 json_object_add_value_int(tmp_object, "min", min);
721 json_object_add_value_int(tmp_object, "max", max);
722 json_object_add_value_float(tmp_object, "mean", mean);
723 json_object_add_value_float(tmp_object, "stddev", dev);
724
725 if (!calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
726 min = max = 0;
727 mean = dev = 0.0;
728 }
729 tmp_object = json_create_object();
730 json_object_add_value_object(dir_object, "clat", tmp_object);
731 json_object_add_value_int(tmp_object, "min", min);
732 json_object_add_value_int(tmp_object, "max", max);
733 json_object_add_value_float(tmp_object, "mean", mean);
734 json_object_add_value_float(tmp_object, "stddev", dev);
735
736 if (ts->clat_percentiles) {
737 len = calc_clat_percentiles(ts->io_u_plat[ddir],
738 ts->clat_stat[ddir].samples,
739 ts->percentile_list, &ovals, &maxv,
740 &minv);
741 } else
742 len = 0;
743
744 percentile_object = json_create_object();
745 json_object_add_value_object(tmp_object, "percentile", percentile_object);
746 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
747 if (i >= len) {
748 json_object_add_value_int(percentile_object, "0.00", 0);
749 continue;
750 }
751 snprintf(buf, sizeof(buf) - 1, "%2.2f", ts->percentile_list[i].u.f);
752 json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]);
753 }
754
755 if (!calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) {
756 min = max = 0;
757 mean = dev = 0.0;
758 }
759 tmp_object = json_create_object();
760 json_object_add_value_object(dir_object, "lat", tmp_object);
761 json_object_add_value_int(tmp_object, "min", min);
762 json_object_add_value_int(tmp_object, "max", max);
763 json_object_add_value_float(tmp_object, "mean", mean);
764 json_object_add_value_float(tmp_object, "stddev", dev);
765 if (ovals)
766 free(ovals);
767
768 if (!calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
769 if (rs->agg[ddir]) {
770 p_of_agg = mean * 100 / (double) rs->agg[ddir];
771 if (p_of_agg > 100.0)
772 p_of_agg = 100.0;
773 }
774 } else {
775 min = max = 0;
776 p_of_agg = mean = dev = 0.0;
777 }
778 json_object_add_value_int(dir_object, "bw_min", min);
779 json_object_add_value_int(dir_object, "bw_max", max);
780 json_object_add_value_float(dir_object, "bw_agg", mean);
781 json_object_add_value_float(dir_object, "bw_mean", mean);
782 json_object_add_value_float(dir_object, "bw_dev", dev);
783}
784
Jens Axboe4d658652011-10-17 15:05:47 +0200785static void show_thread_status_terse_v2(struct thread_stat *ts,
786 struct group_run_stats *rs)
787{
788 double io_u_dist[FIO_IO_U_MAP_NR];
789 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
790 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
791 double usr_cpu, sys_cpu;
792 int i;
793
794 /* General Info */
795 log_info("2;%s;%d;%d", ts->name, ts->groupid, ts->error);
796 /* Log Read Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200797 show_ddir_status_terse(ts, rs, DDIR_READ);
Jens Axboe4d658652011-10-17 15:05:47 +0200798 /* Log Write Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200799 show_ddir_status_terse(ts, rs, DDIR_WRITE);
800 /* Log Trim Status */
801 show_ddir_status_terse(ts, rs, DDIR_TRIM);
Jens Axboe4d658652011-10-17 15:05:47 +0200802
803 /* CPU Usage */
804 if (ts->total_run_time) {
805 double runt = (double) ts->total_run_time;
806
807 usr_cpu = (double) ts->usr_time * 100 / runt;
808 sys_cpu = (double) ts->sys_time * 100 / runt;
809 } else {
810 usr_cpu = 0;
811 sys_cpu = 0;
812 }
813
814 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
815 ts->minf);
816
817 /* Calc % distribution of IO depths, usecond, msecond latency */
818 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
819 stat_calc_lat_u(ts, io_u_lat_u);
820 stat_calc_lat_m(ts, io_u_lat_m);
821
822 /* Only show fixed 7 I/O depth levels*/
823 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
824 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
825 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
826
827 /* Microsecond latency */
828 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
829 log_info(";%3.2f%%", io_u_lat_u[i]);
830 /* Millisecond latency */
831 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
832 log_info(";%3.2f%%", io_u_lat_m[i]);
833 /* Additional output if continue_on_error set - default off*/
834 if (ts->continue_on_error)
835 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
836 log_info("\n");
837
838 /* Additional output if description is set */
839 if (ts->description)
840 log_info(";%s", ts->description);
841
842 log_info("\n");
843}
844
Jens Axboe3449ab82012-09-14 23:35:08 +0200845static void show_thread_status_terse_v3_v4(struct thread_stat *ts,
846 struct group_run_stats *rs, int ver)
Jens Axboec6ae0a52006-06-12 11:04:44 +0200847{
Jens Axboe22708902007-03-06 17:05:32 +0100848 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200849 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
850 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200851 double usr_cpu, sys_cpu;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200852 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200853
David Nellans562c2d22010-09-23 08:38:17 +0200854 /* General Info */
Jens Axboef3afa572012-09-17 13:34:16 +0200855 log_info("%d;%s;%s;%d;%d", ver, fio_version_string,
Jens Axboe5e726d02011-10-14 08:08:10 +0200856 ts->name, ts->groupid, ts->error);
David Nellans562c2d22010-09-23 08:38:17 +0200857 /* Log Read Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200858 show_ddir_status_terse(ts, rs, DDIR_READ);
David Nellans562c2d22010-09-23 08:38:17 +0200859 /* Log Write Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200860 show_ddir_status_terse(ts, rs, DDIR_WRITE);
861 /* Log Trim Status */
Jens Axboe3449ab82012-09-14 23:35:08 +0200862 if (ver == 4)
863 show_ddir_status_terse(ts, rs, DDIR_TRIM);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200864
David Nellans562c2d22010-09-23 08:38:17 +0200865 /* CPU Usage */
Jens Axboe756867b2007-03-06 15:19:24 +0100866 if (ts->total_run_time) {
867 double runt = (double) ts->total_run_time;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200868
Jens Axboe756867b2007-03-06 15:19:24 +0100869 usr_cpu = (double) ts->usr_time * 100 / runt;
870 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200871 } else {
872 usr_cpu = 0;
873 sys_cpu = 0;
874 }
875
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100876 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
877 ts->minf);
Jens Axboe22708902007-03-06 17:05:32 +0100878
David Nellans562c2d22010-09-23 08:38:17 +0200879 /* Calc % distribution of IO depths, usecond, msecond latency */
Jens Axboe838bc702008-05-22 13:08:23 +0200880 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200881 stat_calc_lat_u(ts, io_u_lat_u);
882 stat_calc_lat_m(ts, io_u_lat_m);
Jens Axboe22708902007-03-06 17:05:32 +0100883
David Nellans562c2d22010-09-23 08:38:17 +0200884 /* Only show fixed 7 I/O depth levels*/
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100885 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
886 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
887 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
Jens Axboe22708902007-03-06 17:05:32 +0100888
David Nellans562c2d22010-09-23 08:38:17 +0200889 /* Microsecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200890 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
891 log_info(";%3.2f%%", io_u_lat_u[i]);
David Nellans562c2d22010-09-23 08:38:17 +0200892 /* Millisecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200893 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
894 log_info(";%3.2f%%", io_u_lat_m[i]);
Jens Axboef2f788d2011-10-13 14:03:52 +0200895
896 /* disk util stats, if any */
Shaohua Licc372b12012-09-17 09:12:18 +0200897 show_disk_util(1, NULL);
Jens Axboef2f788d2011-10-13 14:03:52 +0200898
David Nellans562c2d22010-09-23 08:38:17 +0200899 /* Additional output if continue_on_error set - default off*/
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200900 if (ts->continue_on_error)
901 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
Jens Axboe22708902007-03-06 17:05:32 +0100902
David Nellans562c2d22010-09-23 08:38:17 +0200903 /* Additional output if description is set */
Jens Axboe4b0f2252011-10-13 15:03:25 +0200904 if (strlen(ts->description))
Jens Axboe946e4272012-03-23 19:22:21 +0100905 log_info(";%s", ts->description);
906
907 log_info("\n");
Jens Axboe756867b2007-03-06 15:19:24 +0100908}
909
Shaohua Licc372b12012-09-17 09:12:18 +0200910static struct json_object *show_thread_status_json(struct thread_stat *ts,
911 struct group_run_stats *rs)
912{
913 struct json_object *root, *tmp;
914 double io_u_dist[FIO_IO_U_MAP_NR];
915 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
916 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
917 double usr_cpu, sys_cpu;
918 int i;
919
920 root = json_create_object();
921 json_object_add_value_string(root, "jobname", ts->name);
922 json_object_add_value_int(root, "groupid", ts->groupid);
923 json_object_add_value_int(root, "error", ts->error);
924
925 add_ddir_status_json(ts, rs, DDIR_READ, root);
926 add_ddir_status_json(ts, rs, DDIR_WRITE, root);
Jens Axboef3afa572012-09-17 13:34:16 +0200927 add_ddir_status_json(ts, rs, DDIR_TRIM, root);
Shaohua Licc372b12012-09-17 09:12:18 +0200928
929 /* CPU Usage */
930 if (ts->total_run_time) {
931 double runt = (double) ts->total_run_time;
932
933 usr_cpu = (double) ts->usr_time * 100 / runt;
934 sys_cpu = (double) ts->sys_time * 100 / runt;
935 } else {
936 usr_cpu = 0;
937 sys_cpu = 0;
938 }
939 json_object_add_value_float(root, "usr_cpu", usr_cpu);
940 json_object_add_value_float(root, "sys_cpu", sys_cpu);
941 json_object_add_value_int(root, "ctx", ts->ctx);
942 json_object_add_value_int(root, "majf", ts->majf);
943 json_object_add_value_int(root, "minf", ts->minf);
944
945
946 /* Calc % distribution of IO depths, usecond, msecond latency */
947 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
948 stat_calc_lat_u(ts, io_u_lat_u);
949 stat_calc_lat_m(ts, io_u_lat_m);
950
951 tmp = json_create_object();
952 json_object_add_value_object(root, "iodepth_level", tmp);
953 /* Only show fixed 7 I/O depth levels*/
954 for (i = 0; i < 7; i++) {
955 char name[20];
956 if (i < 6)
957 snprintf(name, 19, "%d", 1 << i);
958 else
959 snprintf(name, 19, ">=%d", 1 << i);
960 json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]);
961 }
962
963 tmp = json_create_object();
964 json_object_add_value_object(root, "latency_us", tmp);
965 /* Microsecond latency */
966 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
967 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
968 "250", "500", "750", "1000", };
969 json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]);
970 }
971 /* Millisecond latency */
972 tmp = json_create_object();
973 json_object_add_value_object(root, "latency_ms", tmp);
974 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) {
975 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
976 "250", "500", "750", "1000", "2000",
977 ">=2000", };
978 json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]);
979 }
980
981 /* Additional output if continue_on_error set - default off*/
982 if (ts->continue_on_error) {
983 json_object_add_value_int(root, "total_err", ts->total_err_count);
984 json_object_add_value_int(root, "total_err", ts->first_error);
985 }
986
987 /* Additional output if description is set */
988 if (strlen(ts->description))
989 json_object_add_value_string(root, "desc", ts->description);
990
991 return root;
992}
993
Jens Axboe4d658652011-10-17 15:05:47 +0200994static void show_thread_status_terse(struct thread_stat *ts,
995 struct group_run_stats *rs)
996{
997 if (terse_version == 2)
998 show_thread_status_terse_v2(ts, rs);
Jens Axboe3449ab82012-09-14 23:35:08 +0200999 else if (terse_version == 3 || terse_version == 4)
1000 show_thread_status_terse_v3_v4(ts, rs, terse_version);
Jens Axboe4d658652011-10-17 15:05:47 +02001001 else
1002 log_err("fio: bad terse version!? %d\n", terse_version);
1003}
1004
Jens Axboe197574e2007-03-08 15:35:11 +01001005static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
Jens Axboe756867b2007-03-06 15:19:24 +01001006{
1007 double mean, S;
1008
Zheng Liue09231c2011-09-16 08:20:12 +02001009 if (src->samples == 0)
1010 return;
1011
Jens Axboe756867b2007-03-06 15:19:24 +01001012 dst->min_val = min(dst->min_val, src->min_val);
1013 dst->max_val = max(dst->max_val, src->max_val);
Jens Axboe756867b2007-03-06 15:19:24 +01001014
1015 /*
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001016 * Compute new mean and S after the merge
1017 * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
1018 * #Parallel_algorithm>
Jens Axboe756867b2007-03-06 15:19:24 +01001019 */
1020 if (nr == 1) {
Jens Axboe802ad4a2011-10-05 09:51:58 +02001021 mean = src->mean.u.f;
1022 S = src->S.u.f;
Jens Axboe756867b2007-03-06 15:19:24 +01001023 } else {
Jens Axboe802ad4a2011-10-05 09:51:58 +02001024 double delta = src->mean.u.f - dst->mean.u.f;
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001025
Jens Axboe802ad4a2011-10-05 09:51:58 +02001026 mean = ((src->mean.u.f * src->samples) +
1027 (dst->mean.u.f * dst->samples)) /
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001028 (dst->samples + src->samples);
1029
Jens Axboe802ad4a2011-10-05 09:51:58 +02001030 S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) *
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001031 (dst->samples * src->samples) /
1032 (dst->samples + src->samples);
Jens Axboe756867b2007-03-06 15:19:24 +01001033 }
1034
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001035 dst->samples += src->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +02001036 dst->mean.u.f = mean;
1037 dst->S.u.f = S;
Jens Axboe756867b2007-03-06 15:19:24 +01001038}
1039
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001040void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src)
1041{
1042 int i;
1043
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001044 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001045 if (dst->max_run[i] < src->max_run[i])
1046 dst->max_run[i] = src->max_run[i];
1047 if (dst->min_run[i] && dst->min_run[i] > src->min_run[i])
1048 dst->min_run[i] = src->min_run[i];
1049 if (dst->max_bw[i] < src->max_bw[i])
1050 dst->max_bw[i] = src->max_bw[i];
1051 if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i])
1052 dst->min_bw[i] = src->min_bw[i];
1053
1054 dst->io_kb[i] += src->io_kb[i];
1055 dst->agg[i] += src->agg[i];
1056 }
1057
1058}
1059
Jens Axboe5b9babb2011-10-10 12:14:30 +02001060void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr)
1061{
1062 int l, k;
1063
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001064 for (l = 0; l < DDIR_RWDIR_CNT; l++) {
Jens Axboe5b9babb2011-10-10 12:14:30 +02001065 sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr);
1066 sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr);
1067 sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr);
1068 sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr);
1069
1070 dst->io_bytes[l] += src->io_bytes[l];
1071
1072 if (dst->runtime[l] < src->runtime[l])
1073 dst->runtime[l] = src->runtime[l];
1074 }
1075
1076 dst->usr_time += src->usr_time;
1077 dst->sys_time += src->sys_time;
1078 dst->ctx += src->ctx;
1079 dst->majf += src->majf;
1080 dst->minf += src->minf;
1081
1082 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1083 dst->io_u_map[k] += src->io_u_map[k];
1084 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1085 dst->io_u_submit[k] += src->io_u_submit[k];
1086 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1087 dst->io_u_complete[k] += src->io_u_complete[k];
1088 for (k = 0; k < FIO_IO_U_LAT_U_NR; k++)
1089 dst->io_u_lat_u[k] += src->io_u_lat_u[k];
1090 for (k = 0; k < FIO_IO_U_LAT_M_NR; k++)
1091 dst->io_u_lat_m[k] += src->io_u_lat_m[k];
1092
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001093 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
Jens Axboe5b9babb2011-10-10 12:14:30 +02001094 dst->total_io_u[k] += src->total_io_u[k];
1095 dst->short_io_u[k] += src->short_io_u[k];
1096 }
1097
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001098 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
Jens Axboe5b9babb2011-10-10 12:14:30 +02001099 int m;
1100 for (m = 0; m < FIO_IO_U_PLAT_NR; m++)
1101 dst->io_u_plat[k][m] += src->io_u_plat[k][m];
1102 }
1103
1104 dst->total_run_time += src->total_run_time;
1105 dst->total_submit += src->total_submit;
1106 dst->total_complete += src->total_complete;
1107}
1108
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001109void init_group_run_stat(struct group_run_stats *gs)
1110{
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001111 int i;
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001112 memset(gs, 0, sizeof(*gs));
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001113
1114 for (i = 0; i < DDIR_RWDIR_CNT; i++)
1115 gs->min_bw[i] = gs->min_run[i] = ~0UL;
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001116}
1117
1118void init_thread_stat(struct thread_stat *ts)
1119{
1120 int j;
1121
1122 memset(ts, 0, sizeof(*ts));
1123
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001124 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001125 ts->lat_stat[j].min_val = -1UL;
1126 ts->clat_stat[j].min_val = -1UL;
1127 ts->slat_stat[j].min_val = -1UL;
1128 ts->bw_stat[j].min_val = -1UL;
1129 }
1130 ts->groupid = -1;
1131}
1132
Jens Axboe3c39a372006-06-06 20:56:12 +02001133void show_run_stats(void)
1134{
1135 struct group_run_stats *runstats, *rs;
1136 struct thread_data *td;
Jens Axboe756867b2007-03-06 15:19:24 +01001137 struct thread_stat *threadstats, *ts;
Jens Axboe5b9babb2011-10-10 12:14:30 +02001138 int i, j, nr_ts, last_ts, idx;
Jens Axboe90fef2d2009-07-17 22:33:32 +02001139 int kb_base_warned = 0;
Shaohua Licc372b12012-09-17 09:12:18 +02001140 struct json_object *root = NULL;
1141 struct json_array *array = NULL;
Jens Axboe3c39a372006-06-06 20:56:12 +02001142
1143 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
1144
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001145 for (i = 0; i < groupid + 1; i++)
1146 init_group_run_stat(&runstats[i]);
Jens Axboe3c39a372006-06-06 20:56:12 +02001147
Jens Axboe756867b2007-03-06 15:19:24 +01001148 /*
1149 * find out how many threads stats we need. if group reporting isn't
1150 * enabled, it's one-per-td.
1151 */
1152 nr_ts = 0;
1153 last_ts = -1;
Jens Axboe34572e22006-10-20 09:33:18 +02001154 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001155 if (!td->o.group_reporting) {
Jens Axboe756867b2007-03-06 15:19:24 +01001156 nr_ts++;
1157 continue;
1158 }
1159 if (last_ts == td->groupid)
1160 continue;
1161
1162 last_ts = td->groupid;
1163 nr_ts++;
1164 }
1165
1166 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
1167
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001168 for (i = 0; i < nr_ts; i++)
1169 init_thread_stat(&threadstats[i]);
Jens Axboe756867b2007-03-06 15:19:24 +01001170
1171 j = 0;
1172 last_ts = -1;
Jens Axboe197574e2007-03-08 15:35:11 +01001173 idx = 0;
Jens Axboe756867b2007-03-06 15:19:24 +01001174 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001175 if (idx && (!td->o.group_reporting ||
1176 (td->o.group_reporting && last_ts != td->groupid))) {
Jens Axboe7abd0e32007-03-12 15:24:43 +01001177 idx = 0;
1178 j++;
1179 }
1180
1181 last_ts = td->groupid;
1182
Jens Axboe756867b2007-03-06 15:19:24 +01001183 ts = &threadstats[j];
1184
Yu-ju Hong83349192011-08-13 00:53:44 +02001185 ts->clat_percentiles = td->o.clat_percentiles;
1186 if (td->o.overwrite_plist)
Jens Axboe802ad4a2011-10-05 09:51:58 +02001187 memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +02001188 else
Jens Axboe802ad4a2011-10-05 09:51:58 +02001189 memcpy(ts->percentile_list, def_percentile_list, sizeof(def_percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +02001190
Jens Axboe197574e2007-03-08 15:35:11 +01001191 idx++;
Jens Axboe6586ee82007-03-06 19:46:09 +01001192 ts->members++;
Jens Axboe756867b2007-03-06 15:19:24 +01001193
Jens Axboe7abd0e32007-03-12 15:24:43 +01001194 if (ts->groupid == -1) {
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001195 /*
1196 * These are per-group shared already
1197 */
Jens Axboef6bb5b82011-10-03 12:21:25 +02001198 strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE);
Jens Axboea64e88d2011-10-03 14:20:01 +02001199 if (td->o.description)
1200 strncpy(ts->description, td->o.description,
1201 FIO_JOBNAME_SIZE);
1202 else
1203 memset(ts->description, 0, FIO_JOBNAME_SIZE);
1204
Jens Axboe756867b2007-03-06 15:19:24 +01001205 ts->groupid = td->groupid;
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001206
1207 /*
1208 * first pid in group, not very useful...
1209 */
Jens Axboe756867b2007-03-06 15:19:24 +01001210 ts->pid = td->pid;
Jens Axboe90fef2d2009-07-17 22:33:32 +02001211
1212 ts->kb_base = td->o.kb_base;
1213 } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) {
1214 log_info("fio: kb_base differs for jobs in group, using"
1215 " %u as the base\n", ts->kb_base);
1216 kb_base_warned = 1;
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001217 }
1218
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001219 ts->continue_on_error = td->o.continue_on_error;
1220 ts->total_err_count += td->total_err_count;
1221 ts->first_error = td->first_error;
1222 if (!ts->error) {
1223 if (!td->error && td->o.continue_on_error &&
1224 td->first_error) {
1225 ts->error = td->first_error;
Jens Axboef6bb5b82011-10-03 12:21:25 +02001226 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001227 } else if (td->error) {
1228 ts->error = td->error;
Jens Axboef6bb5b82011-10-03 12:21:25 +02001229 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001230 }
Jens Axboe756867b2007-03-06 15:19:24 +01001231 }
1232
Jens Axboe5b9babb2011-10-10 12:14:30 +02001233 sum_thread_stats(ts, &td->ts, idx);
Jens Axboe756867b2007-03-06 15:19:24 +01001234 }
1235
1236 for (i = 0; i < nr_ts; i++) {
Jens Axboe94370ac2007-03-08 15:28:10 +01001237 unsigned long long bw;
Jens Axboe3c39a372006-06-06 20:56:12 +02001238
Jens Axboe756867b2007-03-06 15:19:24 +01001239 ts = &threadstats[i];
1240 rs = &runstats[ts->groupid];
Jens Axboe90fef2d2009-07-17 22:33:32 +02001241 rs->kb_base = ts->kb_base;
Jens Axboe3c39a372006-06-06 20:56:12 +02001242
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001243 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
Jens Axboe94370ac2007-03-08 15:28:10 +01001244 if (!ts->runtime[j])
1245 continue;
1246 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
1247 rs->min_run[j] = ts->runtime[j];
1248 if (ts->runtime[j] > rs->max_run[j])
1249 rs->max_run[j] = ts->runtime[j];
Jens Axboe3c39a372006-06-06 20:56:12 +02001250
Jens Axboe94370ac2007-03-08 15:28:10 +01001251 bw = 0;
Jens Axboe8879fd12009-04-20 10:06:02 +02001252 if (ts->runtime[j]) {
Jens Axboec857cfe2012-04-05 08:42:11 -06001253 unsigned long runt = ts->runtime[j];
1254 unsigned long long kb;
Jens Axboe8879fd12009-04-20 10:06:02 +02001255
Jens Axboec857cfe2012-04-05 08:42:11 -06001256 kb = ts->io_bytes[j] / rs->kb_base;
1257 bw = kb * 1000 / runt;
Jens Axboe8879fd12009-04-20 10:06:02 +02001258 }
Jens Axboe94370ac2007-03-08 15:28:10 +01001259 if (bw < rs->min_bw[j])
1260 rs->min_bw[j] = bw;
1261 if (bw > rs->max_bw[j])
1262 rs->max_bw[j] = bw;
Jens Axboe3c39a372006-06-06 20:56:12 +02001263
Jens Axboe90fef2d2009-07-17 22:33:32 +02001264 rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base;
Jens Axboe94370ac2007-03-08 15:28:10 +01001265 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001266 }
1267
1268 for (i = 0; i < groupid + 1; i++) {
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001269 int ddir;
1270
Jens Axboe3c39a372006-06-06 20:56:12 +02001271 rs = &runstats[i];
1272
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001273 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
1274 if (rs->max_run[ddir])
1275 rs->agg[ddir] = (rs->io_kb[ddir] * 1000) /
1276 rs->max_run[ddir];
1277 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001278 }
1279
1280 /*
1281 * don't overwrite last signal output
1282 */
Jens Axboef3afa572012-09-17 13:34:16 +02001283 if (output_format == FIO_OUTPUT_NORMAL)
Jens Axboe4ceb30d2010-02-24 09:19:14 +01001284 log_info("\n");
Jens Axboef3afa572012-09-17 13:34:16 +02001285 else if (output_format == FIO_OUTPUT_JSON) {
Shaohua Licc372b12012-09-17 09:12:18 +02001286 root = json_create_object();
1287 json_object_add_value_string(root, "fio version", fio_version_string);
1288 array = json_create_array();
1289 json_object_add_value_array(root, "jobs", array);
1290 }
1291
Jens Axboe756867b2007-03-06 15:19:24 +01001292 for (i = 0; i < nr_ts; i++) {
1293 ts = &threadstats[i];
1294 rs = &runstats[ts->groupid];
Jens Axboe3c39a372006-06-06 20:56:12 +02001295
Jens Axboea64e88d2011-10-03 14:20:01 +02001296 if (is_backend)
1297 fio_server_send_ts(ts, rs);
Jens Axboef3afa572012-09-17 13:34:16 +02001298 else if (output_format == FIO_OUTPUT_TERSE)
1299 show_thread_status_terse(ts, rs);
1300 else if (output_format == FIO_OUTPUT_JSON) {
1301 struct json_object *tmp = show_thread_status_json(ts, rs);
1302 json_array_add_value_object(array, tmp);
Shaohua Licc372b12012-09-17 09:12:18 +02001303 } else
Jens Axboe756867b2007-03-06 15:19:24 +01001304 show_thread_status(ts, rs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001305 }
Jens Axboef3afa572012-09-17 13:34:16 +02001306 if (output_format == FIO_OUTPUT_JSON) {
Shaohua Licc372b12012-09-17 09:12:18 +02001307 /* disk util stats, if any */
1308 show_disk_util(1, root);
1309
1310 json_print_object(root);
1311 log_info("\n");
1312 json_free_object(root);
1313 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001314
Jens Axboe72c27ff2011-10-16 11:50:31 +02001315 for (i = 0; i < groupid + 1; i++) {
1316 rs = &runstats[i];
Jens Axboea64e88d2011-10-03 14:20:01 +02001317
Jens Axboe72c27ff2011-10-16 11:50:31 +02001318 rs->groupid = i;
Jens Axboed09a64a2011-10-13 11:38:56 +02001319 if (is_backend)
Jens Axboe72c27ff2011-10-16 11:50:31 +02001320 fio_server_send_gs(rs);
Jens Axboef3afa572012-09-17 13:34:16 +02001321 else if (output_format == FIO_OUTPUT_NORMAL)
Jens Axboe72c27ff2011-10-16 11:50:31 +02001322 show_group_stats(rs);
Jens Axboec6ae0a52006-06-12 11:04:44 +02001323 }
Jens Axboeeecf2722006-10-20 14:00:36 +02001324
Jens Axboe72c27ff2011-10-16 11:50:31 +02001325 if (is_backend)
1326 fio_server_send_du();
Jens Axboef3afa572012-09-17 13:34:16 +02001327 else if (output_format == FIO_OUTPUT_NORMAL)
Shaohua Licc372b12012-09-17 09:12:18 +02001328 show_disk_util(0, NULL);
Jens Axboe72c27ff2011-10-16 11:50:31 +02001329
Jens Axboeeecf2722006-10-20 14:00:36 +02001330 free(runstats);
Jens Axboe756867b2007-03-06 15:19:24 +01001331 free(threadstats);
Jens Axboe3c39a372006-06-06 20:56:12 +02001332}
1333
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001334static void *__show_running_run_stats(void *arg)
1335{
1336 struct thread_data *td;
1337 unsigned long long *rt;
1338 struct timeval tv;
1339 int i;
1340
1341 rt = malloc(thread_number * sizeof(unsigned long long));
1342 fio_gettime(&tv, NULL);
1343
1344 for_each_td(td, i) {
1345 rt[i] = mtime_since(&td->start, &tv);
1346 if (td_read(td) && td->io_bytes[DDIR_READ])
1347 td->ts.runtime[DDIR_READ] += rt[i];
1348 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1349 td->ts.runtime[DDIR_WRITE] += rt[i];
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001350 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1351 td->ts.runtime[DDIR_TRIM] += rt[i];
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001352
1353 update_rusage_stat(td);
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001354 td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ];
1355 td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
1356 td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001357 td->ts.total_run_time = mtime_since(&td->epoch, &tv);
1358 }
1359
1360 show_run_stats();
1361
1362 for_each_td(td, i) {
1363 if (td_read(td) && td->io_bytes[DDIR_READ])
1364 td->ts.runtime[DDIR_READ] -= rt[i];
1365 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1366 td->ts.runtime[DDIR_WRITE] -= rt[i];
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001367 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1368 td->ts.runtime[DDIR_TRIM] -= rt[i];
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001369 }
1370
1371 free(rt);
1372 return NULL;
1373}
1374
1375/*
1376 * Called from signal handler. It _should_ be safe to just run this inline
1377 * in the sig handler, but we should be disturbing the system less by just
1378 * creating a thread to do it.
1379 */
1380void show_running_run_stats(void)
1381{
1382 pthread_t thread;
1383
1384 pthread_create(&thread, NULL, __show_running_run_stats, NULL);
1385 pthread_detach(thread);
1386}
1387
Jens Axboe68704082007-01-10 19:56:37 +01001388static inline void add_stat_sample(struct io_stat *is, unsigned long data)
Jens Axboe3c39a372006-06-06 20:56:12 +02001389{
Jens Axboe68704082007-01-10 19:56:37 +01001390 double val = data;
Jens Axboe6660cc62007-03-06 15:48:38 +01001391 double delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001392
Jens Axboe68704082007-01-10 19:56:37 +01001393 if (data > is->max_val)
1394 is->max_val = data;
1395 if (data < is->min_val)
1396 is->min_val = data;
1397
Jens Axboe802ad4a2011-10-05 09:51:58 +02001398 delta = val - is->mean.u.f;
Jens Axboeef11d732007-03-29 15:36:29 +02001399 if (delta) {
Jens Axboe802ad4a2011-10-05 09:51:58 +02001400 is->mean.u.f += delta / (is->samples + 1.0);
1401 is->S.u.f += delta * (val - is->mean.u.f);
Jens Axboeef11d732007-03-29 15:36:29 +02001402 }
Jens Axboe68704082007-01-10 19:56:37 +01001403
Jens Axboe3c39a372006-06-06 20:56:12 +02001404 is->samples++;
1405}
1406
Jens Axboebb3884d2007-01-17 17:23:11 +11001407static void __add_log_sample(struct io_log *iolog, unsigned long val,
Jens Axboe306ddc92009-05-18 13:08:12 +02001408 enum fio_ddir ddir, unsigned int bs,
Jens Axboe2b13e712011-01-19 14:04:16 -07001409 unsigned long t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001410{
Jens Axboe306ddc92009-05-18 13:08:12 +02001411 const int nr_samples = iolog->nr_samples;
1412
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001413 if (!iolog->nr_samples)
1414 iolog->avg_last = t;
1415
Jens Axboe3c39a372006-06-06 20:56:12 +02001416 if (iolog->nr_samples == iolog->max_samples) {
1417 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
1418
1419 iolog->log = realloc(iolog->log, new_size);
1420 iolog->max_samples <<= 1;
1421 }
1422
Jens Axboe306ddc92009-05-18 13:08:12 +02001423 iolog->log[nr_samples].val = val;
Jens Axboe2b13e712011-01-19 14:04:16 -07001424 iolog->log[nr_samples].time = t;
Jens Axboe306ddc92009-05-18 13:08:12 +02001425 iolog->log[nr_samples].ddir = ddir;
1426 iolog->log[nr_samples].bs = bs;
Jens Axboe3c39a372006-06-06 20:56:12 +02001427 iolog->nr_samples++;
1428}
1429
Jens Axboe7fb28d32011-12-01 15:17:24 +01001430static inline void reset_io_stat(struct io_stat *ios)
1431{
1432 ios->max_val = ios->min_val = ios->samples = 0;
1433 ios->mean.u.f = ios->S.u.f = 0;
1434}
1435
Jens Axboebb3884d2007-01-17 17:23:11 +11001436static void add_log_sample(struct thread_data *td, struct io_log *iolog,
Jens Axboe306ddc92009-05-18 13:08:12 +02001437 unsigned long val, enum fio_ddir ddir,
1438 unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001439{
Jens Axboe7fb28d32011-12-01 15:17:24 +01001440 unsigned long elapsed, this_window;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001441
Jens Axboeff58fce2010-08-25 12:02:08 +02001442 if (!ddir_rw(ddir))
1443 return;
1444
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001445 elapsed = mtime_since_now(&td->epoch);
1446
1447 /*
1448 * If no time averaging, just add the log sample.
1449 */
1450 if (!iolog->avg_msec) {
1451 __add_log_sample(iolog, val, ddir, bs, elapsed);
1452 return;
1453 }
1454
1455 /*
1456 * Add the sample. If the time period has passed, then
1457 * add that entry to the log and clear.
1458 */
1459 add_stat_sample(&iolog->avg_window[ddir], val);
1460
Jens Axboe7fb28d32011-12-01 15:17:24 +01001461 /*
1462 * If period hasn't passed, adding the above sample is all we
1463 * need to do.
1464 */
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001465 this_window = elapsed - iolog->avg_last;
1466 if (this_window < iolog->avg_msec)
1467 return;
1468
Jens Axboe7fb28d32011-12-01 15:17:24 +01001469 /*
1470 * Note an entry in the log. Use the mean from the logged samples,
1471 * making sure to properly round up. Only write a log entry if we
1472 * had actual samples done.
1473 */
1474 if (iolog->avg_window[DDIR_READ].samples) {
1475 unsigned long mr;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001476
Jens Axboe7fb28d32011-12-01 15:17:24 +01001477 mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001478 __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed);
Jens Axboe7fb28d32011-12-01 15:17:24 +01001479 }
1480 if (iolog->avg_window[DDIR_WRITE].samples) {
1481 unsigned long mw;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001482
Jens Axboe7fb28d32011-12-01 15:17:24 +01001483 mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50;
1484 __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed);
1485 }
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001486 if (iolog->avg_window[DDIR_TRIM].samples) {
1487 unsigned long mw;
1488
1489 mw = iolog->avg_window[DDIR_TRIM].mean.u.f + 0.50;
1490 __add_log_sample(iolog, mw, DDIR_TRIM, 0, elapsed);
1491 }
1492
Jens Axboe7fb28d32011-12-01 15:17:24 +01001493
1494 reset_io_stat(&iolog->avg_window[DDIR_READ]);
1495 reset_io_stat(&iolog->avg_window[DDIR_WRITE]);
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001496 reset_io_stat(&iolog->avg_window[DDIR_TRIM]);
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001497 iolog->avg_last = elapsed;
Jens Axboebb3884d2007-01-17 17:23:11 +11001498}
1499
Jens Axboe306ddc92009-05-18 13:08:12 +02001500void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001501{
Jens Axboeff58fce2010-08-25 12:02:08 +02001502 struct io_log *iolog;
Jens Axboebb3884d2007-01-17 17:23:11 +11001503
Jens Axboeff58fce2010-08-25 12:02:08 +02001504 if (!ddir_rw(ddir))
1505 return;
1506
1507 iolog = agg_io_log[ddir];
Jens Axboe306ddc92009-05-18 13:08:12 +02001508 __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis());
Jens Axboebb3884d2007-01-17 17:23:11 +11001509}
1510
Yu-ju Hong83349192011-08-13 00:53:44 +02001511static void add_clat_percentile_sample(struct thread_stat *ts,
1512 unsigned long usec, enum fio_ddir ddir)
1513{
1514 unsigned int idx = plat_val_to_idx(usec);
1515 assert(idx < FIO_IO_U_PLAT_NR);
1516
1517 ts->io_u_plat[ddir][idx]++;
1518}
1519
Jens Axboe1e97cce2006-12-05 11:44:16 +01001520void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001521 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001522{
Jens Axboe756867b2007-03-06 15:19:24 +01001523 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001524
Jens Axboeff58fce2010-08-25 12:02:08 +02001525 if (!ddir_rw(ddir))
1526 return;
1527
Jens Axboed85f5112007-06-18 09:41:23 +02001528 add_stat_sample(&ts->clat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001529
Jens Axboe7b9f7332011-10-03 10:06:44 +02001530 if (td->clat_log)
1531 add_log_sample(td, td->clat_log, usec, ddir, bs);
Yu-ju Hong83349192011-08-13 00:53:44 +02001532
1533 if (ts->clat_percentiles)
1534 add_clat_percentile_sample(ts, usec, ddir);
Jens Axboe3c39a372006-06-06 20:56:12 +02001535}
1536
Jens Axboe1e97cce2006-12-05 11:44:16 +01001537void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001538 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001539{
Jens Axboe756867b2007-03-06 15:19:24 +01001540 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001541
Jens Axboeff58fce2010-08-25 12:02:08 +02001542 if (!ddir_rw(ddir))
1543 return;
1544
Jens Axboed85f5112007-06-18 09:41:23 +02001545 add_stat_sample(&ts->slat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001546
Jens Axboe7b9f7332011-10-03 10:06:44 +02001547 if (td->slat_log)
1548 add_log_sample(td, td->slat_log, usec, ddir, bs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001549}
1550
Jens Axboe02af0982010-06-24 09:59:34 +02001551void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
1552 unsigned long usec, unsigned int bs)
1553{
1554 struct thread_stat *ts = &td->ts;
1555
Jens Axboeff58fce2010-08-25 12:02:08 +02001556 if (!ddir_rw(ddir))
1557 return;
1558
Jens Axboe02af0982010-06-24 09:59:34 +02001559 add_stat_sample(&ts->lat_stat[ddir], usec);
1560
Jens Axboe7b9f7332011-10-03 10:06:44 +02001561 if (td->lat_log)
1562 add_log_sample(td, td->lat_log, usec, ddir, bs);
Jens Axboe02af0982010-06-24 09:59:34 +02001563}
1564
Jens Axboe306ddc92009-05-18 13:08:12 +02001565void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
Jens Axboe1e97cce2006-12-05 11:44:16 +01001566 struct timeval *t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001567{
Jens Axboe756867b2007-03-06 15:19:24 +01001568 struct thread_stat *ts = &td->ts;
Jens Axboeff58fce2010-08-25 12:02:08 +02001569 unsigned long spent, rate;
Jens Axboe3c39a372006-06-06 20:56:12 +02001570
Jens Axboeff58fce2010-08-25 12:02:08 +02001571 if (!ddir_rw(ddir))
1572 return;
1573
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001574 spent = mtime_since(&td->bw_sample_time, t);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001575 if (spent < td->o.bw_avg_time)
Jens Axboe3c39a372006-06-06 20:56:12 +02001576 return;
Jens Axboe9602d8d2012-02-20 20:19:28 +01001577
1578 /*
Josh Carter5daa4eb2012-02-20 10:12:22 +01001579 * Compute both read and write rates for the interval.
1580 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001581 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
Josh Carter5daa4eb2012-02-20 10:12:22 +01001582 uint64_t delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001583
Josh Carter5daa4eb2012-02-20 10:12:22 +01001584 delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir];
1585 if (!delta)
1586 continue; /* No entries for interval */
Jens Axboe3c39a372006-06-06 20:56:12 +02001587
Josh Carter5daa4eb2012-02-20 10:12:22 +01001588 rate = delta * 1000 / spent / 1024;
1589 add_stat_sample(&ts->bw_stat[ddir], rate);
1590
1591 if (td->bw_log)
1592 add_log_sample(td, td->bw_log, rate, ddir, bs);
1593
1594 td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
1595 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001596
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001597 fio_gettime(&td->bw_sample_time, NULL);
Jens Axboe3c39a372006-06-06 20:56:12 +02001598}
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001599
1600void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,
1601 struct timeval *t)
1602{
1603 struct thread_stat *ts = &td->ts;
1604 unsigned long spent, iops;
1605
1606 if (!ddir_rw(ddir))
1607 return;
1608
1609 spent = mtime_since(&td->iops_sample_time, t);
1610 if (spent < td->o.iops_avg_time)
1611 return;
1612
Jens Axboe9602d8d2012-02-20 20:19:28 +01001613 /*
1614 * Compute both read and write rates for the interval.
1615 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001616 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
Jens Axboe9602d8d2012-02-20 20:19:28 +01001617 uint64_t delta;
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001618
Jens Axboe9602d8d2012-02-20 20:19:28 +01001619 delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir];
1620 if (!delta)
1621 continue; /* No entries for interval */
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001622
Jens Axboe9602d8d2012-02-20 20:19:28 +01001623 iops = (delta * 1000) / spent;
1624 add_stat_sample(&ts->iops_stat[ddir], iops);
1625
1626 if (td->iops_log)
1627 add_log_sample(td, td->iops_log, iops, ddir, 0);
1628
Jens Axboe421f4a82012-02-28 08:20:26 +01001629 td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
Jens Axboe9602d8d2012-02-20 20:19:28 +01001630 }
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001631
1632 fio_gettime(&td->iops_sample_time, NULL);
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001633}