blob: 66bea0a59a779340fa6f2fc747cb6d35a2a27ee4 [file] [log] [blame]
Jens Axboe3c39a372006-06-06 20:56:12 +02001#include <stdio.h>
2#include <string.h>
3#include <sys/time.h>
4#include <sys/types.h>
Jens Axboe5c4e1db2006-06-07 14:17:08 +02005#include <sys/stat.h>
Jens Axboe3c39a372006-06-06 20:56:12 +02006#include <dirent.h>
7#include <libgen.h>
8#include <math.h>
9
10#include "fio.h"
Jens Axboe7c9b1bc2009-06-03 09:25:57 +020011#include "diskutil.h"
Jens Axboec7c6cb42011-10-13 14:12:40 +020012#include "lib/ieee754.h"
Shaohua Licc372b12012-09-17 09:12:18 +020013#include "json.h"
Jens Axboe44404c52013-01-24 14:20:09 -070014#include "lib/getrusage.h"
Huadong Liuf2a2ce02013-01-30 13:22:24 +010015#include "idletime.h"
Jens Axboe3c39a372006-06-06 20:56:12 +020016
Jens Axboe3c39a372006-06-06 20:56:12 +020017void update_rusage_stat(struct thread_data *td)
18{
Jens Axboe756867b2007-03-06 15:19:24 +010019 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +020020
Jens Axboe44404c52013-01-24 14:20:09 -070021 fio_getrusage(&td->ru_end);
Jens Axboec8aaba12011-10-03 12:14:19 +020022 ts->usr_time += mtime_since(&td->ru_start.ru_utime,
23 &td->ru_end.ru_utime);
24 ts->sys_time += mtime_since(&td->ru_start.ru_stime,
25 &td->ru_end.ru_stime);
26 ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw
27 - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw);
28 ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt;
29 ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010030
Jens Axboec8aaba12011-10-03 12:14:19 +020031 memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end));
Jens Axboe3c39a372006-06-06 20:56:12 +020032}
33
Yu-ju Hong83349192011-08-13 00:53:44 +020034/*
35 * Given a latency, return the index of the corresponding bucket in
36 * the structure tracking percentiles.
37 *
38 * (1) find the group (and error bits) that the value (latency)
39 * belongs to by looking at its MSB. (2) find the bucket number in the
40 * group by looking at the index bits.
41 *
42 */
43static unsigned int plat_val_to_idx(unsigned int val)
44{
45 unsigned int msb, error_bits, base, offset, idx;
46
47 /* Find MSB starting from bit 0 */
48 if (val == 0)
49 msb = 0;
50 else
51 msb = (sizeof(val)*8) - __builtin_clz(val) - 1;
52
Jens Axboe716050f2011-08-16 08:43:45 +020053 /*
54 * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
55 * all bits of the sample as index
56 */
Yu-ju Hong83349192011-08-13 00:53:44 +020057 if (msb <= FIO_IO_U_PLAT_BITS)
58 return val;
59
60 /* Compute the number of error bits to discard*/
61 error_bits = msb - FIO_IO_U_PLAT_BITS;
62
63 /* Compute the number of buckets before the group */
64 base = (error_bits + 1) << FIO_IO_U_PLAT_BITS;
65
Jens Axboe716050f2011-08-16 08:43:45 +020066 /*
67 * Discard the error bits and apply the mask to find the
Jens Axboe3c3ed072012-03-27 09:12:39 +020068 * index for the buckets in the group
Jens Axboe716050f2011-08-16 08:43:45 +020069 */
Yu-ju Hong83349192011-08-13 00:53:44 +020070 offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits);
71
72 /* Make sure the index does not exceed (array size - 1) */
Jens Axboe3c3ed072012-03-27 09:12:39 +020073 idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1) ?
Yu-ju Hong83349192011-08-13 00:53:44 +020074 (base + offset) : (FIO_IO_U_PLAT_NR - 1);
75
76 return idx;
77}
78
79/*
80 * Convert the given index of the bucket array to the value
81 * represented by the bucket
82 */
83static unsigned int plat_idx_to_val(unsigned int idx)
84{
85 unsigned int error_bits, k, base;
86
87 assert(idx < FIO_IO_U_PLAT_NR);
88
89 /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
90 * all bits of the sample as index */
Jens Axboe3c3ed072012-03-27 09:12:39 +020091 if (idx < (FIO_IO_U_PLAT_VAL << 1))
Yu-ju Hong83349192011-08-13 00:53:44 +020092 return idx;
93
94 /* Find the group and compute the minimum value of that group */
Jens Axboe3c3ed072012-03-27 09:12:39 +020095 error_bits = (idx >> FIO_IO_U_PLAT_BITS) - 1;
Yu-ju Hong83349192011-08-13 00:53:44 +020096 base = 1 << (error_bits + FIO_IO_U_PLAT_BITS);
97
98 /* Find its bucket number of the group */
99 k = idx % FIO_IO_U_PLAT_VAL;
100
101 /* Return the mean of the range of the bucket */
102 return base + ((k + 0.5) * (1 << error_bits));
103}
104
105static int double_cmp(const void *a, const void *b)
106{
Jens Axboe802ad4a2011-10-05 09:51:58 +0200107 const fio_fp64_t fa = *(const fio_fp64_t *) a;
108 const fio_fp64_t fb = *(const fio_fp64_t *) b;
Yu-ju Hong83349192011-08-13 00:53:44 +0200109 int cmp = 0;
110
Jens Axboe802ad4a2011-10-05 09:51:58 +0200111 if (fa.u.f > fb.u.f)
Yu-ju Hong83349192011-08-13 00:53:44 +0200112 cmp = 1;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200113 else if (fa.u.f < fb.u.f)
Yu-ju Hong83349192011-08-13 00:53:44 +0200114 cmp = -1;
115
116 return cmp;
117}
118
Jens Axboea2697902012-03-05 16:43:49 +0100119unsigned int calc_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
120 fio_fp64_t *plist, unsigned int **output,
121 unsigned int *maxv, unsigned int *minv)
Yu-ju Hong83349192011-08-13 00:53:44 +0200122{
123 unsigned long sum = 0;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200124 unsigned int len, i, j = 0;
125 unsigned int oval_len = 0;
126 unsigned int *ovals = NULL;
127 int is_last;
128
129 *minv = -1U;
130 *maxv = 0;
Yu-ju Hong83349192011-08-13 00:53:44 +0200131
Jens Axboe802ad4a2011-10-05 09:51:58 +0200132 len = 0;
133 while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0)
134 len++;
Jens Axboe716050f2011-08-16 08:43:45 +0200135
Jens Axboe351de8d2011-10-12 21:03:45 +0200136 if (!len)
Jens Axboe1db92cb2011-10-13 13:43:36 +0200137 return 0;
Jens Axboe351de8d2011-10-12 21:03:45 +0200138
Jens Axboe716050f2011-08-16 08:43:45 +0200139 /*
Jens Axboe802ad4a2011-10-05 09:51:58 +0200140 * Sort the percentile list. Note that it may already be sorted if
141 * we are using the default values, but since it's a short list this
142 * isn't a worry. Also note that this does not work for NaN values.
Jens Axboe716050f2011-08-16 08:43:45 +0200143 */
Jens Axboe802ad4a2011-10-05 09:51:58 +0200144 if (len > 1)
Jens Axboe3c3ed072012-03-27 09:12:39 +0200145 qsort((void *)plist, len, sizeof(plist[0]), double_cmp);
Yu-ju Hong83349192011-08-13 00:53:44 +0200146
Jens Axboe4f6f8292011-10-13 09:28:21 +0200147 /*
148 * Calculate bucket values, note down max and min values
149 */
Jens Axboe07511a62011-10-13 12:00:24 +0200150 is_last = 0;
151 for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) {
Yu-ju Hong83349192011-08-13 00:53:44 +0200152 sum += io_u_plat[i];
Jens Axboe802ad4a2011-10-05 09:51:58 +0200153 while (sum >= (plist[j].u.f / 100.0 * nr)) {
154 assert(plist[j].u.f <= 100.0);
Yu-ju Hong83349192011-08-13 00:53:44 +0200155
Jens Axboe4f6f8292011-10-13 09:28:21 +0200156 if (j == oval_len) {
157 oval_len += 100;
158 ovals = realloc(ovals, oval_len * sizeof(unsigned int));
159 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200160
Jens Axboe4f6f8292011-10-13 09:28:21 +0200161 ovals[j] = plat_idx_to_val(i);
Jens Axboe1db92cb2011-10-13 13:43:36 +0200162 if (ovals[j] < *minv)
163 *minv = ovals[j];
164 if (ovals[j] > *maxv)
165 *maxv = ovals[j];
Jens Axboe07511a62011-10-13 12:00:24 +0200166
167 is_last = (j == len - 1);
168 if (is_last)
169 break;
170
Jens Axboe4f6f8292011-10-13 09:28:21 +0200171 j++;
Yu-ju Hong83349192011-08-13 00:53:44 +0200172 }
173 }
Jens Axboe4f6f8292011-10-13 09:28:21 +0200174
Jens Axboe1db92cb2011-10-13 13:43:36 +0200175 *output = ovals;
176 return len;
177}
178
179/*
180 * Find and display the p-th percentile of clat
181 */
182static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
Jens Axboe3dc1e5b2013-02-07 12:56:09 +0100183 fio_fp64_t *plist, unsigned int precision)
Jens Axboe1db92cb2011-10-13 13:43:36 +0200184{
185 unsigned int len, j = 0, minv, maxv;
186 unsigned int *ovals;
Jens Axboeeef02442013-02-06 08:51:57 +0100187 int is_last, per_line, scale_down;
188 char fmt[32];
Jens Axboe1db92cb2011-10-13 13:43:36 +0200189
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
Jens Axboe3dc1e5b2013-02-07 12:56:09 +0100206 snprintf(fmt, sizeof(fmt), "%%1.%uf", precision);
Jens Axboeeef02442013-02-06 08:51:57 +0100207 per_line = (80 - 7) / (precision + 14);
Jens Axboe619adf92013-02-06 08:46:55 +0100208
Jens Axboe4f6f8292011-10-13 09:28:21 +0200209 for (j = 0; j < len; j++) {
Jens Axboe619adf92013-02-06 08:46:55 +0100210 char fbuf[16], *ptr = fbuf;
Jens Axboe4f6f8292011-10-13 09:28:21 +0200211
212 /* for formatting */
Jens Axboeeef02442013-02-06 08:51:57 +0100213 if (j != 0 && (j % per_line) == 0)
Jens Axboe4f6f8292011-10-13 09:28:21 +0200214 log_info(" |");
215
216 /* end of the list */
217 is_last = (j == len - 1);
218
219 if (plist[j].u.f < 10.0)
Jens Axboe619adf92013-02-06 08:46:55 +0100220 ptr += sprintf(fbuf, " ");
221
Jens Axboeeef02442013-02-06 08:51:57 +0100222 snprintf(ptr, sizeof(fbuf), fmt, plist[j].u.f);
Jens Axboe4f6f8292011-10-13 09:28:21 +0200223
224 if (scale_down)
225 ovals[j] = (ovals[j] + 999) / 1000;
226
227 log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ',');
228
229 if (is_last)
230 break;
231
Jens Axboeeef02442013-02-06 08:51:57 +0100232 if ((j % per_line) == per_line - 1) /* for formatting */
Jens Axboe4f6f8292011-10-13 09:28:21 +0200233 log_info("\n");
234 }
235
Jens Axboe1db92cb2011-10-13 13:43:36 +0200236out:
Jens Axboe4f6f8292011-10-13 09:28:21 +0200237 if (ovals)
238 free(ovals);
Yu-ju Hong83349192011-08-13 00:53:44 +0200239}
240
Jens Axboeb29ad562012-03-05 13:08:51 +0100241int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
242 double *mean, double *dev)
Jens Axboe3c39a372006-06-06 20:56:12 +0200243{
Jens Axboe68704082007-01-10 19:56:37 +0100244 double n = is->samples;
Jens Axboe3c39a372006-06-06 20:56:12 +0200245
246 if (is->samples == 0)
247 return 0;
248
249 *min = is->min_val;
250 *max = is->max_val;
251
252 n = (double) is->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200253 *mean = is->mean.u.f;
Jens Axboe3c39a372006-06-06 20:56:12 +0200254
Jens Axboe68704082007-01-10 19:56:37 +0100255 if (n > 1.0)
Jens Axboe802ad4a2011-10-05 09:51:58 +0200256 *dev = sqrt(is->S.u.f / (n - 1.0));
Jens Axboeef9c5c42007-01-03 14:21:13 +0100257 else
Jens Axboe4b43f542007-07-19 21:38:35 +0200258 *dev = 0;
Jens Axboeef9c5c42007-01-03 14:21:13 +0100259
Jens Axboe3c39a372006-06-06 20:56:12 +0200260 return 1;
261}
262
Jens Axboea64e88d2011-10-03 14:20:01 +0200263void show_group_stats(struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200264{
Jens Axboedbe11252007-02-11 00:19:51 +0100265 char *p1, *p2, *p3, *p4;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200266 const char *ddir_str[] = { " READ", " WRITE" , " TRIM"};
Jens Axboedbe11252007-02-11 00:19:51 +0100267 int i;
268
Jens Axboe7e1773b2011-10-14 12:47:56 +0200269 log_info("\nRun status group %d (all jobs):\n", rs->groupid);
Jens Axboe3c39a372006-06-06 20:56:12 +0200270
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200271 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200272 const int i2p = is_power_of_2(rs->kb_base);
273
Jens Axboedbe11252007-02-11 00:19:51 +0100274 if (!rs->max_run[i])
275 continue;
276
Steven Noonan73798eb2013-04-05 16:57:38 -0700277 p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p, 8);
Steven Noonanad705bc2013-04-08 15:05:25 -0700278 p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p, rs->unit_base);
279 p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p, rs->unit_base);
280 p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p, rs->unit_base);
Jens Axboedbe11252007-02-11 00:19:51 +0100281
Steven Noonan73798eb2013-04-05 16:57:38 -0700282 log_info("%s: io=%s, aggrb=%s/s, minb=%s/s, maxb=%s/s,"
Jens Axboe771e58b2013-01-30 12:56:23 +0100283 " mint=%llumsec, maxt=%llumsec\n",
284 rs->unified_rw_rep ? " MIXED" : ddir_str[i],
285 p1, p2, p3, p4, rs->min_run[i], rs->max_run[i]);
Jens Axboedbe11252007-02-11 00:19:51 +0100286
287 free(p1);
288 free(p2);
289 free(p3);
290 free(p4);
291 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200292}
293
Jens Axboe2e331012012-03-05 22:07:54 +0100294void stat_calc_dist(unsigned int *map, unsigned long total, double *io_u_dist)
Jens Axboe22708902007-03-06 17:05:32 +0100295{
296 int i;
297
298 /*
299 * Do depth distribution calculations
300 */
301 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200302 if (total) {
303 io_u_dist[i] = (double) map[i] / (double) total;
304 io_u_dist[i] *= 100.0;
305 if (io_u_dist[i] < 0.1 && map[i])
306 io_u_dist[i] = 0.1;
307 } else
308 io_u_dist[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100309 }
310}
311
Jens Axboe04a0fea2007-06-19 12:48:41 +0200312static void stat_calc_lat(struct thread_stat *ts, double *dst,
313 unsigned int *src, int nr)
Jens Axboe22708902007-03-06 17:05:32 +0100314{
Jens Axboed79db122012-09-24 08:51:24 +0200315 unsigned long total = ddir_rw_sum(ts->total_io_u);
Jens Axboe22708902007-03-06 17:05:32 +0100316 int i;
317
318 /*
319 * Do latency distribution calculations
320 */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200321 for (i = 0; i < nr; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200322 if (total) {
323 dst[i] = (double) src[i] / (double) total;
324 dst[i] *= 100.0;
325 if (dst[i] < 0.01 && src[i])
326 dst[i] = 0.01;
327 } else
328 dst[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100329 }
330}
331
Jens Axboee5bd1342012-03-05 21:38:12 +0100332void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200333{
334 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
335}
336
Jens Axboee5bd1342012-03-05 21:38:12 +0100337void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200338{
339 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
340}
341
Jens Axboeb29ad562012-03-05 13:08:51 +0100342static void display_lat(const char *name, unsigned long min, unsigned long max,
343 double mean, double dev)
Jens Axboeea2accc2007-06-19 09:48:44 +0200344{
Jens Axboeb29ad562012-03-05 13:08:51 +0100345 const char *base = "(usec)";
346 char *minp, *maxp;
Jens Axboeea2accc2007-06-19 09:48:44 +0200347
Jens Axboeb29ad562012-03-05 13:08:51 +0100348 if (!usec_to_msec(&min, &max, &mean, &dev))
349 base = "(msec)";
350
Jens Axboe22f80452013-04-09 20:29:16 +0200351 minp = num2str(min, 6, 1, 0, 0);
352 maxp = num2str(max, 6, 1, 0, 0);
Jens Axboeb29ad562012-03-05 13:08:51 +0100353
354 log_info(" %s %s: min=%s, max=%s, avg=%5.02f,"
355 " stdev=%5.02f\n", name, base, minp, maxp, mean, dev);
356
357 free(minp);
358 free(maxp);
Jens Axboeea2accc2007-06-19 09:48:44 +0200359}
360
Jens Axboe756867b2007-03-06 15:19:24 +0100361static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
Jens Axboe3c39a372006-06-06 20:56:12 +0200362 int ddir)
363{
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200364 const char *ddir_str[] = { "read ", "write", "trim" };
Jens Axboe8879fd12009-04-20 10:06:02 +0200365 unsigned long min, max, runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100366 unsigned long long bw, iops;
Jens Axboe3c39a372006-06-06 20:56:12 +0200367 double mean, dev;
Jens Axboeb3605062007-03-12 14:19:47 +0100368 char *io_p, *bw_p, *iops_p;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200369 int i2p;
Jens Axboe3c39a372006-06-06 20:56:12 +0200370
Jens Axboeff58fce2010-08-25 12:02:08 +0200371 assert(ddir_rw(ddir));
372
Jens Axboe756867b2007-03-06 15:19:24 +0100373 if (!ts->runtime[ddir])
Jens Axboe3c39a372006-06-06 20:56:12 +0200374 return;
375
Jens Axboe90fef2d2009-07-17 22:33:32 +0200376 i2p = is_power_of_2(rs->kb_base);
Jens Axboe8879fd12009-04-20 10:06:02 +0200377 runt = ts->runtime[ddir];
378
379 bw = (1000 * ts->io_bytes[ddir]) / runt;
Steven Noonan73798eb2013-04-05 16:57:38 -0700380 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p, 8);
Steven Noonanad705bc2013-04-08 15:05:25 -0700381 bw_p = num2str(bw, 6, 1, i2p, ts->unit_base);
Jens Axboe8879fd12009-04-20 10:06:02 +0200382
Bruce Cran0aacc502011-07-09 08:19:53 +0200383 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
Steven Noonan73798eb2013-04-05 16:57:38 -0700384 iops_p = num2str(iops, 6, 1, 0, 0);
Jens Axboedbe11252007-02-11 00:19:51 +0100385
Steven Noonan73798eb2013-04-05 16:57:38 -0700386 log_info(" %s: io=%s, bw=%s/s, iops=%s, runt=%6llumsec\n",
Jens Axboe771e58b2013-01-30 12:56:23 +0100387 rs->unified_rw_rep ? "mixed" : ddir_str[ddir],
388 io_p, bw_p, iops_p, ts->runtime[ddir]);
Jens Axboedbe11252007-02-11 00:19:51 +0100389
390 free(io_p);
391 free(bw_p);
Jens Axboeb3605062007-03-12 14:19:47 +0100392 free(iops_p);
Jens Axboe3c39a372006-06-06 20:56:12 +0200393
Jens Axboeb29ad562012-03-05 13:08:51 +0100394 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
395 display_lat("slat", min, max, mean, dev);
396 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
397 display_lat("clat", min, max, mean, dev);
398 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
399 display_lat(" lat", min, max, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200400
Yu-ju Hong83349192011-08-13 00:53:44 +0200401 if (ts->clat_percentiles) {
402 show_clat_percentiles(ts->io_u_plat[ddir],
403 ts->clat_stat[ddir].samples,
Vincent Kang Fu435d1952013-02-06 08:43:40 +0100404 ts->percentile_list,
405 ts->percentile_precision);
Yu-ju Hong83349192011-08-13 00:53:44 +0200406 }
Jens Axboe079ad092007-02-20 13:58:20 +0100407 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Steven Noonan142c7f22013-04-08 15:25:54 -0700408 double p_of_agg = 100.0, fkb_base = (double)rs->kb_base;
Steven Noonand6869902013-04-08 15:40:13 -0700409 const char *bw_str = (rs->unit_base == 1 ? "Kbit" : "KB");
410
411 if (rs->unit_base == 1) {
412 min *= 8.0;
413 max *= 8.0;
414 mean *= 8.0;
415 dev *= 8.0;
416 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200417
Jens Axboe2f2c6922012-02-07 16:42:43 +0100418 if (rs->agg[ddir]) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100419 p_of_agg = mean * 100 / (double) rs->agg[ddir];
420 if (p_of_agg > 100.0)
421 p_of_agg = 100.0;
422 }
Jens Axboeb7017e32011-10-14 09:30:01 +0200423
Steven Noonan142c7f22013-04-08 15:25:54 -0700424 if (mean > fkb_base * fkb_base) {
425 min /= fkb_base;
426 max /= fkb_base;
427 mean /= fkb_base;
428 dev /= fkb_base;
Steven Noonand6869902013-04-08 15:40:13 -0700429 bw_str = (rs->unit_base == 1 ? "Mbit" : "MB");
Jens Axboeb7017e32011-10-14 09:30:01 +0200430 }
431
Steven Noonand6869902013-04-08 15:40:13 -0700432 log_info(" bw (%-4s/s): min=%5lu, max=%5lu, per=%3.2f%%,"
Jens Axboeb7017e32011-10-14 09:30:01 +0200433 " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max,
434 p_of_agg, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200435 }
436}
437
Jens Axboe7e1773b2011-10-14 12:47:56 +0200438static int show_lat(double *io_u_lat, int nr, const char **ranges,
439 const char *msg)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200440{
Jens Axboe7e1773b2011-10-14 12:47:56 +0200441 int new_line = 1, i, line = 0, shown = 0;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200442
443 for (i = 0; i < nr; i++) {
444 if (io_u_lat[i] <= 0.0)
445 continue;
Jens Axboe7e1773b2011-10-14 12:47:56 +0200446 shown = 1;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200447 if (new_line) {
Jens Axboe4539ed72007-07-23 14:21:17 +0200448 if (line)
449 log_info("\n");
Jens Axboe7e1773b2011-10-14 12:47:56 +0200450 log_info(" lat (%s) : ", msg);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200451 new_line = 0;
452 line = 0;
453 }
454 if (line)
455 log_info(", ");
456 log_info("%s%3.2f%%", ranges[i], io_u_lat[i]);
457 line++;
458 if (line == 5)
459 new_line = 1;
460 }
Jens Axboe7e1773b2011-10-14 12:47:56 +0200461
462 if (shown)
463 log_info("\n");
464
465 return shown;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200466}
467
468static void show_lat_u(double *io_u_lat_u)
469{
470 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
471 "250=", "500=", "750=", "1000=", };
472
473 show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec");
474}
475
476static void show_lat_m(double *io_u_lat_m)
477{
478 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
479 "250=", "500=", "750=", "1000=", "2000=",
480 ">=2000=", };
481
482 show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec");
483}
484
Jens Axboec551f652012-03-05 20:49:10 +0100485static void show_latencies(struct thread_stat *ts)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200486{
Jens Axboec551f652012-03-05 20:49:10 +0100487 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
488 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
489
Jens Axboe5a189882012-03-05 14:08:34 +0100490 stat_calc_lat_u(ts, io_u_lat_u);
491 stat_calc_lat_m(ts, io_u_lat_m);
492
Jens Axboe04a0fea2007-06-19 12:48:41 +0200493 show_lat_u(io_u_lat_u);
494 show_lat_m(io_u_lat_m);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200495}
496
Jens Axboea64e88d2011-10-03 14:20:01 +0200497void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200498{
499 double usr_cpu, sys_cpu;
Jens Axboe69008992006-11-24 13:12:56 +0100500 unsigned long runtime;
Jens Axboe71619dc2007-01-13 23:56:33 +0100501 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe57a64322012-06-14 15:11:15 +0200502 time_t time_p;
503 char time_buf[64];
Jens Axboe3c39a372006-06-06 20:56:12 +0200504
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200505 if (!(ts->io_bytes[DDIR_READ] + ts->io_bytes[DDIR_WRITE] +
506 ts->io_bytes[DDIR_TRIM]) && !(ts->total_io_u[DDIR_READ] +
507 ts->total_io_u[DDIR_WRITE] + ts->total_io_u[DDIR_TRIM]))
Jens Axboe3c39a372006-06-06 20:56:12 +0200508 return;
509
Jens Axboe57a64322012-06-14 15:11:15 +0200510 time(&time_p);
Saurabh De45054cb2012-10-09 14:46:24 -0600511 os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf));
Jens Axboe57a64322012-06-14 15:11:15 +0200512
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100513 if (!ts->error) {
Jens Axboe57a64322012-06-14 15:11:15 +0200514 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100515 ts->name, ts->groupid, ts->members,
Jens Axboe57a64322012-06-14 15:11:15 +0200516 ts->error, (int) ts->pid, time_buf);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100517 } else {
Jens Axboe57a64322012-06-14 15:11:15 +0200518 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100519 ts->name, ts->groupid, ts->members,
Jens Axboe57a64322012-06-14 15:11:15 +0200520 ts->error, ts->verror, (int) ts->pid,
521 time_buf);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100522 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200523
Jens Axboe259e47d2011-10-13 21:05:59 +0200524 if (strlen(ts->description))
Jens Axboe6d861442007-03-15 09:22:23 +0100525 log_info(" Description : [%s]\n", ts->description);
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100526
Jens Axboe756867b2007-03-06 15:19:24 +0100527 if (ts->io_bytes[DDIR_READ])
528 show_ddir_status(rs, ts, DDIR_READ);
529 if (ts->io_bytes[DDIR_WRITE])
530 show_ddir_status(rs, ts, DDIR_WRITE);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200531 if (ts->io_bytes[DDIR_TRIM])
532 show_ddir_status(rs, ts, DDIR_TRIM);
Jens Axboe3c39a372006-06-06 20:56:12 +0200533
Jens Axboec551f652012-03-05 20:49:10 +0100534 show_latencies(ts);
Jens Axboe7e1773b2011-10-14 12:47:56 +0200535
Jens Axboe756867b2007-03-06 15:19:24 +0100536 runtime = ts->total_run_time;
Jens Axboe69008992006-11-24 13:12:56 +0100537 if (runtime) {
Jens Axboe1e97cce2006-12-05 11:44:16 +0100538 double runt = (double) runtime;
Jens Axboe3c39a372006-06-06 20:56:12 +0200539
Jens Axboe756867b2007-03-06 15:19:24 +0100540 usr_cpu = (double) ts->usr_time * 100 / runt;
541 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboe3c39a372006-06-06 20:56:12 +0200542 } else {
543 usr_cpu = 0;
544 sys_cpu = 0;
545 }
546
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100547 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu,"
548 " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf);
Jens Axboe71619dc2007-01-13 23:56:33 +0100549
Jens Axboed79db122012-09-24 08:51:24 +0200550 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100551 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%,"
552 " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
553 io_u_dist[1], io_u_dist[2],
554 io_u_dist[3], io_u_dist[4],
555 io_u_dist[5], io_u_dist[6]);
Jens Axboe838bc702008-05-22 13:08:23 +0200556
557 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
558 log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
559 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
560 io_u_dist[1], io_u_dist[2],
561 io_u_dist[3], io_u_dist[4],
562 io_u_dist[5], io_u_dist[6]);
563 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
564 log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
565 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
566 io_u_dist[1], io_u_dist[2],
567 io_u_dist[3], io_u_dist[4],
568 io_u_dist[5], io_u_dist[6]);
Jens Axboe7e1773b2011-10-14 12:47:56 +0200569 log_info(" issued : total=r=%lu/w=%lu/d=%lu,"
570 " short=r=%lu/w=%lu/d=%lu\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100571 ts->total_io_u[0], ts->total_io_u[1],
Jens Axboe0d29de82010-09-01 13:54:15 +0200572 ts->total_io_u[2],
573 ts->short_io_u[0], ts->short_io_u[1],
574 ts->short_io_u[2]);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200575 if (ts->continue_on_error) {
Jens Axboe1ec99ee2009-06-15 12:37:30 +0200576 log_info(" errors : total=%lu, first_error=%d/<%s>\n",
577 ts->total_err_count,
578 ts->first_error,
579 strerror(ts->first_error));
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200580 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200581}
582
Jens Axboe756867b2007-03-06 15:19:24 +0100583static void show_ddir_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200584 struct group_run_stats *rs, int ddir)
585{
586 unsigned long min, max;
Jens Axboe312b4af2011-10-13 13:11:42 +0200587 unsigned long long bw, iops;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200588 unsigned int *ovals = NULL;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200589 double mean, dev;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200590 unsigned int len, minv, maxv;
591 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200592
Jens Axboeff58fce2010-08-25 12:02:08 +0200593 assert(ddir_rw(ddir));
594
Jens Axboe312b4af2011-10-13 13:11:42 +0200595 iops = bw = 0;
596 if (ts->runtime[ddir]) {
597 uint64_t runt = ts->runtime[ddir];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200598
Jens Axboe033bbb52012-05-07 09:46:40 +0200599 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
Jens Axboe312b4af2011-10-13 13:11:42 +0200600 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
601 }
602
603 log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops,
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100604 ts->runtime[ddir]);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200605
Jens Axboe079ad092007-02-20 13:58:20 +0100606 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100607 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200608 else
Jens Axboe6d861442007-03-15 09:22:23 +0100609 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200610
Jens Axboe079ad092007-02-20 13:58:20 +0100611 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100612 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200613 else
Jens Axboe6d861442007-03-15 09:22:23 +0100614 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200615
Jens Axboe1db92cb2011-10-13 13:43:36 +0200616 if (ts->clat_percentiles) {
617 len = calc_clat_percentiles(ts->io_u_plat[ddir],
618 ts->clat_stat[ddir].samples,
619 ts->percentile_list, &ovals, &maxv,
620 &minv);
621 } else
622 len = 0;
623
624 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
625 if (i >= len) {
626 log_info(";0%%=0");
627 continue;
628 }
Vincent Kang Fu435d1952013-02-06 08:43:40 +0100629 log_info(";%f%%=%u", ts->percentile_list[i].u.f, ovals[i]);
Jens Axboe1db92cb2011-10-13 13:43:36 +0200630 }
Keplar kramer2341a372011-10-19 21:31:27 +0200631
632 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
633 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
634 else
635 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
636
Jens Axboe1db92cb2011-10-13 13:43:36 +0200637 if (ovals)
638 free(ovals);
639
Jens Axboe079ad092007-02-20 13:58:20 +0100640 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100641 double p_of_agg = 100.0;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200642
Jens Axboe19d3e962012-02-07 12:27:28 +0100643 if (rs->agg[ddir]) {
644 p_of_agg = mean * 100 / (double) rs->agg[ddir];
645 if (p_of_agg > 100.0)
646 p_of_agg = 100.0;
647 }
648
Jens Axboe6d861442007-03-15 09:22:23 +0100649 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200650 } else
Jens Axboe6d861442007-03-15 09:22:23 +0100651 log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200652}
653
Shaohua Licc372b12012-09-17 09:12:18 +0200654static void add_ddir_status_json(struct thread_stat *ts,
655 struct group_run_stats *rs, int ddir, struct json_object *parent)
656{
657 unsigned long min, max;
658 unsigned long long bw, iops;
659 unsigned int *ovals = NULL;
660 double mean, dev;
661 unsigned int len, minv, maxv;
662 int i;
663 const char *ddirname[] = {"read", "write", "trim"};
664 struct json_object *dir_object, *tmp_object, *percentile_object;
665 char buf[120];
666 double p_of_agg = 100.0;
667
668 assert(ddir_rw(ddir));
669
Jens Axboe771e58b2013-01-30 12:56:23 +0100670 if (ts->unified_rw_rep && ddir != DDIR_READ)
671 return;
672
Shaohua Licc372b12012-09-17 09:12:18 +0200673 dir_object = json_create_object();
Jens Axboe771e58b2013-01-30 12:56:23 +0100674 json_object_add_value_object(parent,
675 ts->unified_rw_rep ? "mixed" : ddirname[ddir], dir_object);
Shaohua Licc372b12012-09-17 09:12:18 +0200676
677 iops = bw = 0;
678 if (ts->runtime[ddir]) {
679 uint64_t runt = ts->runtime[ddir];
680
681 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
682 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
683 }
684
685 json_object_add_value_int(dir_object, "io_bytes", ts->io_bytes[ddir] >> 10);
686 json_object_add_value_int(dir_object, "bw", bw);
687 json_object_add_value_int(dir_object, "iops", iops);
688 json_object_add_value_int(dir_object, "runtime", ts->runtime[ddir]);
689
690 if (!calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
691 min = max = 0;
692 mean = dev = 0.0;
693 }
694 tmp_object = json_create_object();
695 json_object_add_value_object(dir_object, "slat", tmp_object);
696 json_object_add_value_int(tmp_object, "min", min);
697 json_object_add_value_int(tmp_object, "max", max);
698 json_object_add_value_float(tmp_object, "mean", mean);
699 json_object_add_value_float(tmp_object, "stddev", dev);
700
701 if (!calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
702 min = max = 0;
703 mean = dev = 0.0;
704 }
705 tmp_object = json_create_object();
706 json_object_add_value_object(dir_object, "clat", tmp_object);
707 json_object_add_value_int(tmp_object, "min", min);
708 json_object_add_value_int(tmp_object, "max", max);
709 json_object_add_value_float(tmp_object, "mean", mean);
710 json_object_add_value_float(tmp_object, "stddev", dev);
711
712 if (ts->clat_percentiles) {
713 len = calc_clat_percentiles(ts->io_u_plat[ddir],
714 ts->clat_stat[ddir].samples,
715 ts->percentile_list, &ovals, &maxv,
716 &minv);
717 } else
718 len = 0;
719
720 percentile_object = json_create_object();
721 json_object_add_value_object(tmp_object, "percentile", percentile_object);
722 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
723 if (i >= len) {
724 json_object_add_value_int(percentile_object, "0.00", 0);
725 continue;
726 }
Vincent Kang Fu435d1952013-02-06 08:43:40 +0100727 snprintf(buf, sizeof(buf), "%f", ts->percentile_list[i].u.f);
Shaohua Licc372b12012-09-17 09:12:18 +0200728 json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]);
729 }
730
731 if (!calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) {
732 min = max = 0;
733 mean = dev = 0.0;
734 }
735 tmp_object = json_create_object();
736 json_object_add_value_object(dir_object, "lat", tmp_object);
737 json_object_add_value_int(tmp_object, "min", min);
738 json_object_add_value_int(tmp_object, "max", max);
739 json_object_add_value_float(tmp_object, "mean", mean);
740 json_object_add_value_float(tmp_object, "stddev", dev);
741 if (ovals)
742 free(ovals);
743
Shaohua Lib9e1b492013-04-03 08:40:17 +0200744 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Shaohua Licc372b12012-09-17 09:12:18 +0200745 if (rs->agg[ddir]) {
746 p_of_agg = mean * 100 / (double) rs->agg[ddir];
747 if (p_of_agg > 100.0)
748 p_of_agg = 100.0;
749 }
750 } else {
751 min = max = 0;
752 p_of_agg = mean = dev = 0.0;
753 }
754 json_object_add_value_int(dir_object, "bw_min", min);
755 json_object_add_value_int(dir_object, "bw_max", max);
756 json_object_add_value_float(dir_object, "bw_agg", mean);
757 json_object_add_value_float(dir_object, "bw_mean", mean);
758 json_object_add_value_float(dir_object, "bw_dev", dev);
759}
760
Jens Axboe4d658652011-10-17 15:05:47 +0200761static void show_thread_status_terse_v2(struct thread_stat *ts,
Jens Axboe3c3ed072012-03-27 09:12:39 +0200762 struct group_run_stats *rs)
Jens Axboe4d658652011-10-17 15:05:47 +0200763{
764 double io_u_dist[FIO_IO_U_MAP_NR];
765 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
766 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
767 double usr_cpu, sys_cpu;
768 int i;
769
770 /* General Info */
771 log_info("2;%s;%d;%d", ts->name, ts->groupid, ts->error);
772 /* Log Read Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200773 show_ddir_status_terse(ts, rs, DDIR_READ);
Jens Axboe4d658652011-10-17 15:05:47 +0200774 /* Log Write Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200775 show_ddir_status_terse(ts, rs, DDIR_WRITE);
776 /* Log Trim Status */
777 show_ddir_status_terse(ts, rs, DDIR_TRIM);
Jens Axboe4d658652011-10-17 15:05:47 +0200778
779 /* CPU Usage */
780 if (ts->total_run_time) {
781 double runt = (double) ts->total_run_time;
782
783 usr_cpu = (double) ts->usr_time * 100 / runt;
784 sys_cpu = (double) ts->sys_time * 100 / runt;
785 } else {
786 usr_cpu = 0;
787 sys_cpu = 0;
788 }
789
790 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
791 ts->minf);
792
793 /* Calc % distribution of IO depths, usecond, msecond latency */
Jens Axboed79db122012-09-24 08:51:24 +0200794 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
Jens Axboe4d658652011-10-17 15:05:47 +0200795 stat_calc_lat_u(ts, io_u_lat_u);
796 stat_calc_lat_m(ts, io_u_lat_m);
797
798 /* Only show fixed 7 I/O depth levels*/
799 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
800 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
801 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
802
803 /* Microsecond latency */
804 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
805 log_info(";%3.2f%%", io_u_lat_u[i]);
806 /* Millisecond latency */
807 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
808 log_info(";%3.2f%%", io_u_lat_m[i]);
809 /* Additional output if continue_on_error set - default off*/
810 if (ts->continue_on_error)
811 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
812 log_info("\n");
813
814 /* Additional output if description is set */
815 if (ts->description)
816 log_info(";%s", ts->description);
817
818 log_info("\n");
819}
820
Jens Axboe3449ab82012-09-14 23:35:08 +0200821static void show_thread_status_terse_v3_v4(struct thread_stat *ts,
822 struct group_run_stats *rs, int ver)
Jens Axboec6ae0a52006-06-12 11:04:44 +0200823{
Jens Axboe22708902007-03-06 17:05:32 +0100824 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200825 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
826 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200827 double usr_cpu, sys_cpu;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200828 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200829
David Nellans562c2d22010-09-23 08:38:17 +0200830 /* General Info */
Jens Axboef3afa572012-09-17 13:34:16 +0200831 log_info("%d;%s;%s;%d;%d", ver, fio_version_string,
Jens Axboe5e726d02011-10-14 08:08:10 +0200832 ts->name, ts->groupid, ts->error);
David Nellans562c2d22010-09-23 08:38:17 +0200833 /* Log Read Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200834 show_ddir_status_terse(ts, rs, DDIR_READ);
David Nellans562c2d22010-09-23 08:38:17 +0200835 /* Log Write Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200836 show_ddir_status_terse(ts, rs, DDIR_WRITE);
837 /* Log Trim Status */
Jens Axboe3449ab82012-09-14 23:35:08 +0200838 if (ver == 4)
839 show_ddir_status_terse(ts, rs, DDIR_TRIM);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200840
David Nellans562c2d22010-09-23 08:38:17 +0200841 /* CPU Usage */
Jens Axboe756867b2007-03-06 15:19:24 +0100842 if (ts->total_run_time) {
843 double runt = (double) ts->total_run_time;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200844
Jens Axboe756867b2007-03-06 15:19:24 +0100845 usr_cpu = (double) ts->usr_time * 100 / runt;
846 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200847 } else {
848 usr_cpu = 0;
849 sys_cpu = 0;
850 }
851
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100852 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
853 ts->minf);
Jens Axboe22708902007-03-06 17:05:32 +0100854
David Nellans562c2d22010-09-23 08:38:17 +0200855 /* Calc % distribution of IO depths, usecond, msecond latency */
Jens Axboed79db122012-09-24 08:51:24 +0200856 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200857 stat_calc_lat_u(ts, io_u_lat_u);
858 stat_calc_lat_m(ts, io_u_lat_m);
Jens Axboe22708902007-03-06 17:05:32 +0100859
David Nellans562c2d22010-09-23 08:38:17 +0200860 /* Only show fixed 7 I/O depth levels*/
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100861 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
862 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
863 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
Jens Axboe22708902007-03-06 17:05:32 +0100864
David Nellans562c2d22010-09-23 08:38:17 +0200865 /* Microsecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200866 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
867 log_info(";%3.2f%%", io_u_lat_u[i]);
David Nellans562c2d22010-09-23 08:38:17 +0200868 /* Millisecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200869 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
870 log_info(";%3.2f%%", io_u_lat_m[i]);
Jens Axboef2f788d2011-10-13 14:03:52 +0200871
872 /* disk util stats, if any */
Shaohua Licc372b12012-09-17 09:12:18 +0200873 show_disk_util(1, NULL);
Jens Axboef2f788d2011-10-13 14:03:52 +0200874
David Nellans562c2d22010-09-23 08:38:17 +0200875 /* Additional output if continue_on_error set - default off*/
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200876 if (ts->continue_on_error)
877 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
Jens Axboe22708902007-03-06 17:05:32 +0100878
David Nellans562c2d22010-09-23 08:38:17 +0200879 /* Additional output if description is set */
Jens Axboe4b0f2252011-10-13 15:03:25 +0200880 if (strlen(ts->description))
Jens Axboe6d861442007-03-15 09:22:23 +0100881 log_info(";%s", ts->description);
Jens Axboe946e4272012-03-23 19:22:21 +0100882
883 log_info("\n");
Jens Axboe756867b2007-03-06 15:19:24 +0100884}
885
Shaohua Licc372b12012-09-17 09:12:18 +0200886static struct json_object *show_thread_status_json(struct thread_stat *ts,
887 struct group_run_stats *rs)
888{
889 struct json_object *root, *tmp;
890 double io_u_dist[FIO_IO_U_MAP_NR];
891 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
892 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
893 double usr_cpu, sys_cpu;
894 int i;
895
896 root = json_create_object();
897 json_object_add_value_string(root, "jobname", ts->name);
898 json_object_add_value_int(root, "groupid", ts->groupid);
899 json_object_add_value_int(root, "error", ts->error);
900
901 add_ddir_status_json(ts, rs, DDIR_READ, root);
902 add_ddir_status_json(ts, rs, DDIR_WRITE, root);
Jens Axboef3afa572012-09-17 13:34:16 +0200903 add_ddir_status_json(ts, rs, DDIR_TRIM, root);
Shaohua Licc372b12012-09-17 09:12:18 +0200904
905 /* CPU Usage */
906 if (ts->total_run_time) {
907 double runt = (double) ts->total_run_time;
908
909 usr_cpu = (double) ts->usr_time * 100 / runt;
910 sys_cpu = (double) ts->sys_time * 100 / runt;
911 } else {
912 usr_cpu = 0;
913 sys_cpu = 0;
914 }
915 json_object_add_value_float(root, "usr_cpu", usr_cpu);
916 json_object_add_value_float(root, "sys_cpu", sys_cpu);
917 json_object_add_value_int(root, "ctx", ts->ctx);
918 json_object_add_value_int(root, "majf", ts->majf);
919 json_object_add_value_int(root, "minf", ts->minf);
920
921
922 /* Calc % distribution of IO depths, usecond, msecond latency */
Jens Axboed79db122012-09-24 08:51:24 +0200923 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
Shaohua Licc372b12012-09-17 09:12:18 +0200924 stat_calc_lat_u(ts, io_u_lat_u);
925 stat_calc_lat_m(ts, io_u_lat_m);
926
927 tmp = json_create_object();
928 json_object_add_value_object(root, "iodepth_level", tmp);
929 /* Only show fixed 7 I/O depth levels*/
930 for (i = 0; i < 7; i++) {
931 char name[20];
932 if (i < 6)
Ken Raeburn98ffb8f2013-01-30 22:31:09 +0100933 snprintf(name, 20, "%d", 1 << i);
Shaohua Licc372b12012-09-17 09:12:18 +0200934 else
Ken Raeburn98ffb8f2013-01-30 22:31:09 +0100935 snprintf(name, 20, ">=%d", 1 << i);
Shaohua Licc372b12012-09-17 09:12:18 +0200936 json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]);
937 }
938
939 tmp = json_create_object();
940 json_object_add_value_object(root, "latency_us", tmp);
941 /* Microsecond latency */
942 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
943 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
944 "250", "500", "750", "1000", };
945 json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]);
946 }
947 /* Millisecond latency */
948 tmp = json_create_object();
949 json_object_add_value_object(root, "latency_ms", tmp);
950 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) {
951 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
952 "250", "500", "750", "1000", "2000",
953 ">=2000", };
954 json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]);
955 }
956
957 /* Additional output if continue_on_error set - default off*/
958 if (ts->continue_on_error) {
959 json_object_add_value_int(root, "total_err", ts->total_err_count);
960 json_object_add_value_int(root, "total_err", ts->first_error);
961 }
962
963 /* Additional output if description is set */
964 if (strlen(ts->description))
965 json_object_add_value_string(root, "desc", ts->description);
966
967 return root;
968}
969
Jens Axboe4d658652011-10-17 15:05:47 +0200970static void show_thread_status_terse(struct thread_stat *ts,
971 struct group_run_stats *rs)
972{
973 if (terse_version == 2)
974 show_thread_status_terse_v2(ts, rs);
Jens Axboe3449ab82012-09-14 23:35:08 +0200975 else if (terse_version == 3 || terse_version == 4)
976 show_thread_status_terse_v3_v4(ts, rs, terse_version);
Jens Axboe4d658652011-10-17 15:05:47 +0200977 else
978 log_err("fio: bad terse version!? %d\n", terse_version);
979}
980
Jens Axboe197574e2007-03-08 15:35:11 +0100981static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
Jens Axboe756867b2007-03-06 15:19:24 +0100982{
983 double mean, S;
984
Zheng Liue09231c2011-09-16 08:20:12 +0200985 if (src->samples == 0)
986 return;
987
Jens Axboe756867b2007-03-06 15:19:24 +0100988 dst->min_val = min(dst->min_val, src->min_val);
989 dst->max_val = max(dst->max_val, src->max_val);
Jens Axboe756867b2007-03-06 15:19:24 +0100990
991 /*
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200992 * Compute new mean and S after the merge
993 * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
994 * #Parallel_algorithm>
Jens Axboe756867b2007-03-06 15:19:24 +0100995 */
996 if (nr == 1) {
Jens Axboe802ad4a2011-10-05 09:51:58 +0200997 mean = src->mean.u.f;
998 S = src->S.u.f;
Jens Axboe756867b2007-03-06 15:19:24 +0100999 } else {
Jens Axboe802ad4a2011-10-05 09:51:58 +02001000 double delta = src->mean.u.f - dst->mean.u.f;
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001001
Jens Axboe802ad4a2011-10-05 09:51:58 +02001002 mean = ((src->mean.u.f * src->samples) +
1003 (dst->mean.u.f * dst->samples)) /
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001004 (dst->samples + src->samples);
1005
Jens Axboe802ad4a2011-10-05 09:51:58 +02001006 S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) *
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001007 (dst->samples * src->samples) /
1008 (dst->samples + src->samples);
Jens Axboe756867b2007-03-06 15:19:24 +01001009 }
1010
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +02001011 dst->samples += src->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +02001012 dst->mean.u.f = mean;
1013 dst->S.u.f = S;
Jens Axboe756867b2007-03-06 15:19:24 +01001014}
1015
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001016void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src)
1017{
1018 int i;
1019
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001020 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001021 if (dst->max_run[i] < src->max_run[i])
1022 dst->max_run[i] = src->max_run[i];
1023 if (dst->min_run[i] && dst->min_run[i] > src->min_run[i])
1024 dst->min_run[i] = src->min_run[i];
1025 if (dst->max_bw[i] < src->max_bw[i])
1026 dst->max_bw[i] = src->max_bw[i];
1027 if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i])
1028 dst->min_bw[i] = src->min_bw[i];
1029
1030 dst->io_kb[i] += src->io_kb[i];
1031 dst->agg[i] += src->agg[i];
1032 }
1033
1034}
1035
Jens Axboe5b9babb2011-10-10 12:14:30 +02001036void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr)
1037{
1038 int l, k;
1039
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001040 for (l = 0; l < DDIR_RWDIR_CNT; l++) {
Jens Axboe771e58b2013-01-30 12:56:23 +01001041 if (!dst->unified_rw_rep) {
1042 sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr);
1043 sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr);
1044 sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr);
1045 sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr);
Jens Axboe5b9babb2011-10-10 12:14:30 +02001046
Jens Axboe771e58b2013-01-30 12:56:23 +01001047 dst->io_bytes[l] += src->io_bytes[l];
Jens Axboe5b9babb2011-10-10 12:14:30 +02001048
Jens Axboe771e58b2013-01-30 12:56:23 +01001049 if (dst->runtime[l] < src->runtime[l])
1050 dst->runtime[l] = src->runtime[l];
1051 } else {
1052 sum_stat(&dst->clat_stat[0], &src->clat_stat[l], nr);
1053 sum_stat(&dst->slat_stat[0], &src->slat_stat[l], nr);
1054 sum_stat(&dst->lat_stat[0], &src->lat_stat[l], nr);
1055 sum_stat(&dst->bw_stat[0], &src->bw_stat[l], nr);
1056
1057 dst->io_bytes[0] += src->io_bytes[l];
1058
1059 if (dst->runtime[0] < src->runtime[l])
1060 dst->runtime[0] = src->runtime[l];
1061 }
Jens Axboe5b9babb2011-10-10 12:14:30 +02001062 }
1063
1064 dst->usr_time += src->usr_time;
1065 dst->sys_time += src->sys_time;
1066 dst->ctx += src->ctx;
1067 dst->majf += src->majf;
1068 dst->minf += src->minf;
1069
1070 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1071 dst->io_u_map[k] += src->io_u_map[k];
1072 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1073 dst->io_u_submit[k] += src->io_u_submit[k];
1074 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1075 dst->io_u_complete[k] += src->io_u_complete[k];
1076 for (k = 0; k < FIO_IO_U_LAT_U_NR; k++)
1077 dst->io_u_lat_u[k] += src->io_u_lat_u[k];
1078 for (k = 0; k < FIO_IO_U_LAT_M_NR; k++)
1079 dst->io_u_lat_m[k] += src->io_u_lat_m[k];
1080
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001081 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
Jens Axboe771e58b2013-01-30 12:56:23 +01001082 if (!dst->unified_rw_rep) {
1083 dst->total_io_u[k] += src->total_io_u[k];
1084 dst->short_io_u[k] += src->short_io_u[k];
1085 } else {
1086 dst->total_io_u[0] += src->total_io_u[k];
1087 dst->short_io_u[0] += src->short_io_u[k];
1088 }
Jens Axboe5b9babb2011-10-10 12:14:30 +02001089 }
1090
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001091 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
Jens Axboe5b9babb2011-10-10 12:14:30 +02001092 int m;
Jens Axboe771e58b2013-01-30 12:56:23 +01001093
1094 for (m = 0; m < FIO_IO_U_PLAT_NR; m++) {
1095 if (!dst->unified_rw_rep)
1096 dst->io_u_plat[k][m] += src->io_u_plat[k][m];
1097 else
1098 dst->io_u_plat[0][m] += src->io_u_plat[k][m];
1099 }
Jens Axboe5b9babb2011-10-10 12:14:30 +02001100 }
1101
1102 dst->total_run_time += src->total_run_time;
1103 dst->total_submit += src->total_submit;
1104 dst->total_complete += src->total_complete;
1105}
1106
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001107void init_group_run_stat(struct group_run_stats *gs)
1108{
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001109 int i;
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001110 memset(gs, 0, sizeof(*gs));
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001111
1112 for (i = 0; i < DDIR_RWDIR_CNT; i++)
1113 gs->min_bw[i] = gs->min_run[i] = ~0UL;
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001114}
1115
1116void init_thread_stat(struct thread_stat *ts)
1117{
1118 int j;
1119
1120 memset(ts, 0, sizeof(*ts));
1121
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001122 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001123 ts->lat_stat[j].min_val = -1UL;
1124 ts->clat_stat[j].min_val = -1UL;
1125 ts->slat_stat[j].min_val = -1UL;
1126 ts->bw_stat[j].min_val = -1UL;
1127 }
1128 ts->groupid = -1;
1129}
1130
Jens Axboe3c39a372006-06-06 20:56:12 +02001131void show_run_stats(void)
1132{
1133 struct group_run_stats *runstats, *rs;
1134 struct thread_data *td;
Jens Axboe756867b2007-03-06 15:19:24 +01001135 struct thread_stat *threadstats, *ts;
Jens Axboe5b9babb2011-10-10 12:14:30 +02001136 int i, j, nr_ts, last_ts, idx;
Jens Axboe90fef2d2009-07-17 22:33:32 +02001137 int kb_base_warned = 0;
Steven Noonanad705bc2013-04-08 15:05:25 -07001138 int unit_base_warned = 0;
Shaohua Licc372b12012-09-17 09:12:18 +02001139 struct json_object *root = NULL;
1140 struct json_array *array = NULL;
Jens Axboe3c39a372006-06-06 20:56:12 +02001141
1142 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
1143
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001144 for (i = 0; i < groupid + 1; i++)
1145 init_group_run_stat(&runstats[i]);
Jens Axboe3c39a372006-06-06 20:56:12 +02001146
Jens Axboe756867b2007-03-06 15:19:24 +01001147 /*
1148 * find out how many threads stats we need. if group reporting isn't
1149 * enabled, it's one-per-td.
1150 */
1151 nr_ts = 0;
1152 last_ts = -1;
Jens Axboe34572e22006-10-20 09:33:18 +02001153 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001154 if (!td->o.group_reporting) {
Jens Axboe756867b2007-03-06 15:19:24 +01001155 nr_ts++;
1156 continue;
1157 }
1158 if (last_ts == td->groupid)
1159 continue;
1160
1161 last_ts = td->groupid;
1162 nr_ts++;
1163 }
1164
1165 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
1166
Jens Axboe37f0c1a2011-10-11 14:08:33 +02001167 for (i = 0; i < nr_ts; i++)
1168 init_thread_stat(&threadstats[i]);
Jens Axboe756867b2007-03-06 15:19:24 +01001169
1170 j = 0;
1171 last_ts = -1;
Jens Axboe197574e2007-03-08 15:35:11 +01001172 idx = 0;
Jens Axboe756867b2007-03-06 15:19:24 +01001173 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001174 if (idx && (!td->o.group_reporting ||
1175 (td->o.group_reporting && last_ts != td->groupid))) {
Jens Axboe7abd0e32007-03-12 15:24:43 +01001176 idx = 0;
1177 j++;
1178 }
1179
1180 last_ts = td->groupid;
1181
Jens Axboe756867b2007-03-06 15:19:24 +01001182 ts = &threadstats[j];
1183
Yu-ju Hong83349192011-08-13 00:53:44 +02001184 ts->clat_percentiles = td->o.clat_percentiles;
Vincent Kang Fu435d1952013-02-06 08:43:40 +01001185 ts->percentile_precision = td->o.percentile_precision;
Vincent Kang Fufd112d32013-02-02 09:28:55 +01001186 memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +02001187
Jens Axboe197574e2007-03-08 15:35:11 +01001188 idx++;
Jens Axboe6586ee82007-03-06 19:46:09 +01001189 ts->members++;
Jens Axboe756867b2007-03-06 15:19:24 +01001190
Jens Axboe7abd0e32007-03-12 15:24:43 +01001191 if (ts->groupid == -1) {
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001192 /*
1193 * These are per-group shared already
1194 */
Jens Axboef6bb5b82011-10-03 12:21:25 +02001195 strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE);
Jens Axboea64e88d2011-10-03 14:20:01 +02001196 if (td->o.description)
1197 strncpy(ts->description, td->o.description,
1198 FIO_JOBNAME_SIZE);
1199 else
1200 memset(ts->description, 0, FIO_JOBNAME_SIZE);
1201
Jens Axboe2f122b12012-03-15 13:10:19 +01001202 /*
1203 * If multiple entries in this group, this is
1204 * the first member.
1205 */
1206 ts->thread_number = td->thread_number;
Jens Axboe756867b2007-03-06 15:19:24 +01001207 ts->groupid = td->groupid;
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001208
1209 /*
1210 * first pid in group, not very useful...
1211 */
Jens Axboe756867b2007-03-06 15:19:24 +01001212 ts->pid = td->pid;
Jens Axboe90fef2d2009-07-17 22:33:32 +02001213
1214 ts->kb_base = td->o.kb_base;
Steven Noonanad705bc2013-04-08 15:05:25 -07001215 ts->unit_base = td->o.unit_base;
Jens Axboe771e58b2013-01-30 12:56:23 +01001216 ts->unified_rw_rep = td->o.unified_rw_rep;
Jens Axboe90fef2d2009-07-17 22:33:32 +02001217 } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) {
1218 log_info("fio: kb_base differs for jobs in group, using"
1219 " %u as the base\n", ts->kb_base);
1220 kb_base_warned = 1;
Steven Noonanad705bc2013-04-08 15:05:25 -07001221 } else if (ts->unit_base != td->o.unit_base && !unit_base_warned) {
1222 log_info("fio: unit_base differs for jobs in group, using"
1223 " %u as the base\n", ts->unit_base);
1224 unit_base_warned = 1;
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001225 }
1226
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001227 ts->continue_on_error = td->o.continue_on_error;
1228 ts->total_err_count += td->total_err_count;
1229 ts->first_error = td->first_error;
1230 if (!ts->error) {
1231 if (!td->error && td->o.continue_on_error &&
1232 td->first_error) {
1233 ts->error = td->first_error;
Jens Axboef6bb5b82011-10-03 12:21:25 +02001234 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001235 } else if (td->error) {
1236 ts->error = td->error;
Jens Axboef6bb5b82011-10-03 12:21:25 +02001237 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001238 }
Jens Axboe756867b2007-03-06 15:19:24 +01001239 }
1240
Jens Axboe5b9babb2011-10-10 12:14:30 +02001241 sum_thread_stats(ts, &td->ts, idx);
Jens Axboe756867b2007-03-06 15:19:24 +01001242 }
1243
1244 for (i = 0; i < nr_ts; i++) {
Jens Axboe94370ac2007-03-08 15:28:10 +01001245 unsigned long long bw;
Jens Axboe3c39a372006-06-06 20:56:12 +02001246
Jens Axboe756867b2007-03-06 15:19:24 +01001247 ts = &threadstats[i];
1248 rs = &runstats[ts->groupid];
Jens Axboe90fef2d2009-07-17 22:33:32 +02001249 rs->kb_base = ts->kb_base;
Steven Noonanad705bc2013-04-08 15:05:25 -07001250 rs->unit_base = ts->unit_base;
Jens Axboe771e58b2013-01-30 12:56:23 +01001251 rs->unified_rw_rep += ts->unified_rw_rep;
Jens Axboe3c39a372006-06-06 20:56:12 +02001252
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001253 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
Jens Axboe94370ac2007-03-08 15:28:10 +01001254 if (!ts->runtime[j])
1255 continue;
1256 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
1257 rs->min_run[j] = ts->runtime[j];
1258 if (ts->runtime[j] > rs->max_run[j])
1259 rs->max_run[j] = ts->runtime[j];
Jens Axboe3c39a372006-06-06 20:56:12 +02001260
Jens Axboe94370ac2007-03-08 15:28:10 +01001261 bw = 0;
Jens Axboe8879fd12009-04-20 10:06:02 +02001262 if (ts->runtime[j]) {
Jens Axboec857cfe2012-04-05 08:42:11 -06001263 unsigned long runt = ts->runtime[j];
1264 unsigned long long kb;
Jens Axboe8879fd12009-04-20 10:06:02 +02001265
Jens Axboec857cfe2012-04-05 08:42:11 -06001266 kb = ts->io_bytes[j] / rs->kb_base;
1267 bw = kb * 1000 / runt;
Jens Axboe8879fd12009-04-20 10:06:02 +02001268 }
Jens Axboe94370ac2007-03-08 15:28:10 +01001269 if (bw < rs->min_bw[j])
1270 rs->min_bw[j] = bw;
1271 if (bw > rs->max_bw[j])
1272 rs->max_bw[j] = bw;
Jens Axboe3c39a372006-06-06 20:56:12 +02001273
Jens Axboe90fef2d2009-07-17 22:33:32 +02001274 rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base;
Jens Axboe94370ac2007-03-08 15:28:10 +01001275 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001276 }
1277
1278 for (i = 0; i < groupid + 1; i++) {
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001279 int ddir;
1280
Jens Axboe3c39a372006-06-06 20:56:12 +02001281 rs = &runstats[i];
1282
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001283 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
1284 if (rs->max_run[ddir])
1285 rs->agg[ddir] = (rs->io_kb[ddir] * 1000) /
1286 rs->max_run[ddir];
1287 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001288 }
1289
1290 /*
1291 * don't overwrite last signal output
1292 */
Jens Axboef3afa572012-09-17 13:34:16 +02001293 if (output_format == FIO_OUTPUT_NORMAL)
Jens Axboe4ceb30d2010-02-24 09:19:14 +01001294 log_info("\n");
Jens Axboef3afa572012-09-17 13:34:16 +02001295 else if (output_format == FIO_OUTPUT_JSON) {
Shaohua Licc372b12012-09-17 09:12:18 +02001296 root = json_create_object();
1297 json_object_add_value_string(root, "fio version", fio_version_string);
1298 array = json_create_array();
1299 json_object_add_value_array(root, "jobs", array);
1300 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001301
Jens Axboe756867b2007-03-06 15:19:24 +01001302 for (i = 0; i < nr_ts; i++) {
1303 ts = &threadstats[i];
1304 rs = &runstats[ts->groupid];
Jens Axboe3c39a372006-06-06 20:56:12 +02001305
Jens Axboea64e88d2011-10-03 14:20:01 +02001306 if (is_backend)
1307 fio_server_send_ts(ts, rs);
Jens Axboef3afa572012-09-17 13:34:16 +02001308 else if (output_format == FIO_OUTPUT_TERSE)
Jens Axboe756867b2007-03-06 15:19:24 +01001309 show_thread_status_terse(ts, rs);
Jens Axboef3afa572012-09-17 13:34:16 +02001310 else if (output_format == FIO_OUTPUT_JSON) {
1311 struct json_object *tmp = show_thread_status_json(ts, rs);
1312 json_array_add_value_object(array, tmp);
Shaohua Licc372b12012-09-17 09:12:18 +02001313 } else
Jens Axboe756867b2007-03-06 15:19:24 +01001314 show_thread_status(ts, rs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001315 }
Jens Axboef3afa572012-09-17 13:34:16 +02001316 if (output_format == FIO_OUTPUT_JSON) {
Shaohua Licc372b12012-09-17 09:12:18 +02001317 /* disk util stats, if any */
1318 show_disk_util(1, root);
1319
Huadong Liuf2a2ce02013-01-30 13:22:24 +01001320 show_idle_prof_stats(FIO_OUTPUT_JSON, root);
1321
Shaohua Licc372b12012-09-17 09:12:18 +02001322 json_print_object(root);
1323 log_info("\n");
1324 json_free_object(root);
1325 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001326
Jens Axboe72c27ff2011-10-16 11:50:31 +02001327 for (i = 0; i < groupid + 1; i++) {
1328 rs = &runstats[i];
Jens Axboea64e88d2011-10-03 14:20:01 +02001329
Jens Axboe72c27ff2011-10-16 11:50:31 +02001330 rs->groupid = i;
Jens Axboed09a64a2011-10-13 11:38:56 +02001331 if (is_backend)
Jens Axboe72c27ff2011-10-16 11:50:31 +02001332 fio_server_send_gs(rs);
Jens Axboef3afa572012-09-17 13:34:16 +02001333 else if (output_format == FIO_OUTPUT_NORMAL)
Jens Axboe72c27ff2011-10-16 11:50:31 +02001334 show_group_stats(rs);
Jens Axboec6ae0a52006-06-12 11:04:44 +02001335 }
Jens Axboeeecf2722006-10-20 14:00:36 +02001336
Jens Axboe72c27ff2011-10-16 11:50:31 +02001337 if (is_backend)
1338 fio_server_send_du();
Huadong Liu60904002013-02-21 10:24:20 +01001339 else if (output_format == FIO_OUTPUT_NORMAL) {
Shaohua Licc372b12012-09-17 09:12:18 +02001340 show_disk_util(0, NULL);
Huadong Liu60904002013-02-21 10:24:20 +01001341 show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL);
1342 }
Huadong Liuf2a2ce02013-01-30 13:22:24 +01001343
Jens Axboeeecf2722006-10-20 14:00:36 +02001344 free(runstats);
Jens Axboe756867b2007-03-06 15:19:24 +01001345 free(threadstats);
Jens Axboe3c39a372006-06-06 20:56:12 +02001346}
1347
Jens Axboeb4ea84d2013-04-11 14:20:33 +02001348static void *__show_running_run_stats(void fio_unused *arg)
Jens Axboeb852e7c2012-03-30 10:30:35 +02001349{
1350 struct thread_data *td;
1351 unsigned long long *rt;
1352 struct timeval tv;
1353 int i;
1354
1355 rt = malloc(thread_number * sizeof(unsigned long long));
1356 fio_gettime(&tv, NULL);
1357
1358 for_each_td(td, i) {
1359 rt[i] = mtime_since(&td->start, &tv);
1360 if (td_read(td) && td->io_bytes[DDIR_READ])
1361 td->ts.runtime[DDIR_READ] += rt[i];
1362 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1363 td->ts.runtime[DDIR_WRITE] += rt[i];
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001364 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1365 td->ts.runtime[DDIR_TRIM] += rt[i];
Jens Axboeb852e7c2012-03-30 10:30:35 +02001366
Jens Axboec97f1ad2013-03-28 15:08:49 -06001367 td->update_rusage = 1;
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001368 td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ];
1369 td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
1370 td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
Jens Axboeb852e7c2012-03-30 10:30:35 +02001371 td->ts.total_run_time = mtime_since(&td->epoch, &tv);
1372 }
1373
Jens Axboec97f1ad2013-03-28 15:08:49 -06001374 for_each_td(td, i) {
1375 if (td->rusage_sem) {
1376 td->update_rusage = 1;
1377 fio_mutex_down(td->rusage_sem);
1378 }
1379 td->update_rusage = 0;
1380 }
1381
Jens Axboeb852e7c2012-03-30 10:30:35 +02001382 show_run_stats();
1383
1384 for_each_td(td, i) {
1385 if (td_read(td) && td->io_bytes[DDIR_READ])
1386 td->ts.runtime[DDIR_READ] -= rt[i];
1387 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1388 td->ts.runtime[DDIR_WRITE] -= rt[i];
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001389 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1390 td->ts.runtime[DDIR_TRIM] -= rt[i];
Jens Axboeb852e7c2012-03-30 10:30:35 +02001391 }
1392
1393 free(rt);
1394 return NULL;
1395}
1396
1397/*
1398 * Called from signal handler. It _should_ be safe to just run this inline
1399 * in the sig handler, but we should be disturbing the system less by just
1400 * creating a thread to do it.
1401 */
1402void show_running_run_stats(void)
1403{
1404 pthread_t thread;
1405
1406 pthread_create(&thread, NULL, __show_running_run_stats, NULL);
1407 pthread_detach(thread);
1408}
1409
Jens Axboe68704082007-01-10 19:56:37 +01001410static inline void add_stat_sample(struct io_stat *is, unsigned long data)
Jens Axboe3c39a372006-06-06 20:56:12 +02001411{
Jens Axboe68704082007-01-10 19:56:37 +01001412 double val = data;
Jens Axboe6660cc62007-03-06 15:48:38 +01001413 double delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001414
Jens Axboe68704082007-01-10 19:56:37 +01001415 if (data > is->max_val)
1416 is->max_val = data;
1417 if (data < is->min_val)
1418 is->min_val = data;
1419
Jens Axboe802ad4a2011-10-05 09:51:58 +02001420 delta = val - is->mean.u.f;
Jens Axboeef11d732007-03-29 15:36:29 +02001421 if (delta) {
Jens Axboe802ad4a2011-10-05 09:51:58 +02001422 is->mean.u.f += delta / (is->samples + 1.0);
1423 is->S.u.f += delta * (val - is->mean.u.f);
Jens Axboeef11d732007-03-29 15:36:29 +02001424 }
Jens Axboe68704082007-01-10 19:56:37 +01001425
Jens Axboe3c39a372006-06-06 20:56:12 +02001426 is->samples++;
1427}
1428
Jens Axboebb3884d2007-01-17 17:23:11 +11001429static void __add_log_sample(struct io_log *iolog, unsigned long val,
Jens Axboe306ddc92009-05-18 13:08:12 +02001430 enum fio_ddir ddir, unsigned int bs,
Jens Axboe2b13e712011-01-19 14:04:16 -07001431 unsigned long t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001432{
Jens Axboe306ddc92009-05-18 13:08:12 +02001433 const int nr_samples = iolog->nr_samples;
1434
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001435 if (!iolog->nr_samples)
1436 iolog->avg_last = t;
1437
Jens Axboe3c39a372006-06-06 20:56:12 +02001438 if (iolog->nr_samples == iolog->max_samples) {
1439 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
1440
1441 iolog->log = realloc(iolog->log, new_size);
1442 iolog->max_samples <<= 1;
1443 }
1444
Jens Axboe306ddc92009-05-18 13:08:12 +02001445 iolog->log[nr_samples].val = val;
Jens Axboe2b13e712011-01-19 14:04:16 -07001446 iolog->log[nr_samples].time = t;
Jens Axboe306ddc92009-05-18 13:08:12 +02001447 iolog->log[nr_samples].ddir = ddir;
1448 iolog->log[nr_samples].bs = bs;
Jens Axboe3c39a372006-06-06 20:56:12 +02001449 iolog->nr_samples++;
1450}
1451
Jens Axboe7fb28d32011-12-01 15:17:24 +01001452static inline void reset_io_stat(struct io_stat *ios)
1453{
1454 ios->max_val = ios->min_val = ios->samples = 0;
1455 ios->mean.u.f = ios->S.u.f = 0;
1456}
1457
Jens Axboebb3884d2007-01-17 17:23:11 +11001458static void add_log_sample(struct thread_data *td, struct io_log *iolog,
Jens Axboe306ddc92009-05-18 13:08:12 +02001459 unsigned long val, enum fio_ddir ddir,
1460 unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001461{
Jens Axboe7fb28d32011-12-01 15:17:24 +01001462 unsigned long elapsed, this_window;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001463
Jens Axboeff58fce2010-08-25 12:02:08 +02001464 if (!ddir_rw(ddir))
1465 return;
1466
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001467 elapsed = mtime_since_now(&td->epoch);
1468
1469 /*
1470 * If no time averaging, just add the log sample.
1471 */
1472 if (!iolog->avg_msec) {
1473 __add_log_sample(iolog, val, ddir, bs, elapsed);
1474 return;
1475 }
1476
1477 /*
1478 * Add the sample. If the time period has passed, then
1479 * add that entry to the log and clear.
1480 */
1481 add_stat_sample(&iolog->avg_window[ddir], val);
1482
Jens Axboe7fb28d32011-12-01 15:17:24 +01001483 /*
1484 * If period hasn't passed, adding the above sample is all we
1485 * need to do.
1486 */
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001487 this_window = elapsed - iolog->avg_last;
1488 if (this_window < iolog->avg_msec)
1489 return;
1490
Jens Axboe7fb28d32011-12-01 15:17:24 +01001491 /*
1492 * Note an entry in the log. Use the mean from the logged samples,
1493 * making sure to properly round up. Only write a log entry if we
1494 * had actual samples done.
1495 */
1496 if (iolog->avg_window[DDIR_READ].samples) {
1497 unsigned long mr;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001498
Jens Axboe7fb28d32011-12-01 15:17:24 +01001499 mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001500 __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed);
Jens Axboe7fb28d32011-12-01 15:17:24 +01001501 }
1502 if (iolog->avg_window[DDIR_WRITE].samples) {
1503 unsigned long mw;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001504
Jens Axboe7fb28d32011-12-01 15:17:24 +01001505 mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50;
1506 __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed);
1507 }
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001508 if (iolog->avg_window[DDIR_TRIM].samples) {
1509 unsigned long mw;
1510
1511 mw = iolog->avg_window[DDIR_TRIM].mean.u.f + 0.50;
1512 __add_log_sample(iolog, mw, DDIR_TRIM, 0, elapsed);
1513 }
1514
Jens Axboe7fb28d32011-12-01 15:17:24 +01001515
1516 reset_io_stat(&iolog->avg_window[DDIR_READ]);
1517 reset_io_stat(&iolog->avg_window[DDIR_WRITE]);
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001518 reset_io_stat(&iolog->avg_window[DDIR_TRIM]);
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001519 iolog->avg_last = elapsed;
Jens Axboebb3884d2007-01-17 17:23:11 +11001520}
1521
Jens Axboe306ddc92009-05-18 13:08:12 +02001522void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001523{
Jens Axboeff58fce2010-08-25 12:02:08 +02001524 struct io_log *iolog;
Jens Axboebb3884d2007-01-17 17:23:11 +11001525
Jens Axboeff58fce2010-08-25 12:02:08 +02001526 if (!ddir_rw(ddir))
1527 return;
1528
1529 iolog = agg_io_log[ddir];
Jens Axboe306ddc92009-05-18 13:08:12 +02001530 __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis());
Jens Axboebb3884d2007-01-17 17:23:11 +11001531}
1532
Yu-ju Hong83349192011-08-13 00:53:44 +02001533static void add_clat_percentile_sample(struct thread_stat *ts,
1534 unsigned long usec, enum fio_ddir ddir)
1535{
1536 unsigned int idx = plat_val_to_idx(usec);
1537 assert(idx < FIO_IO_U_PLAT_NR);
1538
1539 ts->io_u_plat[ddir][idx]++;
1540}
1541
Jens Axboe1e97cce2006-12-05 11:44:16 +01001542void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001543 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001544{
Jens Axboe756867b2007-03-06 15:19:24 +01001545 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001546
Jens Axboeff58fce2010-08-25 12:02:08 +02001547 if (!ddir_rw(ddir))
1548 return;
1549
Jens Axboed85f5112007-06-18 09:41:23 +02001550 add_stat_sample(&ts->clat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001551
Jens Axboe7b9f7332011-10-03 10:06:44 +02001552 if (td->clat_log)
1553 add_log_sample(td, td->clat_log, usec, ddir, bs);
Yu-ju Hong83349192011-08-13 00:53:44 +02001554
1555 if (ts->clat_percentiles)
1556 add_clat_percentile_sample(ts, usec, ddir);
Jens Axboe3c39a372006-06-06 20:56:12 +02001557}
1558
Jens Axboe1e97cce2006-12-05 11:44:16 +01001559void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001560 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001561{
Jens Axboe756867b2007-03-06 15:19:24 +01001562 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001563
Jens Axboeff58fce2010-08-25 12:02:08 +02001564 if (!ddir_rw(ddir))
1565 return;
1566
Jens Axboed85f5112007-06-18 09:41:23 +02001567 add_stat_sample(&ts->slat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001568
Jens Axboe7b9f7332011-10-03 10:06:44 +02001569 if (td->slat_log)
1570 add_log_sample(td, td->slat_log, usec, ddir, bs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001571}
1572
Jens Axboe02af0982010-06-24 09:59:34 +02001573void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
1574 unsigned long usec, unsigned int bs)
1575{
1576 struct thread_stat *ts = &td->ts;
1577
Jens Axboeff58fce2010-08-25 12:02:08 +02001578 if (!ddir_rw(ddir))
1579 return;
1580
Jens Axboe02af0982010-06-24 09:59:34 +02001581 add_stat_sample(&ts->lat_stat[ddir], usec);
1582
Jens Axboe7b9f7332011-10-03 10:06:44 +02001583 if (td->lat_log)
1584 add_log_sample(td, td->lat_log, usec, ddir, bs);
Jens Axboe02af0982010-06-24 09:59:34 +02001585}
1586
Jens Axboe306ddc92009-05-18 13:08:12 +02001587void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
Jens Axboe1e97cce2006-12-05 11:44:16 +01001588 struct timeval *t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001589{
Jens Axboe756867b2007-03-06 15:19:24 +01001590 struct thread_stat *ts = &td->ts;
Jens Axboeff58fce2010-08-25 12:02:08 +02001591 unsigned long spent, rate;
Jens Axboe3c39a372006-06-06 20:56:12 +02001592
Jens Axboeff58fce2010-08-25 12:02:08 +02001593 if (!ddir_rw(ddir))
1594 return;
1595
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001596 spent = mtime_since(&td->bw_sample_time, t);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001597 if (spent < td->o.bw_avg_time)
Jens Axboe3c39a372006-06-06 20:56:12 +02001598 return;
Jens Axboe9602d8d2012-02-20 20:19:28 +01001599
1600 /*
Josh Carter5daa4eb2012-02-20 10:12:22 +01001601 * Compute both read and write rates for the interval.
1602 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001603 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
Josh Carter5daa4eb2012-02-20 10:12:22 +01001604 uint64_t delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001605
Josh Carter5daa4eb2012-02-20 10:12:22 +01001606 delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir];
1607 if (!delta)
1608 continue; /* No entries for interval */
Jens Axboe3c39a372006-06-06 20:56:12 +02001609
Josh Carter5daa4eb2012-02-20 10:12:22 +01001610 rate = delta * 1000 / spent / 1024;
1611 add_stat_sample(&ts->bw_stat[ddir], rate);
1612
1613 if (td->bw_log)
1614 add_log_sample(td, td->bw_log, rate, ddir, bs);
1615
1616 td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
1617 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001618
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001619 fio_gettime(&td->bw_sample_time, NULL);
Jens Axboe3c39a372006-06-06 20:56:12 +02001620}
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001621
1622void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,
1623 struct timeval *t)
1624{
1625 struct thread_stat *ts = &td->ts;
1626 unsigned long spent, iops;
1627
1628 if (!ddir_rw(ddir))
1629 return;
1630
1631 spent = mtime_since(&td->iops_sample_time, t);
1632 if (spent < td->o.iops_avg_time)
1633 return;
1634
Jens Axboe9602d8d2012-02-20 20:19:28 +01001635 /*
1636 * Compute both read and write rates for the interval.
1637 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001638 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
Jens Axboe9602d8d2012-02-20 20:19:28 +01001639 uint64_t delta;
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001640
Jens Axboe9602d8d2012-02-20 20:19:28 +01001641 delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir];
1642 if (!delta)
1643 continue; /* No entries for interval */
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001644
Jens Axboe9602d8d2012-02-20 20:19:28 +01001645 iops = (delta * 1000) / spent;
1646 add_stat_sample(&ts->iops_stat[ddir], iops);
1647
1648 if (td->iops_log)
1649 add_log_sample(td, td->iops_log, iops, ddir, 0);
1650
Jens Axboe421f4a82012-02-28 08:20:26 +01001651 td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
Jens Axboe9602d8d2012-02-20 20:19:28 +01001652 }
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001653
1654 fio_gettime(&td->iops_sample_time, NULL);
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001655}