blob: 2e7824295600385430d724db60c4dfd574870907 [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
Yufei Ren40059392012-10-22 21:29:37 -040019#ifdef RUSAGE_THREAD
Yufei Renf5fd0b12012-10-19 23:11:50 -040020 getrusage(RUSAGE_THREAD, &td->ru_end);
21#else
Jens Axboec8aaba12011-10-03 12:14:19 +020022 getrusage(RUSAGE_SELF, &td->ru_end);
Yufei Renf5fd0b12012-10-19 23:11:50 -040023#endif
Jens Axboe079ad092007-02-20 13:58:20 +010024
Jens Axboec8aaba12011-10-03 12:14:19 +020025 ts->usr_time += mtime_since(&td->ru_start.ru_utime,
26 &td->ru_end.ru_utime);
27 ts->sys_time += mtime_since(&td->ru_start.ru_stime,
28 &td->ru_end.ru_stime);
29 ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw
30 - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw);
31 ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt;
32 ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010033
Jens Axboec8aaba12011-10-03 12:14:19 +020034 memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end));
Jens Axboe3c39a372006-06-06 20:56:12 +020035}
36
Yu-ju Hong83349192011-08-13 00:53:44 +020037/*
38 * Given a latency, return the index of the corresponding bucket in
39 * the structure tracking percentiles.
40 *
41 * (1) find the group (and error bits) that the value (latency)
42 * belongs to by looking at its MSB. (2) find the bucket number in the
43 * group by looking at the index bits.
44 *
45 */
46static unsigned int plat_val_to_idx(unsigned int val)
47{
48 unsigned int msb, error_bits, base, offset, idx;
49
50 /* Find MSB starting from bit 0 */
51 if (val == 0)
52 msb = 0;
53 else
54 msb = (sizeof(val)*8) - __builtin_clz(val) - 1;
55
Jens Axboe716050f2011-08-16 08:43:45 +020056 /*
57 * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
58 * all bits of the sample as index
59 */
Yu-ju Hong83349192011-08-13 00:53:44 +020060 if (msb <= FIO_IO_U_PLAT_BITS)
61 return val;
62
63 /* Compute the number of error bits to discard*/
64 error_bits = msb - FIO_IO_U_PLAT_BITS;
65
66 /* Compute the number of buckets before the group */
67 base = (error_bits + 1) << FIO_IO_U_PLAT_BITS;
68
Jens Axboe716050f2011-08-16 08:43:45 +020069 /*
70 * Discard the error bits and apply the mask to find the
Jens Axboe3c3ed072012-03-27 09:12:39 +020071 * index for the buckets in the group
Jens Axboe716050f2011-08-16 08:43:45 +020072 */
Yu-ju Hong83349192011-08-13 00:53:44 +020073 offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits);
74
75 /* Make sure the index does not exceed (array size - 1) */
Jens Axboe3c3ed072012-03-27 09:12:39 +020076 idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1) ?
Yu-ju Hong83349192011-08-13 00:53:44 +020077 (base + offset) : (FIO_IO_U_PLAT_NR - 1);
78
79 return idx;
80}
81
82/*
83 * Convert the given index of the bucket array to the value
84 * represented by the bucket
85 */
86static unsigned int plat_idx_to_val(unsigned int idx)
87{
88 unsigned int error_bits, k, base;
89
90 assert(idx < FIO_IO_U_PLAT_NR);
91
92 /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
93 * all bits of the sample as index */
Jens Axboe3c3ed072012-03-27 09:12:39 +020094 if (idx < (FIO_IO_U_PLAT_VAL << 1))
Yu-ju Hong83349192011-08-13 00:53:44 +020095 return idx;
96
97 /* Find the group and compute the minimum value of that group */
Jens Axboe3c3ed072012-03-27 09:12:39 +020098 error_bits = (idx >> FIO_IO_U_PLAT_BITS) - 1;
Yu-ju Hong83349192011-08-13 00:53:44 +020099 base = 1 << (error_bits + FIO_IO_U_PLAT_BITS);
100
101 /* Find its bucket number of the group */
102 k = idx % FIO_IO_U_PLAT_VAL;
103
104 /* Return the mean of the range of the bucket */
105 return base + ((k + 0.5) * (1 << error_bits));
106}
107
108static int double_cmp(const void *a, const void *b)
109{
Jens Axboe802ad4a2011-10-05 09:51:58 +0200110 const fio_fp64_t fa = *(const fio_fp64_t *) a;
111 const fio_fp64_t fb = *(const fio_fp64_t *) b;
Yu-ju Hong83349192011-08-13 00:53:44 +0200112 int cmp = 0;
113
Jens Axboe802ad4a2011-10-05 09:51:58 +0200114 if (fa.u.f > fb.u.f)
Yu-ju Hong83349192011-08-13 00:53:44 +0200115 cmp = 1;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200116 else if (fa.u.f < fb.u.f)
Yu-ju Hong83349192011-08-13 00:53:44 +0200117 cmp = -1;
118
119 return cmp;
120}
121
Jens Axboea2697902012-03-05 16:43:49 +0100122unsigned int calc_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
123 fio_fp64_t *plist, unsigned int **output,
124 unsigned int *maxv, unsigned int *minv)
Yu-ju Hong83349192011-08-13 00:53:44 +0200125{
126 unsigned long sum = 0;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200127 unsigned int len, i, j = 0;
128 unsigned int oval_len = 0;
129 unsigned int *ovals = NULL;
130 int is_last;
131
132 *minv = -1U;
133 *maxv = 0;
Yu-ju Hong83349192011-08-13 00:53:44 +0200134
Jens Axboe802ad4a2011-10-05 09:51:58 +0200135 len = 0;
136 while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0)
137 len++;
Jens Axboe716050f2011-08-16 08:43:45 +0200138
Jens Axboe351de8d2011-10-12 21:03:45 +0200139 if (!len)
Jens Axboe1db92cb2011-10-13 13:43:36 +0200140 return 0;
Jens Axboe351de8d2011-10-12 21:03:45 +0200141
Jens Axboe716050f2011-08-16 08:43:45 +0200142 /*
Jens Axboe802ad4a2011-10-05 09:51:58 +0200143 * Sort the percentile list. Note that it may already be sorted if
144 * we are using the default values, but since it's a short list this
145 * isn't a worry. Also note that this does not work for NaN values.
Jens Axboe716050f2011-08-16 08:43:45 +0200146 */
Jens Axboe802ad4a2011-10-05 09:51:58 +0200147 if (len > 1)
Jens Axboe3c3ed072012-03-27 09:12:39 +0200148 qsort((void *)plist, len, sizeof(plist[0]), double_cmp);
Yu-ju Hong83349192011-08-13 00:53:44 +0200149
Jens Axboe4f6f8292011-10-13 09:28:21 +0200150 /*
151 * Calculate bucket values, note down max and min values
152 */
Jens Axboe07511a62011-10-13 12:00:24 +0200153 is_last = 0;
154 for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) {
Yu-ju Hong83349192011-08-13 00:53:44 +0200155 sum += io_u_plat[i];
Jens Axboe802ad4a2011-10-05 09:51:58 +0200156 while (sum >= (plist[j].u.f / 100.0 * nr)) {
157 assert(plist[j].u.f <= 100.0);
Yu-ju Hong83349192011-08-13 00:53:44 +0200158
Jens Axboe4f6f8292011-10-13 09:28:21 +0200159 if (j == oval_len) {
160 oval_len += 100;
161 ovals = realloc(ovals, oval_len * sizeof(unsigned int));
162 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200163
Jens Axboe4f6f8292011-10-13 09:28:21 +0200164 ovals[j] = plat_idx_to_val(i);
Jens Axboe1db92cb2011-10-13 13:43:36 +0200165 if (ovals[j] < *minv)
166 *minv = ovals[j];
167 if (ovals[j] > *maxv)
168 *maxv = ovals[j];
Jens Axboe07511a62011-10-13 12:00:24 +0200169
170 is_last = (j == len - 1);
171 if (is_last)
172 break;
173
Jens Axboe4f6f8292011-10-13 09:28:21 +0200174 j++;
Yu-ju Hong83349192011-08-13 00:53:44 +0200175 }
176 }
Jens Axboe4f6f8292011-10-13 09:28:21 +0200177
Jens Axboe1db92cb2011-10-13 13:43:36 +0200178 *output = ovals;
179 return len;
180}
181
182/*
183 * Find and display the p-th percentile of clat
184 */
185static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
186 fio_fp64_t *plist)
187{
188 unsigned int len, j = 0, minv, maxv;
189 unsigned int *ovals;
190 int is_last, scale_down;
191
192 len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
193 if (!len)
194 goto out;
195
Jens Axboe4f6f8292011-10-13 09:28:21 +0200196 /*
197 * We default to usecs, but if the value range is such that we
198 * should scale down to msecs, do that.
199 */
200 if (minv > 2000 && maxv > 99999) {
201 scale_down = 1;
202 log_info(" clat percentiles (msec):\n |");
203 } else {
204 scale_down = 0;
205 log_info(" clat percentiles (usec):\n |");
206 }
207
208 for (j = 0; j < len; j++) {
209 char fbuf[8];
210
211 /* for formatting */
212 if (j != 0 && (j % 4) == 0)
213 log_info(" |");
214
215 /* end of the list */
216 is_last = (j == len - 1);
217
218 if (plist[j].u.f < 10.0)
219 sprintf(fbuf, " %2.2f", plist[j].u.f);
220 else
221 sprintf(fbuf, "%2.2f", plist[j].u.f);
222
223 if (scale_down)
224 ovals[j] = (ovals[j] + 999) / 1000;
225
226 log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ',');
227
228 if (is_last)
229 break;
230
231 if (j % 4 == 3) /* for formatting */
232 log_info("\n");
233 }
234
Jens Axboe1db92cb2011-10-13 13:43:36 +0200235out:
Jens Axboe4f6f8292011-10-13 09:28:21 +0200236 if (ovals)
237 free(ovals);
Yu-ju Hong83349192011-08-13 00:53:44 +0200238}
239
Jens Axboeb29ad562012-03-05 13:08:51 +0100240int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
241 double *mean, double *dev)
Jens Axboe3c39a372006-06-06 20:56:12 +0200242{
Jens Axboe68704082007-01-10 19:56:37 +0100243 double n = is->samples;
Jens Axboe3c39a372006-06-06 20:56:12 +0200244
245 if (is->samples == 0)
246 return 0;
247
248 *min = is->min_val;
249 *max = is->max_val;
250
251 n = (double) is->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200252 *mean = is->mean.u.f;
Jens Axboe3c39a372006-06-06 20:56:12 +0200253
Jens Axboe68704082007-01-10 19:56:37 +0100254 if (n > 1.0)
Jens Axboe802ad4a2011-10-05 09:51:58 +0200255 *dev = sqrt(is->S.u.f / (n - 1.0));
Jens Axboeef9c5c42007-01-03 14:21:13 +0100256 else
Jens Axboe4b43f542007-07-19 21:38:35 +0200257 *dev = 0;
Jens Axboeef9c5c42007-01-03 14:21:13 +0100258
Jens Axboe3c39a372006-06-06 20:56:12 +0200259 return 1;
260}
261
Jens Axboea64e88d2011-10-03 14:20:01 +0200262void show_group_stats(struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200263{
Jens Axboedbe11252007-02-11 00:19:51 +0100264 char *p1, *p2, *p3, *p4;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200265 const char *ddir_str[] = { " READ", " WRITE" , " TRIM"};
Jens Axboedbe11252007-02-11 00:19:51 +0100266 int i;
267
Jens Axboe7e1773b2011-10-14 12:47:56 +0200268 log_info("\nRun status group %d (all jobs):\n", rs->groupid);
Jens Axboe3c39a372006-06-06 20:56:12 +0200269
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200270 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200271 const int i2p = is_power_of_2(rs->kb_base);
272
Jens Axboedbe11252007-02-11 00:19:51 +0100273 if (!rs->max_run[i])
274 continue;
275
Jens Axboe90fef2d2009-07-17 22:33:32 +0200276 p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p);
277 p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p);
278 p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p);
279 p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p);
Jens Axboedbe11252007-02-11 00:19:51 +0100280
Jens Axboeb22989b2009-07-17 22:29:23 +0200281 log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s,"
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100282 " mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2,
283 p3, p4, rs->min_run[i],
284 rs->max_run[i]);
Jens Axboedbe11252007-02-11 00:19:51 +0100285
286 free(p1);
287 free(p2);
288 free(p3);
289 free(p4);
290 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200291}
292
Jens Axboe2e331012012-03-05 22:07:54 +0100293void stat_calc_dist(unsigned int *map, unsigned long total, double *io_u_dist)
Jens Axboe22708902007-03-06 17:05:32 +0100294{
295 int i;
296
297 /*
298 * Do depth distribution calculations
299 */
300 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200301 if (total) {
302 io_u_dist[i] = (double) map[i] / (double) total;
303 io_u_dist[i] *= 100.0;
304 if (io_u_dist[i] < 0.1 && map[i])
305 io_u_dist[i] = 0.1;
306 } else
307 io_u_dist[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100308 }
309}
310
Jens Axboe04a0fea2007-06-19 12:48:41 +0200311static void stat_calc_lat(struct thread_stat *ts, double *dst,
312 unsigned int *src, int nr)
Jens Axboe22708902007-03-06 17:05:32 +0100313{
Jens Axboed79db122012-09-24 08:51:24 +0200314 unsigned long total = ddir_rw_sum(ts->total_io_u);
Jens Axboe22708902007-03-06 17:05:32 +0100315 int i;
316
317 /*
318 * Do latency distribution calculations
319 */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200320 for (i = 0; i < nr; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200321 if (total) {
322 dst[i] = (double) src[i] / (double) total;
323 dst[i] *= 100.0;
324 if (dst[i] < 0.01 && src[i])
325 dst[i] = 0.01;
326 } else
327 dst[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100328 }
329}
330
Jens Axboee5bd1342012-03-05 21:38:12 +0100331void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200332{
333 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
334}
335
Jens Axboee5bd1342012-03-05 21:38:12 +0100336void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200337{
338 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
339}
340
Jens Axboeb29ad562012-03-05 13:08:51 +0100341static void display_lat(const char *name, unsigned long min, unsigned long max,
342 double mean, double dev)
Jens Axboeea2accc2007-06-19 09:48:44 +0200343{
Jens Axboeb29ad562012-03-05 13:08:51 +0100344 const char *base = "(usec)";
345 char *minp, *maxp;
Jens Axboeea2accc2007-06-19 09:48:44 +0200346
Jens Axboeb29ad562012-03-05 13:08:51 +0100347 if (!usec_to_msec(&min, &max, &mean, &dev))
348 base = "(msec)";
349
350 minp = num2str(min, 6, 1, 0);
351 maxp = num2str(max, 6, 1, 0);
352
353 log_info(" %s %s: min=%s, max=%s, avg=%5.02f,"
354 " stdev=%5.02f\n", name, base, minp, maxp, mean, dev);
355
356 free(minp);
357 free(maxp);
Jens Axboeea2accc2007-06-19 09:48:44 +0200358}
359
Jens Axboe756867b2007-03-06 15:19:24 +0100360static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
Jens Axboe3c39a372006-06-06 20:56:12 +0200361 int ddir)
362{
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200363 const char *ddir_str[] = { "read ", "write", "trim" };
Jens Axboe8879fd12009-04-20 10:06:02 +0200364 unsigned long min, max, runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100365 unsigned long long bw, iops;
Jens Axboe3c39a372006-06-06 20:56:12 +0200366 double mean, dev;
Jens Axboeb3605062007-03-12 14:19:47 +0100367 char *io_p, *bw_p, *iops_p;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200368 int i2p;
Jens Axboe3c39a372006-06-06 20:56:12 +0200369
Jens Axboeff58fce2010-08-25 12:02:08 +0200370 assert(ddir_rw(ddir));
371
Jens Axboe756867b2007-03-06 15:19:24 +0100372 if (!ts->runtime[ddir])
Jens Axboe3c39a372006-06-06 20:56:12 +0200373 return;
374
Jens Axboe90fef2d2009-07-17 22:33:32 +0200375 i2p = is_power_of_2(rs->kb_base);
Jens Axboe8879fd12009-04-20 10:06:02 +0200376 runt = ts->runtime[ddir];
377
378 bw = (1000 * ts->io_bytes[ddir]) / runt;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200379 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
380 bw_p = num2str(bw, 6, 1, i2p);
Jens Axboe8879fd12009-04-20 10:06:02 +0200381
Bruce Cran0aacc502011-07-09 08:19:53 +0200382 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100383 iops_p = num2str(iops, 6, 1, 0);
Jens Axboedbe11252007-02-11 00:19:51 +0100384
Signed-off-by Steven Prattcda99fa2010-12-14 08:31:36 +0100385 log_info(" %s: io=%sB, bw=%sB/s, iops=%s, runt=%6llumsec\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100386 ddir_str[ddir], io_p, bw_p, iops_p,
387 ts->runtime[ddir]);
Jens Axboedbe11252007-02-11 00:19:51 +0100388
389 free(io_p);
390 free(bw_p);
Jens Axboeb3605062007-03-12 14:19:47 +0100391 free(iops_p);
Jens Axboe3c39a372006-06-06 20:56:12 +0200392
Jens Axboeb29ad562012-03-05 13:08:51 +0100393 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
394 display_lat("slat", min, max, mean, dev);
395 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
396 display_lat("clat", min, max, mean, dev);
397 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
398 display_lat(" lat", min, max, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200399
Yu-ju Hong83349192011-08-13 00:53:44 +0200400 if (ts->clat_percentiles) {
401 show_clat_percentiles(ts->io_u_plat[ddir],
402 ts->clat_stat[ddir].samples,
403 ts->percentile_list);
404 }
Jens Axboe079ad092007-02-20 13:58:20 +0100405 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100406 double p_of_agg = 100.0;
Jens Axboeb7017e32011-10-14 09:30:01 +0200407 const char *bw_str = "KB";
Jens Axboe3c39a372006-06-06 20:56:12 +0200408
Jens Axboe2f2c6922012-02-07 16:42:43 +0100409 if (rs->agg[ddir]) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100410 p_of_agg = mean * 100 / (double) rs->agg[ddir];
411 if (p_of_agg > 100.0)
412 p_of_agg = 100.0;
413 }
Jens Axboeb7017e32011-10-14 09:30:01 +0200414
415 if (mean > 999999.9) {
416 min /= 1000.0;
417 max /= 1000.0;
418 mean /= 1000.0;
419 dev /= 1000.0;
420 bw_str = "MB";
421 }
422
Jens Axboe7e1773b2011-10-14 12:47:56 +0200423 log_info(" bw (%s/s) : min=%5lu, max=%5lu, per=%3.2f%%,"
Jens Axboeb7017e32011-10-14 09:30:01 +0200424 " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max,
425 p_of_agg, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200426 }
427}
428
Jens Axboe7e1773b2011-10-14 12:47:56 +0200429static int show_lat(double *io_u_lat, int nr, const char **ranges,
430 const char *msg)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200431{
Jens Axboe7e1773b2011-10-14 12:47:56 +0200432 int new_line = 1, i, line = 0, shown = 0;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200433
434 for (i = 0; i < nr; i++) {
435 if (io_u_lat[i] <= 0.0)
436 continue;
Jens Axboe7e1773b2011-10-14 12:47:56 +0200437 shown = 1;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200438 if (new_line) {
Jens Axboe4539ed72007-07-23 14:21:17 +0200439 if (line)
440 log_info("\n");
Jens Axboe7e1773b2011-10-14 12:47:56 +0200441 log_info(" lat (%s) : ", msg);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200442 new_line = 0;
443 line = 0;
444 }
445 if (line)
446 log_info(", ");
447 log_info("%s%3.2f%%", ranges[i], io_u_lat[i]);
448 line++;
449 if (line == 5)
450 new_line = 1;
451 }
Jens Axboe7e1773b2011-10-14 12:47:56 +0200452
453 if (shown)
454 log_info("\n");
455
456 return shown;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200457}
458
459static void show_lat_u(double *io_u_lat_u)
460{
461 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
462 "250=", "500=", "750=", "1000=", };
463
464 show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec");
465}
466
467static void show_lat_m(double *io_u_lat_m)
468{
469 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
470 "250=", "500=", "750=", "1000=", "2000=",
471 ">=2000=", };
472
473 show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec");
474}
475
Jens Axboec551f652012-03-05 20:49:10 +0100476static void show_latencies(struct thread_stat *ts)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200477{
Jens Axboec551f652012-03-05 20:49:10 +0100478 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
479 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
480
Jens Axboe5a189882012-03-05 14:08:34 +0100481 stat_calc_lat_u(ts, io_u_lat_u);
482 stat_calc_lat_m(ts, io_u_lat_m);
483
Jens Axboe04a0fea2007-06-19 12:48:41 +0200484 show_lat_u(io_u_lat_u);
485 show_lat_m(io_u_lat_m);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200486}
487
Jens Axboea64e88d2011-10-03 14:20:01 +0200488void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200489{
490 double usr_cpu, sys_cpu;
Jens Axboe69008992006-11-24 13:12:56 +0100491 unsigned long runtime;
Jens Axboe71619dc2007-01-13 23:56:33 +0100492 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe57a64322012-06-14 15:11:15 +0200493 time_t time_p;
494 char time_buf[64];
Jens Axboe3c39a372006-06-06 20:56:12 +0200495
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200496 if (!(ts->io_bytes[DDIR_READ] + ts->io_bytes[DDIR_WRITE] +
497 ts->io_bytes[DDIR_TRIM]) && !(ts->total_io_u[DDIR_READ] +
498 ts->total_io_u[DDIR_WRITE] + ts->total_io_u[DDIR_TRIM]))
Jens Axboe3c39a372006-06-06 20:56:12 +0200499 return;
500
Jens Axboe57a64322012-06-14 15:11:15 +0200501 time(&time_p);
Saurabh De45054cb2012-10-09 14:46:24 -0600502 os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf));
Jens Axboe57a64322012-06-14 15:11:15 +0200503
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100504 if (!ts->error) {
Jens Axboe57a64322012-06-14 15:11:15 +0200505 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100506 ts->name, ts->groupid, ts->members,
Jens Axboe57a64322012-06-14 15:11:15 +0200507 ts->error, (int) ts->pid, time_buf);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100508 } else {
Jens Axboe57a64322012-06-14 15:11:15 +0200509 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100510 ts->name, ts->groupid, ts->members,
Jens Axboe57a64322012-06-14 15:11:15 +0200511 ts->error, ts->verror, (int) ts->pid,
512 time_buf);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100513 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200514
Jens Axboe259e47d2011-10-13 21:05:59 +0200515 if (strlen(ts->description))
Jens Axboe6d861442007-03-15 09:22:23 +0100516 log_info(" Description : [%s]\n", ts->description);
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100517
Jens Axboe756867b2007-03-06 15:19:24 +0100518 if (ts->io_bytes[DDIR_READ])
519 show_ddir_status(rs, ts, DDIR_READ);
520 if (ts->io_bytes[DDIR_WRITE])
521 show_ddir_status(rs, ts, DDIR_WRITE);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200522 if (ts->io_bytes[DDIR_TRIM])
523 show_ddir_status(rs, ts, DDIR_TRIM);
Jens Axboe3c39a372006-06-06 20:56:12 +0200524
Jens Axboec551f652012-03-05 20:49:10 +0100525 show_latencies(ts);
Jens Axboe7e1773b2011-10-14 12:47:56 +0200526
Jens Axboe756867b2007-03-06 15:19:24 +0100527 runtime = ts->total_run_time;
Jens Axboe69008992006-11-24 13:12:56 +0100528 if (runtime) {
Jens Axboe1e97cce2006-12-05 11:44:16 +0100529 double runt = (double) runtime;
Jens Axboe3c39a372006-06-06 20:56:12 +0200530
Jens Axboe756867b2007-03-06 15:19:24 +0100531 usr_cpu = (double) ts->usr_time * 100 / runt;
532 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboe3c39a372006-06-06 20:56:12 +0200533 } else {
534 usr_cpu = 0;
535 sys_cpu = 0;
536 }
537
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100538 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu,"
539 " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf);
Jens Axboe71619dc2007-01-13 23:56:33 +0100540
Jens Axboed79db122012-09-24 08:51:24 +0200541 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100542 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%,"
543 " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
544 io_u_dist[1], io_u_dist[2],
545 io_u_dist[3], io_u_dist[4],
546 io_u_dist[5], io_u_dist[6]);
Jens Axboe838bc702008-05-22 13:08:23 +0200547
548 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
549 log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
550 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
551 io_u_dist[1], io_u_dist[2],
552 io_u_dist[3], io_u_dist[4],
553 io_u_dist[5], io_u_dist[6]);
554 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
555 log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
556 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
557 io_u_dist[1], io_u_dist[2],
558 io_u_dist[3], io_u_dist[4],
559 io_u_dist[5], io_u_dist[6]);
Jens Axboe7e1773b2011-10-14 12:47:56 +0200560 log_info(" issued : total=r=%lu/w=%lu/d=%lu,"
561 " short=r=%lu/w=%lu/d=%lu\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100562 ts->total_io_u[0], ts->total_io_u[1],
Jens Axboe0d29de82010-09-01 13:54:15 +0200563 ts->total_io_u[2],
564 ts->short_io_u[0], ts->short_io_u[1],
565 ts->short_io_u[2]);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200566 if (ts->continue_on_error) {
Jens Axboe1ec99ee2009-06-15 12:37:30 +0200567 log_info(" errors : total=%lu, first_error=%d/<%s>\n",
568 ts->total_err_count,
569 ts->first_error,
570 strerror(ts->first_error));
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200571 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200572}
573
Jens Axboe756867b2007-03-06 15:19:24 +0100574static void show_ddir_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200575 struct group_run_stats *rs, int ddir)
576{
577 unsigned long min, max;
Jens Axboe312b4af2011-10-13 13:11:42 +0200578 unsigned long long bw, iops;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200579 unsigned int *ovals = NULL;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200580 double mean, dev;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200581 unsigned int len, minv, maxv;
582 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200583
Jens Axboeff58fce2010-08-25 12:02:08 +0200584 assert(ddir_rw(ddir));
585
Jens Axboe312b4af2011-10-13 13:11:42 +0200586 iops = bw = 0;
587 if (ts->runtime[ddir]) {
588 uint64_t runt = ts->runtime[ddir];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200589
Jens Axboe033bbb52012-05-07 09:46:40 +0200590 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
Jens Axboe312b4af2011-10-13 13:11:42 +0200591 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
592 }
593
594 log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops,
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100595 ts->runtime[ddir]);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200596
Jens Axboe079ad092007-02-20 13:58:20 +0100597 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100598 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200599 else
Jens Axboe6d861442007-03-15 09:22:23 +0100600 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200601
Jens Axboe079ad092007-02-20 13:58:20 +0100602 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100603 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200604 else
Jens Axboe6d861442007-03-15 09:22:23 +0100605 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200606
Jens Axboe1db92cb2011-10-13 13:43:36 +0200607 if (ts->clat_percentiles) {
608 len = calc_clat_percentiles(ts->io_u_plat[ddir],
609 ts->clat_stat[ddir].samples,
610 ts->percentile_list, &ovals, &maxv,
611 &minv);
612 } else
613 len = 0;
614
615 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
616 if (i >= len) {
617 log_info(";0%%=0");
618 continue;
619 }
620 log_info(";%2.2f%%=%u", ts->percentile_list[i].u.f, ovals[i]);
621 }
Keplar kramer2341a372011-10-19 21:31:27 +0200622
623 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
624 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
625 else
626 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
627
Jens Axboe1db92cb2011-10-13 13:43:36 +0200628 if (ovals)
629 free(ovals);
630
Jens Axboe079ad092007-02-20 13:58:20 +0100631 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100632 double p_of_agg = 100.0;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200633
Jens Axboe19d3e962012-02-07 12:27:28 +0100634 if (rs->agg[ddir]) {
635 p_of_agg = mean * 100 / (double) rs->agg[ddir];
636 if (p_of_agg > 100.0)
637 p_of_agg = 100.0;
638 }
639
Jens Axboe6d861442007-03-15 09:22:23 +0100640 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, 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;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200643}
644
Shaohua Licc372b12012-09-17 09:12:18 +0200645static void add_ddir_status_json(struct thread_stat *ts,
646 struct group_run_stats *rs, int ddir, struct json_object *parent)
647{
648 unsigned long min, max;
649 unsigned long long bw, iops;
650 unsigned int *ovals = NULL;
651 double mean, dev;
652 unsigned int len, minv, maxv;
653 int i;
654 const char *ddirname[] = {"read", "write", "trim"};
655 struct json_object *dir_object, *tmp_object, *percentile_object;
656 char buf[120];
657 double p_of_agg = 100.0;
658
659 assert(ddir_rw(ddir));
660
661 dir_object = json_create_object();
662 json_object_add_value_object(parent, ddirname[ddir], dir_object);
663
664 iops = bw = 0;
665 if (ts->runtime[ddir]) {
666 uint64_t runt = ts->runtime[ddir];
667
668 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
669 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
670 }
671
672 json_object_add_value_int(dir_object, "io_bytes", ts->io_bytes[ddir] >> 10);
673 json_object_add_value_int(dir_object, "bw", bw);
674 json_object_add_value_int(dir_object, "iops", iops);
675 json_object_add_value_int(dir_object, "runtime", ts->runtime[ddir]);
676
677 if (!calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
678 min = max = 0;
679 mean = dev = 0.0;
680 }
681 tmp_object = json_create_object();
682 json_object_add_value_object(dir_object, "slat", tmp_object);
683 json_object_add_value_int(tmp_object, "min", min);
684 json_object_add_value_int(tmp_object, "max", max);
685 json_object_add_value_float(tmp_object, "mean", mean);
686 json_object_add_value_float(tmp_object, "stddev", dev);
687
688 if (!calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
689 min = max = 0;
690 mean = dev = 0.0;
691 }
692 tmp_object = json_create_object();
693 json_object_add_value_object(dir_object, "clat", tmp_object);
694 json_object_add_value_int(tmp_object, "min", min);
695 json_object_add_value_int(tmp_object, "max", max);
696 json_object_add_value_float(tmp_object, "mean", mean);
697 json_object_add_value_float(tmp_object, "stddev", dev);
698
699 if (ts->clat_percentiles) {
700 len = calc_clat_percentiles(ts->io_u_plat[ddir],
701 ts->clat_stat[ddir].samples,
702 ts->percentile_list, &ovals, &maxv,
703 &minv);
704 } else
705 len = 0;
706
707 percentile_object = json_create_object();
708 json_object_add_value_object(tmp_object, "percentile", percentile_object);
709 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
710 if (i >= len) {
711 json_object_add_value_int(percentile_object, "0.00", 0);
712 continue;
713 }
714 snprintf(buf, sizeof(buf) - 1, "%2.2f", ts->percentile_list[i].u.f);
715 json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]);
716 }
717
718 if (!calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) {
719 min = max = 0;
720 mean = dev = 0.0;
721 }
722 tmp_object = json_create_object();
723 json_object_add_value_object(dir_object, "lat", tmp_object);
724 json_object_add_value_int(tmp_object, "min", min);
725 json_object_add_value_int(tmp_object, "max", max);
726 json_object_add_value_float(tmp_object, "mean", mean);
727 json_object_add_value_float(tmp_object, "stddev", dev);
728 if (ovals)
729 free(ovals);
730
731 if (!calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
732 if (rs->agg[ddir]) {
733 p_of_agg = mean * 100 / (double) rs->agg[ddir];
734 if (p_of_agg > 100.0)
735 p_of_agg = 100.0;
736 }
737 } else {
738 min = max = 0;
739 p_of_agg = mean = dev = 0.0;
740 }
741 json_object_add_value_int(dir_object, "bw_min", min);
742 json_object_add_value_int(dir_object, "bw_max", max);
743 json_object_add_value_float(dir_object, "bw_agg", mean);
744 json_object_add_value_float(dir_object, "bw_mean", mean);
745 json_object_add_value_float(dir_object, "bw_dev", dev);
746}
747
Jens Axboe4d658652011-10-17 15:05:47 +0200748static void show_thread_status_terse_v2(struct thread_stat *ts,
Jens Axboe3c3ed072012-03-27 09:12:39 +0200749 struct group_run_stats *rs)
Jens Axboe4d658652011-10-17 15:05:47 +0200750{
751 double io_u_dist[FIO_IO_U_MAP_NR];
752 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
753 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
754 double usr_cpu, sys_cpu;
755 int i;
756
757 /* General Info */
758 log_info("2;%s;%d;%d", ts->name, ts->groupid, ts->error);
759 /* Log Read Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200760 show_ddir_status_terse(ts, rs, DDIR_READ);
Jens Axboe4d658652011-10-17 15:05:47 +0200761 /* Log Write Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200762 show_ddir_status_terse(ts, rs, DDIR_WRITE);
763 /* Log Trim Status */
764 show_ddir_status_terse(ts, rs, DDIR_TRIM);
Jens Axboe4d658652011-10-17 15:05:47 +0200765
766 /* CPU Usage */
767 if (ts->total_run_time) {
768 double runt = (double) ts->total_run_time;
769
770 usr_cpu = (double) ts->usr_time * 100 / runt;
771 sys_cpu = (double) ts->sys_time * 100 / runt;
772 } else {
773 usr_cpu = 0;
774 sys_cpu = 0;
775 }
776
777 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
778 ts->minf);
779
780 /* Calc % distribution of IO depths, usecond, msecond latency */
Jens Axboed79db122012-09-24 08:51:24 +0200781 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
Jens Axboe4d658652011-10-17 15:05:47 +0200782 stat_calc_lat_u(ts, io_u_lat_u);
783 stat_calc_lat_m(ts, io_u_lat_m);
784
785 /* Only show fixed 7 I/O depth levels*/
786 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
787 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
788 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
789
790 /* Microsecond latency */
791 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
792 log_info(";%3.2f%%", io_u_lat_u[i]);
793 /* Millisecond latency */
794 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
795 log_info(";%3.2f%%", io_u_lat_m[i]);
796 /* Additional output if continue_on_error set - default off*/
797 if (ts->continue_on_error)
798 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
799 log_info("\n");
800
801 /* Additional output if description is set */
802 if (ts->description)
803 log_info(";%s", ts->description);
804
805 log_info("\n");
806}
807
Jens Axboe3449ab82012-09-14 23:35:08 +0200808static void show_thread_status_terse_v3_v4(struct thread_stat *ts,
809 struct group_run_stats *rs, int ver)
Jens Axboec6ae0a52006-06-12 11:04:44 +0200810{
Jens Axboe22708902007-03-06 17:05:32 +0100811 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200812 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
813 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200814 double usr_cpu, sys_cpu;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200815 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200816
David Nellans562c2d22010-09-23 08:38:17 +0200817 /* General Info */
Jens Axboef3afa572012-09-17 13:34:16 +0200818 log_info("%d;%s;%s;%d;%d", ver, fio_version_string,
Jens Axboe5e726d02011-10-14 08:08:10 +0200819 ts->name, ts->groupid, ts->error);
David Nellans562c2d22010-09-23 08:38:17 +0200820 /* Log Read Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200821 show_ddir_status_terse(ts, rs, DDIR_READ);
David Nellans562c2d22010-09-23 08:38:17 +0200822 /* Log Write Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200823 show_ddir_status_terse(ts, rs, DDIR_WRITE);
824 /* Log Trim Status */
Jens Axboe3449ab82012-09-14 23:35:08 +0200825 if (ver == 4)
826 show_ddir_status_terse(ts, rs, DDIR_TRIM);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200827
David Nellans562c2d22010-09-23 08:38:17 +0200828 /* CPU Usage */
Jens Axboe756867b2007-03-06 15:19:24 +0100829 if (ts->total_run_time) {
830 double runt = (double) ts->total_run_time;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200831
Jens Axboe756867b2007-03-06 15:19:24 +0100832 usr_cpu = (double) ts->usr_time * 100 / runt;
833 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200834 } else {
835 usr_cpu = 0;
836 sys_cpu = 0;
837 }
838
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100839 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
840 ts->minf);
Jens Axboe22708902007-03-06 17:05:32 +0100841
David Nellans562c2d22010-09-23 08:38:17 +0200842 /* Calc % distribution of IO depths, usecond, msecond latency */
Jens Axboed79db122012-09-24 08:51:24 +0200843 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200844 stat_calc_lat_u(ts, io_u_lat_u);
845 stat_calc_lat_m(ts, io_u_lat_m);
Jens Axboe22708902007-03-06 17:05:32 +0100846
David Nellans562c2d22010-09-23 08:38:17 +0200847 /* Only show fixed 7 I/O depth levels*/
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100848 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
849 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
850 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
Jens Axboe22708902007-03-06 17:05:32 +0100851
David Nellans562c2d22010-09-23 08:38:17 +0200852 /* Microsecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200853 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
854 log_info(";%3.2f%%", io_u_lat_u[i]);
David Nellans562c2d22010-09-23 08:38:17 +0200855 /* Millisecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200856 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
857 log_info(";%3.2f%%", io_u_lat_m[i]);
Jens Axboef2f788d2011-10-13 14:03:52 +0200858
859 /* disk util stats, if any */
Shaohua Licc372b12012-09-17 09:12:18 +0200860 show_disk_util(1, NULL);
Jens Axboef2f788d2011-10-13 14:03:52 +0200861
David Nellans562c2d22010-09-23 08:38:17 +0200862 /* Additional output if continue_on_error set - default off*/
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200863 if (ts->continue_on_error)
864 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
Jens Axboe22708902007-03-06 17:05:32 +0100865
David Nellans562c2d22010-09-23 08:38:17 +0200866 /* Additional output if description is set */
Jens Axboe4b0f2252011-10-13 15:03:25 +0200867 if (strlen(ts->description))
Jens Axboe6d861442007-03-15 09:22:23 +0100868 log_info(";%s", ts->description);
Jens Axboe946e4272012-03-23 19:22:21 +0100869
870 log_info("\n");
Jens Axboe756867b2007-03-06 15:19:24 +0100871}
872
Shaohua Licc372b12012-09-17 09:12:18 +0200873static struct json_object *show_thread_status_json(struct thread_stat *ts,
874 struct group_run_stats *rs)
875{
876 struct json_object *root, *tmp;
877 double io_u_dist[FIO_IO_U_MAP_NR];
878 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
879 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
880 double usr_cpu, sys_cpu;
881 int i;
882
883 root = json_create_object();
884 json_object_add_value_string(root, "jobname", ts->name);
885 json_object_add_value_int(root, "groupid", ts->groupid);
886 json_object_add_value_int(root, "error", ts->error);
887
888 add_ddir_status_json(ts, rs, DDIR_READ, root);
889 add_ddir_status_json(ts, rs, DDIR_WRITE, root);
Jens Axboef3afa572012-09-17 13:34:16 +0200890 add_ddir_status_json(ts, rs, DDIR_TRIM, root);
Shaohua Licc372b12012-09-17 09:12:18 +0200891
892 /* CPU Usage */
893 if (ts->total_run_time) {
894 double runt = (double) ts->total_run_time;
895
896 usr_cpu = (double) ts->usr_time * 100 / runt;
897 sys_cpu = (double) ts->sys_time * 100 / runt;
898 } else {
899 usr_cpu = 0;
900 sys_cpu = 0;
901 }
902 json_object_add_value_float(root, "usr_cpu", usr_cpu);
903 json_object_add_value_float(root, "sys_cpu", sys_cpu);
904 json_object_add_value_int(root, "ctx", ts->ctx);
905 json_object_add_value_int(root, "majf", ts->majf);
906 json_object_add_value_int(root, "minf", ts->minf);
907
908
909 /* Calc % distribution of IO depths, usecond, msecond latency */
Jens Axboed79db122012-09-24 08:51:24 +0200910 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
Shaohua Licc372b12012-09-17 09:12:18 +0200911 stat_calc_lat_u(ts, io_u_lat_u);
912 stat_calc_lat_m(ts, io_u_lat_m);
913
914 tmp = json_create_object();
915 json_object_add_value_object(root, "iodepth_level", tmp);
916 /* Only show fixed 7 I/O depth levels*/
917 for (i = 0; i < 7; i++) {
918 char name[20];
919 if (i < 6)
920 snprintf(name, 19, "%d", 1 << i);
921 else
922 snprintf(name, 19, ">=%d", 1 << i);
923 json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]);
924 }
925
926 tmp = json_create_object();
927 json_object_add_value_object(root, "latency_us", tmp);
928 /* Microsecond latency */
929 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
930 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
931 "250", "500", "750", "1000", };
932 json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]);
933 }
934 /* Millisecond latency */
935 tmp = json_create_object();
936 json_object_add_value_object(root, "latency_ms", tmp);
937 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) {
938 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
939 "250", "500", "750", "1000", "2000",
940 ">=2000", };
941 json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]);
942 }
943
944 /* Additional output if continue_on_error set - default off*/
945 if (ts->continue_on_error) {
946 json_object_add_value_int(root, "total_err", ts->total_err_count);
947 json_object_add_value_int(root, "total_err", ts->first_error);
948 }
949
950 /* Additional output if description is set */
951 if (strlen(ts->description))
952 json_object_add_value_string(root, "desc", ts->description);
953
954 return root;
955}
956
Jens Axboe4d658652011-10-17 15:05:47 +0200957static void show_thread_status_terse(struct thread_stat *ts,
958 struct group_run_stats *rs)
959{
960 if (terse_version == 2)
961 show_thread_status_terse_v2(ts, rs);
Jens Axboe3449ab82012-09-14 23:35:08 +0200962 else if (terse_version == 3 || terse_version == 4)
963 show_thread_status_terse_v3_v4(ts, rs, terse_version);
Jens Axboe4d658652011-10-17 15:05:47 +0200964 else
965 log_err("fio: bad terse version!? %d\n", terse_version);
966}
967
Jens Axboe197574e2007-03-08 15:35:11 +0100968static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
Jens Axboe756867b2007-03-06 15:19:24 +0100969{
970 double mean, S;
971
Zheng Liue09231c2011-09-16 08:20:12 +0200972 if (src->samples == 0)
973 return;
974
Jens Axboe756867b2007-03-06 15:19:24 +0100975 dst->min_val = min(dst->min_val, src->min_val);
976 dst->max_val = max(dst->max_val, src->max_val);
Jens Axboe756867b2007-03-06 15:19:24 +0100977
978 /*
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200979 * Compute new mean and S after the merge
980 * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
981 * #Parallel_algorithm>
Jens Axboe756867b2007-03-06 15:19:24 +0100982 */
983 if (nr == 1) {
Jens Axboe802ad4a2011-10-05 09:51:58 +0200984 mean = src->mean.u.f;
985 S = src->S.u.f;
Jens Axboe756867b2007-03-06 15:19:24 +0100986 } else {
Jens Axboe802ad4a2011-10-05 09:51:58 +0200987 double delta = src->mean.u.f - dst->mean.u.f;
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200988
Jens Axboe802ad4a2011-10-05 09:51:58 +0200989 mean = ((src->mean.u.f * src->samples) +
990 (dst->mean.u.f * dst->samples)) /
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200991 (dst->samples + src->samples);
992
Jens Axboe802ad4a2011-10-05 09:51:58 +0200993 S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) *
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200994 (dst->samples * src->samples) /
995 (dst->samples + src->samples);
Jens Axboe756867b2007-03-06 15:19:24 +0100996 }
997
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200998 dst->samples += src->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200999 dst->mean.u.f = mean;
1000 dst->S.u.f = S;
Jens Axboe756867b2007-03-06 15:19:24 +01001001}
1002
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001003void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src)
1004{
1005 int i;
1006
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001007 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001008 if (dst->max_run[i] < src->max_run[i])
1009 dst->max_run[i] = src->max_run[i];
1010 if (dst->min_run[i] && dst->min_run[i] > src->min_run[i])
1011 dst->min_run[i] = src->min_run[i];
1012 if (dst->max_bw[i] < src->max_bw[i])
1013 dst->max_bw[i] = src->max_bw[i];
1014 if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i])
1015 dst->min_bw[i] = src->min_bw[i];
1016
1017 dst->io_kb[i] += src->io_kb[i];
1018 dst->agg[i] += src->agg[i];
1019 }
1020
1021}
1022
Jens Axboe5b9babb2011-10-10 12:14:30 +02001023void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr)
1024{
1025 int l, k;
1026
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001027 for (l = 0; l < DDIR_RWDIR_CNT; l++) {
Jens Axboe5b9babb2011-10-10 12:14:30 +02001028 sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr);
1029 sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr);
1030 sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr);
1031 sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr);
1032
1033 dst->io_bytes[l] += src->io_bytes[l];
1034
1035 if (dst->runtime[l] < src->runtime[l])
1036 dst->runtime[l] = src->runtime[l];
1037 }
1038
1039 dst->usr_time += src->usr_time;
1040 dst->sys_time += src->sys_time;
1041 dst->ctx += src->ctx;
1042 dst->majf += src->majf;
1043 dst->minf += src->minf;
1044
1045 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1046 dst->io_u_map[k] += src->io_u_map[k];
1047 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1048 dst->io_u_submit[k] += src->io_u_submit[k];
1049 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1050 dst->io_u_complete[k] += src->io_u_complete[k];
1051 for (k = 0; k < FIO_IO_U_LAT_U_NR; k++)
1052 dst->io_u_lat_u[k] += src->io_u_lat_u[k];
1053 for (k = 0; k < FIO_IO_U_LAT_M_NR; k++)
1054 dst->io_u_lat_m[k] += src->io_u_lat_m[k];
1055
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001056 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
Jens Axboe5b9babb2011-10-10 12:14:30 +02001057 dst->total_io_u[k] += src->total_io_u[k];
1058 dst->short_io_u[k] += src->short_io_u[k];
1059 }
1060
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001061 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
Jens Axboe5b9babb2011-10-10 12:14:30 +02001062 int m;
1063 for (m = 0; m < FIO_IO_U_PLAT_NR; m++)
1064 dst->io_u_plat[k][m] += src->io_u_plat[k][m];
1065 }
1066
1067 dst->total_run_time += src->total_run_time;
1068 dst->total_submit += src->total_submit;
1069 dst->total_complete += src->total_complete;
1070}
1071
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001072void init_group_run_stat(struct group_run_stats *gs)
1073{
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001074 int i;
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001075 memset(gs, 0, sizeof(*gs));
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001076
1077 for (i = 0; i < DDIR_RWDIR_CNT; i++)
1078 gs->min_bw[i] = gs->min_run[i] = ~0UL;
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001079}
1080
1081void init_thread_stat(struct thread_stat *ts)
1082{
1083 int j;
1084
1085 memset(ts, 0, sizeof(*ts));
1086
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001087 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001088 ts->lat_stat[j].min_val = -1UL;
1089 ts->clat_stat[j].min_val = -1UL;
1090 ts->slat_stat[j].min_val = -1UL;
1091 ts->bw_stat[j].min_val = -1UL;
1092 }
1093 ts->groupid = -1;
1094}
1095
Jens Axboe3c39a372006-06-06 20:56:12 +02001096void show_run_stats(void)
1097{
1098 struct group_run_stats *runstats, *rs;
1099 struct thread_data *td;
Jens Axboe756867b2007-03-06 15:19:24 +01001100 struct thread_stat *threadstats, *ts;
Jens Axboe5b9babb2011-10-10 12:14:30 +02001101 int i, j, nr_ts, last_ts, idx;
Jens Axboe90fef2d2009-07-17 22:33:32 +02001102 int kb_base_warned = 0;
Shaohua Licc372b12012-09-17 09:12:18 +02001103 struct json_object *root = NULL;
1104 struct json_array *array = NULL;
Jens Axboe3c39a372006-06-06 20:56:12 +02001105
1106 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
1107
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001108 for (i = 0; i < groupid + 1; i++)
1109 init_group_run_stat(&runstats[i]);
Jens Axboe3c39a372006-06-06 20:56:12 +02001110
Jens Axboe756867b2007-03-06 15:19:24 +01001111 /*
1112 * find out how many threads stats we need. if group reporting isn't
1113 * enabled, it's one-per-td.
1114 */
1115 nr_ts = 0;
1116 last_ts = -1;
Jens Axboe34572e22006-10-20 09:33:18 +02001117 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001118 if (!td->o.group_reporting) {
Jens Axboe756867b2007-03-06 15:19:24 +01001119 nr_ts++;
1120 continue;
1121 }
1122 if (last_ts == td->groupid)
1123 continue;
1124
1125 last_ts = td->groupid;
1126 nr_ts++;
1127 }
1128
1129 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
1130
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001131 for (i = 0; i < nr_ts; i++)
1132 init_thread_stat(&threadstats[i]);
Jens Axboe756867b2007-03-06 15:19:24 +01001133
1134 j = 0;
1135 last_ts = -1;
Jens Axboe197574e2007-03-08 15:35:11 +01001136 idx = 0;
Jens Axboe756867b2007-03-06 15:19:24 +01001137 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001138 if (idx && (!td->o.group_reporting ||
1139 (td->o.group_reporting && last_ts != td->groupid))) {
Jens Axboe7abd0e32007-03-12 15:24:43 +01001140 idx = 0;
1141 j++;
1142 }
1143
1144 last_ts = td->groupid;
1145
Jens Axboe756867b2007-03-06 15:19:24 +01001146 ts = &threadstats[j];
1147
Yu-ju Hong83349192011-08-13 00:53:44 +02001148 ts->clat_percentiles = td->o.clat_percentiles;
1149 if (td->o.overwrite_plist)
Jens Axboe802ad4a2011-10-05 09:51:58 +02001150 memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +02001151 else
Jens Axboe802ad4a2011-10-05 09:51:58 +02001152 memcpy(ts->percentile_list, def_percentile_list, sizeof(def_percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +02001153
Jens Axboe197574e2007-03-08 15:35:11 +01001154 idx++;
Jens Axboe6586ee82007-03-06 19:46:09 +01001155 ts->members++;
Jens Axboe756867b2007-03-06 15:19:24 +01001156
Jens Axboe7abd0e32007-03-12 15:24:43 +01001157 if (ts->groupid == -1) {
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001158 /*
1159 * These are per-group shared already
1160 */
Jens Axboef6bb5b82011-10-03 12:21:25 +02001161 strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE);
Jens Axboea64e88d2011-10-03 14:20:01 +02001162 if (td->o.description)
1163 strncpy(ts->description, td->o.description,
1164 FIO_JOBNAME_SIZE);
1165 else
1166 memset(ts->description, 0, FIO_JOBNAME_SIZE);
1167
Jens Axboe2f122b12012-03-15 13:10:19 +01001168 /*
1169 * If multiple entries in this group, this is
1170 * the first member.
1171 */
1172 ts->thread_number = td->thread_number;
Jens Axboe756867b2007-03-06 15:19:24 +01001173 ts->groupid = td->groupid;
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001174
1175 /*
1176 * first pid in group, not very useful...
1177 */
Jens Axboe756867b2007-03-06 15:19:24 +01001178 ts->pid = td->pid;
Jens Axboe90fef2d2009-07-17 22:33:32 +02001179
1180 ts->kb_base = td->o.kb_base;
1181 } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) {
1182 log_info("fio: kb_base differs for jobs in group, using"
1183 " %u as the base\n", ts->kb_base);
1184 kb_base_warned = 1;
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001185 }
1186
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001187 ts->continue_on_error = td->o.continue_on_error;
1188 ts->total_err_count += td->total_err_count;
1189 ts->first_error = td->first_error;
1190 if (!ts->error) {
1191 if (!td->error && td->o.continue_on_error &&
1192 td->first_error) {
1193 ts->error = td->first_error;
Jens Axboef6bb5b82011-10-03 12:21:25 +02001194 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001195 } else if (td->error) {
1196 ts->error = td->error;
Jens Axboef6bb5b82011-10-03 12:21:25 +02001197 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001198 }
Jens Axboe756867b2007-03-06 15:19:24 +01001199 }
1200
Jens Axboe5b9babb2011-10-10 12:14:30 +02001201 sum_thread_stats(ts, &td->ts, idx);
Jens Axboe756867b2007-03-06 15:19:24 +01001202 }
1203
1204 for (i = 0; i < nr_ts; i++) {
Jens Axboe94370ac2007-03-08 15:28:10 +01001205 unsigned long long bw;
Jens Axboe3c39a372006-06-06 20:56:12 +02001206
Jens Axboe756867b2007-03-06 15:19:24 +01001207 ts = &threadstats[i];
1208 rs = &runstats[ts->groupid];
Jens Axboe90fef2d2009-07-17 22:33:32 +02001209 rs->kb_base = ts->kb_base;
Jens Axboe3c39a372006-06-06 20:56:12 +02001210
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001211 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
Jens Axboe94370ac2007-03-08 15:28:10 +01001212 if (!ts->runtime[j])
1213 continue;
1214 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
1215 rs->min_run[j] = ts->runtime[j];
1216 if (ts->runtime[j] > rs->max_run[j])
1217 rs->max_run[j] = ts->runtime[j];
Jens Axboe3c39a372006-06-06 20:56:12 +02001218
Jens Axboe94370ac2007-03-08 15:28:10 +01001219 bw = 0;
Jens Axboe8879fd12009-04-20 10:06:02 +02001220 if (ts->runtime[j]) {
Jens Axboec857cfe2012-04-05 08:42:11 -06001221 unsigned long runt = ts->runtime[j];
1222 unsigned long long kb;
Jens Axboe8879fd12009-04-20 10:06:02 +02001223
Jens Axboec857cfe2012-04-05 08:42:11 -06001224 kb = ts->io_bytes[j] / rs->kb_base;
1225 bw = kb * 1000 / runt;
Jens Axboe8879fd12009-04-20 10:06:02 +02001226 }
Jens Axboe94370ac2007-03-08 15:28:10 +01001227 if (bw < rs->min_bw[j])
1228 rs->min_bw[j] = bw;
1229 if (bw > rs->max_bw[j])
1230 rs->max_bw[j] = bw;
Jens Axboe3c39a372006-06-06 20:56:12 +02001231
Jens Axboe90fef2d2009-07-17 22:33:32 +02001232 rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base;
Jens Axboe94370ac2007-03-08 15:28:10 +01001233 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001234 }
1235
1236 for (i = 0; i < groupid + 1; i++) {
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001237 int ddir;
1238
Jens Axboe3c39a372006-06-06 20:56:12 +02001239 rs = &runstats[i];
1240
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001241 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
1242 if (rs->max_run[ddir])
1243 rs->agg[ddir] = (rs->io_kb[ddir] * 1000) /
1244 rs->max_run[ddir];
1245 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001246 }
1247
1248 /*
1249 * don't overwrite last signal output
1250 */
Jens Axboef3afa572012-09-17 13:34:16 +02001251 if (output_format == FIO_OUTPUT_NORMAL)
Jens Axboe4ceb30d2010-02-24 09:19:14 +01001252 log_info("\n");
Jens Axboef3afa572012-09-17 13:34:16 +02001253 else if (output_format == FIO_OUTPUT_JSON) {
Shaohua Licc372b12012-09-17 09:12:18 +02001254 root = json_create_object();
1255 json_object_add_value_string(root, "fio version", fio_version_string);
1256 array = json_create_array();
1257 json_object_add_value_array(root, "jobs", array);
1258 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001259
Jens Axboe756867b2007-03-06 15:19:24 +01001260 for (i = 0; i < nr_ts; i++) {
1261 ts = &threadstats[i];
1262 rs = &runstats[ts->groupid];
Jens Axboe3c39a372006-06-06 20:56:12 +02001263
Jens Axboea64e88d2011-10-03 14:20:01 +02001264 if (is_backend)
1265 fio_server_send_ts(ts, rs);
Jens Axboef3afa572012-09-17 13:34:16 +02001266 else if (output_format == FIO_OUTPUT_TERSE)
Jens Axboe756867b2007-03-06 15:19:24 +01001267 show_thread_status_terse(ts, rs);
Jens Axboef3afa572012-09-17 13:34:16 +02001268 else if (output_format == FIO_OUTPUT_JSON) {
1269 struct json_object *tmp = show_thread_status_json(ts, rs);
1270 json_array_add_value_object(array, tmp);
Shaohua Licc372b12012-09-17 09:12:18 +02001271 } else
Jens Axboe756867b2007-03-06 15:19:24 +01001272 show_thread_status(ts, rs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001273 }
Jens Axboef3afa572012-09-17 13:34:16 +02001274 if (output_format == FIO_OUTPUT_JSON) {
Shaohua Licc372b12012-09-17 09:12:18 +02001275 /* disk util stats, if any */
1276 show_disk_util(1, root);
1277
1278 json_print_object(root);
1279 log_info("\n");
1280 json_free_object(root);
1281 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001282
Jens Axboe72c27ff2011-10-16 11:50:31 +02001283 for (i = 0; i < groupid + 1; i++) {
1284 rs = &runstats[i];
Jens Axboea64e88d2011-10-03 14:20:01 +02001285
Jens Axboe72c27ff2011-10-16 11:50:31 +02001286 rs->groupid = i;
Jens Axboed09a64a2011-10-13 11:38:56 +02001287 if (is_backend)
Jens Axboe72c27ff2011-10-16 11:50:31 +02001288 fio_server_send_gs(rs);
Jens Axboef3afa572012-09-17 13:34:16 +02001289 else if (output_format == FIO_OUTPUT_NORMAL)
Jens Axboe72c27ff2011-10-16 11:50:31 +02001290 show_group_stats(rs);
Jens Axboec6ae0a52006-06-12 11:04:44 +02001291 }
Jens Axboeeecf2722006-10-20 14:00:36 +02001292
Jens Axboe72c27ff2011-10-16 11:50:31 +02001293 if (is_backend)
1294 fio_server_send_du();
Jens Axboef3afa572012-09-17 13:34:16 +02001295 else if (output_format == FIO_OUTPUT_NORMAL)
Shaohua Licc372b12012-09-17 09:12:18 +02001296 show_disk_util(0, NULL);
Jens Axboe72c27ff2011-10-16 11:50:31 +02001297
Jens Axboeeecf2722006-10-20 14:00:36 +02001298 free(runstats);
Jens Axboe756867b2007-03-06 15:19:24 +01001299 free(threadstats);
Jens Axboe3c39a372006-06-06 20:56:12 +02001300}
1301
Jens Axboeb852e7c2012-03-30 10:30:35 +02001302static void *__show_running_run_stats(void *arg)
1303{
1304 struct thread_data *td;
1305 unsigned long long *rt;
1306 struct timeval tv;
1307 int i;
1308
1309 rt = malloc(thread_number * sizeof(unsigned long long));
1310 fio_gettime(&tv, NULL);
1311
1312 for_each_td(td, i) {
1313 rt[i] = mtime_since(&td->start, &tv);
1314 if (td_read(td) && td->io_bytes[DDIR_READ])
1315 td->ts.runtime[DDIR_READ] += rt[i];
1316 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1317 td->ts.runtime[DDIR_WRITE] += rt[i];
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001318 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1319 td->ts.runtime[DDIR_TRIM] += rt[i];
Jens Axboeb852e7c2012-03-30 10:30:35 +02001320
1321 update_rusage_stat(td);
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001322 td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ];
1323 td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
1324 td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
Jens Axboeb852e7c2012-03-30 10:30:35 +02001325 td->ts.total_run_time = mtime_since(&td->epoch, &tv);
1326 }
1327
1328 show_run_stats();
1329
1330 for_each_td(td, i) {
1331 if (td_read(td) && td->io_bytes[DDIR_READ])
1332 td->ts.runtime[DDIR_READ] -= rt[i];
1333 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1334 td->ts.runtime[DDIR_WRITE] -= rt[i];
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001335 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1336 td->ts.runtime[DDIR_TRIM] -= rt[i];
Jens Axboeb852e7c2012-03-30 10:30:35 +02001337 }
1338
1339 free(rt);
1340 return NULL;
1341}
1342
1343/*
1344 * Called from signal handler. It _should_ be safe to just run this inline
1345 * in the sig handler, but we should be disturbing the system less by just
1346 * creating a thread to do it.
1347 */
1348void show_running_run_stats(void)
1349{
1350 pthread_t thread;
1351
1352 pthread_create(&thread, NULL, __show_running_run_stats, NULL);
1353 pthread_detach(thread);
1354}
1355
Jens Axboe68704082007-01-10 19:56:37 +01001356static inline void add_stat_sample(struct io_stat *is, unsigned long data)
Jens Axboe3c39a372006-06-06 20:56:12 +02001357{
Jens Axboe68704082007-01-10 19:56:37 +01001358 double val = data;
Jens Axboe6660cc62007-03-06 15:48:38 +01001359 double delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001360
Jens Axboe68704082007-01-10 19:56:37 +01001361 if (data > is->max_val)
1362 is->max_val = data;
1363 if (data < is->min_val)
1364 is->min_val = data;
1365
Jens Axboe802ad4a2011-10-05 09:51:58 +02001366 delta = val - is->mean.u.f;
Jens Axboeef11d732007-03-29 15:36:29 +02001367 if (delta) {
Jens Axboe802ad4a2011-10-05 09:51:58 +02001368 is->mean.u.f += delta / (is->samples + 1.0);
1369 is->S.u.f += delta * (val - is->mean.u.f);
Jens Axboeef11d732007-03-29 15:36:29 +02001370 }
Jens Axboe68704082007-01-10 19:56:37 +01001371
Jens Axboe3c39a372006-06-06 20:56:12 +02001372 is->samples++;
1373}
1374
Jens Axboebb3884d2007-01-17 17:23:11 +11001375static void __add_log_sample(struct io_log *iolog, unsigned long val,
Jens Axboe306ddc92009-05-18 13:08:12 +02001376 enum fio_ddir ddir, unsigned int bs,
Jens Axboe2b13e712011-01-19 14:04:16 -07001377 unsigned long t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001378{
Jens Axboe306ddc92009-05-18 13:08:12 +02001379 const int nr_samples = iolog->nr_samples;
1380
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001381 if (!iolog->nr_samples)
1382 iolog->avg_last = t;
1383
Jens Axboe3c39a372006-06-06 20:56:12 +02001384 if (iolog->nr_samples == iolog->max_samples) {
1385 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
1386
1387 iolog->log = realloc(iolog->log, new_size);
1388 iolog->max_samples <<= 1;
1389 }
1390
Jens Axboe306ddc92009-05-18 13:08:12 +02001391 iolog->log[nr_samples].val = val;
Jens Axboe2b13e712011-01-19 14:04:16 -07001392 iolog->log[nr_samples].time = t;
Jens Axboe306ddc92009-05-18 13:08:12 +02001393 iolog->log[nr_samples].ddir = ddir;
1394 iolog->log[nr_samples].bs = bs;
Jens Axboe3c39a372006-06-06 20:56:12 +02001395 iolog->nr_samples++;
1396}
1397
Jens Axboe7fb28d32011-12-01 15:17:24 +01001398static inline void reset_io_stat(struct io_stat *ios)
1399{
1400 ios->max_val = ios->min_val = ios->samples = 0;
1401 ios->mean.u.f = ios->S.u.f = 0;
1402}
1403
Jens Axboebb3884d2007-01-17 17:23:11 +11001404static void add_log_sample(struct thread_data *td, struct io_log *iolog,
Jens Axboe306ddc92009-05-18 13:08:12 +02001405 unsigned long val, enum fio_ddir ddir,
1406 unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001407{
Jens Axboe7fb28d32011-12-01 15:17:24 +01001408 unsigned long elapsed, this_window;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001409
Jens Axboeff58fce2010-08-25 12:02:08 +02001410 if (!ddir_rw(ddir))
1411 return;
1412
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001413 elapsed = mtime_since_now(&td->epoch);
1414
1415 /*
1416 * If no time averaging, just add the log sample.
1417 */
1418 if (!iolog->avg_msec) {
1419 __add_log_sample(iolog, val, ddir, bs, elapsed);
1420 return;
1421 }
1422
1423 /*
1424 * Add the sample. If the time period has passed, then
1425 * add that entry to the log and clear.
1426 */
1427 add_stat_sample(&iolog->avg_window[ddir], val);
1428
Jens Axboe7fb28d32011-12-01 15:17:24 +01001429 /*
1430 * If period hasn't passed, adding the above sample is all we
1431 * need to do.
1432 */
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001433 this_window = elapsed - iolog->avg_last;
1434 if (this_window < iolog->avg_msec)
1435 return;
1436
Jens Axboe7fb28d32011-12-01 15:17:24 +01001437 /*
1438 * Note an entry in the log. Use the mean from the logged samples,
1439 * making sure to properly round up. Only write a log entry if we
1440 * had actual samples done.
1441 */
1442 if (iolog->avg_window[DDIR_READ].samples) {
1443 unsigned long mr;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001444
Jens Axboe7fb28d32011-12-01 15:17:24 +01001445 mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001446 __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed);
Jens Axboe7fb28d32011-12-01 15:17:24 +01001447 }
1448 if (iolog->avg_window[DDIR_WRITE].samples) {
1449 unsigned long mw;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001450
Jens Axboe7fb28d32011-12-01 15:17:24 +01001451 mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50;
1452 __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed);
1453 }
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001454 if (iolog->avg_window[DDIR_TRIM].samples) {
1455 unsigned long mw;
1456
1457 mw = iolog->avg_window[DDIR_TRIM].mean.u.f + 0.50;
1458 __add_log_sample(iolog, mw, DDIR_TRIM, 0, elapsed);
1459 }
1460
Jens Axboe7fb28d32011-12-01 15:17:24 +01001461
1462 reset_io_stat(&iolog->avg_window[DDIR_READ]);
1463 reset_io_stat(&iolog->avg_window[DDIR_WRITE]);
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001464 reset_io_stat(&iolog->avg_window[DDIR_TRIM]);
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001465 iolog->avg_last = elapsed;
Jens Axboebb3884d2007-01-17 17:23:11 +11001466}
1467
Jens Axboe306ddc92009-05-18 13:08:12 +02001468void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001469{
Jens Axboeff58fce2010-08-25 12:02:08 +02001470 struct io_log *iolog;
Jens Axboebb3884d2007-01-17 17:23:11 +11001471
Jens Axboeff58fce2010-08-25 12:02:08 +02001472 if (!ddir_rw(ddir))
1473 return;
1474
1475 iolog = agg_io_log[ddir];
Jens Axboe306ddc92009-05-18 13:08:12 +02001476 __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis());
Jens Axboebb3884d2007-01-17 17:23:11 +11001477}
1478
Yu-ju Hong83349192011-08-13 00:53:44 +02001479static void add_clat_percentile_sample(struct thread_stat *ts,
1480 unsigned long usec, enum fio_ddir ddir)
1481{
1482 unsigned int idx = plat_val_to_idx(usec);
1483 assert(idx < FIO_IO_U_PLAT_NR);
1484
1485 ts->io_u_plat[ddir][idx]++;
1486}
1487
Jens Axboe1e97cce2006-12-05 11:44:16 +01001488void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001489 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001490{
Jens Axboe756867b2007-03-06 15:19:24 +01001491 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001492
Jens Axboeff58fce2010-08-25 12:02:08 +02001493 if (!ddir_rw(ddir))
1494 return;
1495
Jens Axboed85f5112007-06-18 09:41:23 +02001496 add_stat_sample(&ts->clat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001497
Jens Axboe7b9f7332011-10-03 10:06:44 +02001498 if (td->clat_log)
1499 add_log_sample(td, td->clat_log, usec, ddir, bs);
Yu-ju Hong83349192011-08-13 00:53:44 +02001500
1501 if (ts->clat_percentiles)
1502 add_clat_percentile_sample(ts, usec, ddir);
Jens Axboe3c39a372006-06-06 20:56:12 +02001503}
1504
Jens Axboe1e97cce2006-12-05 11:44:16 +01001505void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001506 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001507{
Jens Axboe756867b2007-03-06 15:19:24 +01001508 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001509
Jens Axboeff58fce2010-08-25 12:02:08 +02001510 if (!ddir_rw(ddir))
1511 return;
1512
Jens Axboed85f5112007-06-18 09:41:23 +02001513 add_stat_sample(&ts->slat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001514
Jens Axboe7b9f7332011-10-03 10:06:44 +02001515 if (td->slat_log)
1516 add_log_sample(td, td->slat_log, usec, ddir, bs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001517}
1518
Jens Axboe02af0982010-06-24 09:59:34 +02001519void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
1520 unsigned long usec, unsigned int bs)
1521{
1522 struct thread_stat *ts = &td->ts;
1523
Jens Axboeff58fce2010-08-25 12:02:08 +02001524 if (!ddir_rw(ddir))
1525 return;
1526
Jens Axboe02af0982010-06-24 09:59:34 +02001527 add_stat_sample(&ts->lat_stat[ddir], usec);
1528
Jens Axboe7b9f7332011-10-03 10:06:44 +02001529 if (td->lat_log)
1530 add_log_sample(td, td->lat_log, usec, ddir, bs);
Jens Axboe02af0982010-06-24 09:59:34 +02001531}
1532
Jens Axboe306ddc92009-05-18 13:08:12 +02001533void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
Jens Axboe1e97cce2006-12-05 11:44:16 +01001534 struct timeval *t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001535{
Jens Axboe756867b2007-03-06 15:19:24 +01001536 struct thread_stat *ts = &td->ts;
Jens Axboeff58fce2010-08-25 12:02:08 +02001537 unsigned long spent, rate;
Jens Axboe3c39a372006-06-06 20:56:12 +02001538
Jens Axboeff58fce2010-08-25 12:02:08 +02001539 if (!ddir_rw(ddir))
1540 return;
1541
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001542 spent = mtime_since(&td->bw_sample_time, t);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001543 if (spent < td->o.bw_avg_time)
Jens Axboe3c39a372006-06-06 20:56:12 +02001544 return;
Jens Axboe9602d8d2012-02-20 20:19:28 +01001545
1546 /*
Josh Carter5daa4eb2012-02-20 10:12:22 +01001547 * Compute both read and write rates for the interval.
1548 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001549 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
Josh Carter5daa4eb2012-02-20 10:12:22 +01001550 uint64_t delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001551
Josh Carter5daa4eb2012-02-20 10:12:22 +01001552 delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir];
1553 if (!delta)
1554 continue; /* No entries for interval */
Jens Axboe3c39a372006-06-06 20:56:12 +02001555
Josh Carter5daa4eb2012-02-20 10:12:22 +01001556 rate = delta * 1000 / spent / 1024;
1557 add_stat_sample(&ts->bw_stat[ddir], rate);
1558
1559 if (td->bw_log)
1560 add_log_sample(td, td->bw_log, rate, ddir, bs);
1561
1562 td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
1563 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001564
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001565 fio_gettime(&td->bw_sample_time, NULL);
Jens Axboe3c39a372006-06-06 20:56:12 +02001566}
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001567
1568void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,
1569 struct timeval *t)
1570{
1571 struct thread_stat *ts = &td->ts;
1572 unsigned long spent, iops;
1573
1574 if (!ddir_rw(ddir))
1575 return;
1576
1577 spent = mtime_since(&td->iops_sample_time, t);
1578 if (spent < td->o.iops_avg_time)
1579 return;
1580
Jens Axboe9602d8d2012-02-20 20:19:28 +01001581 /*
1582 * Compute both read and write rates for the interval.
1583 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001584 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
Jens Axboe9602d8d2012-02-20 20:19:28 +01001585 uint64_t delta;
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001586
Jens Axboe9602d8d2012-02-20 20:19:28 +01001587 delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir];
1588 if (!delta)
1589 continue; /* No entries for interval */
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001590
Jens Axboe9602d8d2012-02-20 20:19:28 +01001591 iops = (delta * 1000) / spent;
1592 add_stat_sample(&ts->iops_stat[ddir], iops);
1593
1594 if (td->iops_log)
1595 add_log_sample(td, td->iops_log, iops, ddir, 0);
1596
Jens Axboe421f4a82012-02-28 08:20:26 +01001597 td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
Jens Axboe9602d8d2012-02-20 20:19:28 +01001598 }
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001599
1600 fio_gettime(&td->iops_sample_time, NULL);
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001601}