blob: e29bf0c162da099507671f8c686fde7c3345190f [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"
Jens Axboe3c39a372006-06-06 20:56:12 +020013
Jens Axboe3c39a372006-06-06 20:56:12 +020014void update_rusage_stat(struct thread_data *td)
15{
Jens Axboe756867b2007-03-06 15:19:24 +010016 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +020017
Jens Axboec8aaba12011-10-03 12:14:19 +020018 getrusage(RUSAGE_SELF, &td->ru_end);
Jens Axboe079ad092007-02-20 13:58:20 +010019
Jens Axboec8aaba12011-10-03 12:14:19 +020020 ts->usr_time += mtime_since(&td->ru_start.ru_utime,
21 &td->ru_end.ru_utime);
22 ts->sys_time += mtime_since(&td->ru_start.ru_stime,
23 &td->ru_end.ru_stime);
24 ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw
25 - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw);
26 ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt;
27 ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt;
Jens Axboe5ec10ea2008-03-06 15:42:00 +010028
Jens Axboec8aaba12011-10-03 12:14:19 +020029 memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end));
Jens Axboe3c39a372006-06-06 20:56:12 +020030}
31
Yu-ju Hong83349192011-08-13 00:53:44 +020032/*
33 * Given a latency, return the index of the corresponding bucket in
34 * the structure tracking percentiles.
35 *
36 * (1) find the group (and error bits) that the value (latency)
37 * belongs to by looking at its MSB. (2) find the bucket number in the
38 * group by looking at the index bits.
39 *
40 */
41static unsigned int plat_val_to_idx(unsigned int val)
42{
43 unsigned int msb, error_bits, base, offset, idx;
44
45 /* Find MSB starting from bit 0 */
46 if (val == 0)
47 msb = 0;
48 else
49 msb = (sizeof(val)*8) - __builtin_clz(val) - 1;
50
Jens Axboe716050f2011-08-16 08:43:45 +020051 /*
52 * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
53 * all bits of the sample as index
54 */
Yu-ju Hong83349192011-08-13 00:53:44 +020055 if (msb <= FIO_IO_U_PLAT_BITS)
56 return val;
57
58 /* Compute the number of error bits to discard*/
59 error_bits = msb - FIO_IO_U_PLAT_BITS;
60
61 /* Compute the number of buckets before the group */
62 base = (error_bits + 1) << FIO_IO_U_PLAT_BITS;
63
Jens Axboe716050f2011-08-16 08:43:45 +020064 /*
65 * Discard the error bits and apply the mask to find the
66 * index for the buckets in the group
67 */
Yu-ju Hong83349192011-08-13 00:53:44 +020068 offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits);
69
70 /* Make sure the index does not exceed (array size - 1) */
71 idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1)?
72 (base + offset) : (FIO_IO_U_PLAT_NR - 1);
73
74 return idx;
75}
76
77/*
78 * Convert the given index of the bucket array to the value
79 * represented by the bucket
80 */
81static unsigned int plat_idx_to_val(unsigned int idx)
82{
83 unsigned int error_bits, k, base;
84
85 assert(idx < FIO_IO_U_PLAT_NR);
86
87 /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
88 * all bits of the sample as index */
89 if (idx < (FIO_IO_U_PLAT_VAL << 1) )
90 return idx;
91
92 /* Find the group and compute the minimum value of that group */
93 error_bits = (idx >> FIO_IO_U_PLAT_BITS) -1;
94 base = 1 << (error_bits + FIO_IO_U_PLAT_BITS);
95
96 /* Find its bucket number of the group */
97 k = idx % FIO_IO_U_PLAT_VAL;
98
99 /* Return the mean of the range of the bucket */
100 return base + ((k + 0.5) * (1 << error_bits));
101}
102
103static int double_cmp(const void *a, const void *b)
104{
Jens Axboe802ad4a2011-10-05 09:51:58 +0200105 const fio_fp64_t fa = *(const fio_fp64_t *) a;
106 const fio_fp64_t fb = *(const fio_fp64_t *) b;
Yu-ju Hong83349192011-08-13 00:53:44 +0200107 int cmp = 0;
108
Jens Axboe802ad4a2011-10-05 09:51:58 +0200109 if (fa.u.f > fb.u.f)
Yu-ju Hong83349192011-08-13 00:53:44 +0200110 cmp = 1;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200111 else if (fa.u.f < fb.u.f)
Yu-ju Hong83349192011-08-13 00:53:44 +0200112 cmp = -1;
113
114 return cmp;
115}
116
Jens Axboe1db92cb2011-10-13 13:43:36 +0200117static unsigned int calc_clat_percentiles(unsigned int *io_u_plat,
118 unsigned long nr, fio_fp64_t *plist,
119 unsigned int **output,
120 unsigned int *maxv,
121 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)
145 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,
183 fio_fp64_t *plist)
184{
185 unsigned int len, j = 0, minv, maxv;
186 unsigned int *ovals;
187 int is_last, scale_down;
188
189 len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
190 if (!len)
191 goto out;
192
Jens Axboe4f6f8292011-10-13 09:28:21 +0200193 /*
194 * We default to usecs, but if the value range is such that we
195 * should scale down to msecs, do that.
196 */
197 if (minv > 2000 && maxv > 99999) {
198 scale_down = 1;
199 log_info(" clat percentiles (msec):\n |");
200 } else {
201 scale_down = 0;
202 log_info(" clat percentiles (usec):\n |");
203 }
204
205 for (j = 0; j < len; j++) {
206 char fbuf[8];
207
208 /* for formatting */
209 if (j != 0 && (j % 4) == 0)
210 log_info(" |");
211
212 /* end of the list */
213 is_last = (j == len - 1);
214
215 if (plist[j].u.f < 10.0)
216 sprintf(fbuf, " %2.2f", plist[j].u.f);
217 else
218 sprintf(fbuf, "%2.2f", plist[j].u.f);
219
220 if (scale_down)
221 ovals[j] = (ovals[j] + 999) / 1000;
222
223 log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ',');
224
225 if (is_last)
226 break;
227
228 if (j % 4 == 3) /* for formatting */
229 log_info("\n");
230 }
231
Jens Axboe1db92cb2011-10-13 13:43:36 +0200232out:
Jens Axboe4f6f8292011-10-13 09:28:21 +0200233 if (ovals)
234 free(ovals);
Yu-ju Hong83349192011-08-13 00:53:44 +0200235}
236
Jens Axboe3c39a372006-06-06 20:56:12 +0200237static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
238 double *mean, double *dev)
239{
Jens Axboe68704082007-01-10 19:56:37 +0100240 double n = is->samples;
Jens Axboe3c39a372006-06-06 20:56:12 +0200241
242 if (is->samples == 0)
243 return 0;
244
245 *min = is->min_val;
246 *max = is->max_val;
247
248 n = (double) is->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200249 *mean = is->mean.u.f;
Jens Axboe3c39a372006-06-06 20:56:12 +0200250
Jens Axboe68704082007-01-10 19:56:37 +0100251 if (n > 1.0)
Jens Axboe802ad4a2011-10-05 09:51:58 +0200252 *dev = sqrt(is->S.u.f / (n - 1.0));
Jens Axboeef9c5c42007-01-03 14:21:13 +0100253 else
Jens Axboe4b43f542007-07-19 21:38:35 +0200254 *dev = 0;
Jens Axboeef9c5c42007-01-03 14:21:13 +0100255
Jens Axboe3c39a372006-06-06 20:56:12 +0200256 return 1;
257}
258
Jens Axboea64e88d2011-10-03 14:20:01 +0200259void show_group_stats(struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200260{
Jens Axboedbe11252007-02-11 00:19:51 +0100261 char *p1, *p2, *p3, *p4;
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200262 const char *ddir_str[] = { " READ", " WRITE" , " TRIM"};
Jens Axboedbe11252007-02-11 00:19:51 +0100263 int i;
264
Jens Axboe7e1773b2011-10-14 12:47:56 +0200265 log_info("\nRun status group %d (all jobs):\n", rs->groupid);
Jens Axboe3c39a372006-06-06 20:56:12 +0200266
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200267 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200268 const int i2p = is_power_of_2(rs->kb_base);
269
Jens Axboedbe11252007-02-11 00:19:51 +0100270 if (!rs->max_run[i])
271 continue;
272
Jens Axboe90fef2d2009-07-17 22:33:32 +0200273 p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p);
274 p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p);
275 p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p);
276 p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p);
Jens Axboedbe11252007-02-11 00:19:51 +0100277
Jens Axboeb22989b2009-07-17 22:29:23 +0200278 log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s,"
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100279 " mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2,
280 p3, p4, rs->min_run[i],
281 rs->max_run[i]);
Jens Axboedbe11252007-02-11 00:19:51 +0100282
283 free(p1);
284 free(p2);
285 free(p3);
286 free(p4);
287 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200288}
289
Jens Axboeb3605062007-03-12 14:19:47 +0100290#define ts_total_io_u(ts) \
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200291 ((ts)->total_io_u[DDIR_READ] + (ts)->total_io_u[DDIR_WRITE] +\
292 (ts)->total_io_u[DDIR_TRIM])
Jens Axboeb3605062007-03-12 14:19:47 +0100293
Jens Axboe838bc702008-05-22 13:08:23 +0200294static void stat_calc_dist(unsigned int *map, unsigned long total,
295 double *io_u_dist)
Jens Axboe22708902007-03-06 17:05:32 +0100296{
297 int i;
298
299 /*
300 * Do depth distribution calculations
301 */
302 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200303 if (total) {
304 io_u_dist[i] = (double) map[i] / (double) total;
305 io_u_dist[i] *= 100.0;
306 if (io_u_dist[i] < 0.1 && map[i])
307 io_u_dist[i] = 0.1;
308 } else
309 io_u_dist[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100310 }
311}
312
Jens Axboe04a0fea2007-06-19 12:48:41 +0200313static void stat_calc_lat(struct thread_stat *ts, double *dst,
314 unsigned int *src, int nr)
Jens Axboe22708902007-03-06 17:05:32 +0100315{
Jens Axboe838bc702008-05-22 13:08:23 +0200316 unsigned long total = ts_total_io_u(ts);
Jens Axboe22708902007-03-06 17:05:32 +0100317 int i;
318
319 /*
320 * Do latency distribution calculations
321 */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200322 for (i = 0; i < nr; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200323 if (total) {
324 dst[i] = (double) src[i] / (double) total;
325 dst[i] *= 100.0;
326 if (dst[i] < 0.01 && src[i])
327 dst[i] = 0.01;
328 } else
329 dst[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100330 }
331}
332
Jens Axboe04a0fea2007-06-19 12:48:41 +0200333static void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
334{
335 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
336}
337
338static void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
339{
340 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
341}
342
Jens Axboeea2accc2007-06-19 09:48:44 +0200343static int usec_to_msec(unsigned long *min, unsigned long *max, double *mean,
344 double *dev)
345{
346 if (*min > 1000 && *max > 1000 && *mean > 1000.0 && *dev > 1000.0) {
347 *min /= 1000;
348 *max /= 1000;
349 *mean /= 1000.0;
350 *dev /= 1000.0;
351 return 0;
352 }
353
354 return 1;
355}
356
Jens Axboe756867b2007-03-06 15:19:24 +0100357static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
Jens Axboe3c39a372006-06-06 20:56:12 +0200358 int ddir)
359{
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200360 const char *ddir_str[] = { "read ", "write", "trim" };
Jens Axboe8879fd12009-04-20 10:06:02 +0200361 unsigned long min, max, runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100362 unsigned long long bw, iops;
Jens Axboe3c39a372006-06-06 20:56:12 +0200363 double mean, dev;
Jens Axboeb3605062007-03-12 14:19:47 +0100364 char *io_p, *bw_p, *iops_p;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200365 int i2p;
Jens Axboe3c39a372006-06-06 20:56:12 +0200366
Jens Axboeff58fce2010-08-25 12:02:08 +0200367 assert(ddir_rw(ddir));
368
Jens Axboe756867b2007-03-06 15:19:24 +0100369 if (!ts->runtime[ddir])
Jens Axboe3c39a372006-06-06 20:56:12 +0200370 return;
371
Jens Axboe90fef2d2009-07-17 22:33:32 +0200372 i2p = is_power_of_2(rs->kb_base);
Jens Axboe8879fd12009-04-20 10:06:02 +0200373 runt = ts->runtime[ddir];
374
375 bw = (1000 * ts->io_bytes[ddir]) / runt;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200376 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
377 bw_p = num2str(bw, 6, 1, i2p);
Jens Axboe8879fd12009-04-20 10:06:02 +0200378
Bruce Cran0aacc502011-07-09 08:19:53 +0200379 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100380 iops_p = num2str(iops, 6, 1, 0);
Jens Axboedbe11252007-02-11 00:19:51 +0100381
Signed-off-by Steven Prattcda99fa2010-12-14 08:31:36 +0100382 log_info(" %s: io=%sB, bw=%sB/s, iops=%s, runt=%6llumsec\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100383 ddir_str[ddir], io_p, bw_p, iops_p,
384 ts->runtime[ddir]);
Jens Axboedbe11252007-02-11 00:19:51 +0100385
386 free(io_p);
387 free(bw_p);
Jens Axboeb3605062007-03-12 14:19:47 +0100388 free(iops_p);
Jens Axboe3c39a372006-06-06 20:56:12 +0200389
Jens Axboed85f5112007-06-18 09:41:23 +0200390 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
391 const char *base = "(usec)";
Jens Axboed9309cb2007-08-16 13:07:46 +0200392 char *minp, *maxp;
Jens Axboe3c39a372006-06-06 20:56:12 +0200393
Jens Axboeea2accc2007-06-19 09:48:44 +0200394 if (!usec_to_msec(&min, &max, &mean, &dev))
Jens Axboed85f5112007-06-18 09:41:23 +0200395 base = "(msec)";
Jens Axboeea2accc2007-06-19 09:48:44 +0200396
Jens Axboed9309cb2007-08-16 13:07:46 +0200397 minp = num2str(min, 6, 1, 0);
398 maxp = num2str(max, 6, 1, 0);
399
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100400 log_info(" slat %s: min=%s, max=%s, avg=%5.02f,"
401 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
Jens Axboed9309cb2007-08-16 13:07:46 +0200402
403 free(minp);
404 free(maxp);
Jens Axboed85f5112007-06-18 09:41:23 +0200405 }
406 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
407 const char *base = "(usec)";
Jens Axboed9309cb2007-08-16 13:07:46 +0200408 char *minp, *maxp;
Jens Axboe3c39a372006-06-06 20:56:12 +0200409
Jens Axboeea2accc2007-06-19 09:48:44 +0200410 if (!usec_to_msec(&min, &max, &mean, &dev))
411 base = "(msec)";
412
Jens Axboed9309cb2007-08-16 13:07:46 +0200413 minp = num2str(min, 6, 1, 0);
414 maxp = num2str(max, 6, 1, 0);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100415
416 log_info(" clat %s: min=%s, max=%s, avg=%5.02f,"
417 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
Jens Axboed9309cb2007-08-16 13:07:46 +0200418
419 free(minp);
420 free(maxp);
Jens Axboed85f5112007-06-18 09:41:23 +0200421 }
Jens Axboe02af0982010-06-24 09:59:34 +0200422 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) {
423 const char *base = "(usec)";
424 char *minp, *maxp;
425
426 if (!usec_to_msec(&min, &max, &mean, &dev))
427 base = "(msec)";
428
429 minp = num2str(min, 6, 1, 0);
430 maxp = num2str(max, 6, 1, 0);
431
432 log_info(" lat %s: min=%s, max=%s, avg=%5.02f,"
433 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
434
435 free(minp);
436 free(maxp);
437 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200438 if (ts->clat_percentiles) {
439 show_clat_percentiles(ts->io_u_plat[ddir],
440 ts->clat_stat[ddir].samples,
441 ts->percentile_list);
442 }
Jens Axboe079ad092007-02-20 13:58:20 +0100443 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100444 double p_of_agg = 100.0;
Jens Axboeb7017e32011-10-14 09:30:01 +0200445 const char *bw_str = "KB";
Jens Axboe3c39a372006-06-06 20:56:12 +0200446
Jens Axboe2f2c6922012-02-07 16:42:43 +0100447 if (rs->agg[ddir]) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100448 p_of_agg = mean * 100 / (double) rs->agg[ddir];
449 if (p_of_agg > 100.0)
450 p_of_agg = 100.0;
451 }
Jens Axboeb7017e32011-10-14 09:30:01 +0200452
453 if (mean > 999999.9) {
454 min /= 1000.0;
455 max /= 1000.0;
456 mean /= 1000.0;
457 dev /= 1000.0;
458 bw_str = "MB";
459 }
460
Jens Axboe7e1773b2011-10-14 12:47:56 +0200461 log_info(" bw (%s/s) : min=%5lu, max=%5lu, per=%3.2f%%,"
Jens Axboeb7017e32011-10-14 09:30:01 +0200462 " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max,
463 p_of_agg, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200464 }
465}
466
Jens Axboe7e1773b2011-10-14 12:47:56 +0200467static int show_lat(double *io_u_lat, int nr, const char **ranges,
468 const char *msg)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200469{
Jens Axboe7e1773b2011-10-14 12:47:56 +0200470 int new_line = 1, i, line = 0, shown = 0;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200471
472 for (i = 0; i < nr; i++) {
473 if (io_u_lat[i] <= 0.0)
474 continue;
Jens Axboe7e1773b2011-10-14 12:47:56 +0200475 shown = 1;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200476 if (new_line) {
Jens Axboe4539ed72007-07-23 14:21:17 +0200477 if (line)
478 log_info("\n");
Jens Axboe7e1773b2011-10-14 12:47:56 +0200479 log_info(" lat (%s) : ", msg);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200480 new_line = 0;
481 line = 0;
482 }
483 if (line)
484 log_info(", ");
485 log_info("%s%3.2f%%", ranges[i], io_u_lat[i]);
486 line++;
487 if (line == 5)
488 new_line = 1;
489 }
Jens Axboe7e1773b2011-10-14 12:47:56 +0200490
491 if (shown)
492 log_info("\n");
493
494 return shown;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200495}
496
497static void show_lat_u(double *io_u_lat_u)
498{
499 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
500 "250=", "500=", "750=", "1000=", };
501
502 show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec");
503}
504
505static void show_lat_m(double *io_u_lat_m)
506{
507 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
508 "250=", "500=", "750=", "1000=", "2000=",
509 ">=2000=", };
510
511 show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec");
512}
513
514static void show_latencies(double *io_u_lat_u, double *io_u_lat_m)
515{
516 show_lat_u(io_u_lat_u);
517 show_lat_m(io_u_lat_m);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200518}
519
Jens Axboea64e88d2011-10-03 14:20:01 +0200520void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200521{
522 double usr_cpu, sys_cpu;
Jens Axboe69008992006-11-24 13:12:56 +0100523 unsigned long runtime;
Jens Axboe71619dc2007-01-13 23:56:33 +0100524 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200525 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
526 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboe57a64322012-06-14 15:11:15 +0200527 time_t time_p;
528 char time_buf[64];
Jens Axboe3c39a372006-06-06 20:56:12 +0200529
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200530 if (!(ts->io_bytes[DDIR_READ] + ts->io_bytes[DDIR_WRITE] +
531 ts->io_bytes[DDIR_TRIM]) && !(ts->total_io_u[DDIR_READ] +
532 ts->total_io_u[DDIR_WRITE] + ts->total_io_u[DDIR_TRIM]))
Jens Axboe3c39a372006-06-06 20:56:12 +0200533 return;
534
Jens Axboe57a64322012-06-14 15:11:15 +0200535 time(&time_p);
536 ctime_r((const time_t *) &time_p, time_buf);
537
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100538 if (!ts->error) {
Jens Axboe57a64322012-06-14 15:11:15 +0200539 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100540 ts->name, ts->groupid, ts->members,
Jens Axboe57a64322012-06-14 15:11:15 +0200541 ts->error, (int) ts->pid, time_buf);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100542 } else {
Jens Axboe57a64322012-06-14 15:11:15 +0200543 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100544 ts->name, ts->groupid, ts->members,
Jens Axboe57a64322012-06-14 15:11:15 +0200545 ts->error, ts->verror, (int) ts->pid,
546 time_buf);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100547 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200548
Jens Axboe259e47d2011-10-13 21:05:59 +0200549 if (strlen(ts->description))
Jens Axboe6d861442007-03-15 09:22:23 +0100550 log_info(" Description : [%s]\n", ts->description);
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100551
Jens Axboe756867b2007-03-06 15:19:24 +0100552 if (ts->io_bytes[DDIR_READ])
553 show_ddir_status(rs, ts, DDIR_READ);
554 if (ts->io_bytes[DDIR_WRITE])
555 show_ddir_status(rs, ts, DDIR_WRITE);
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200556 if (ts->io_bytes[DDIR_TRIM])
557 show_ddir_status(rs, ts, DDIR_TRIM);
Jens Axboe3c39a372006-06-06 20:56:12 +0200558
Jens Axboe7e1773b2011-10-14 12:47:56 +0200559 stat_calc_lat_u(ts, io_u_lat_u);
560 stat_calc_lat_m(ts, io_u_lat_m);
561 show_latencies(io_u_lat_u, io_u_lat_m);
562
Jens Axboe756867b2007-03-06 15:19:24 +0100563 runtime = ts->total_run_time;
Jens Axboe69008992006-11-24 13:12:56 +0100564 if (runtime) {
Jens Axboe1e97cce2006-12-05 11:44:16 +0100565 double runt = (double) runtime;
Jens Axboe3c39a372006-06-06 20:56:12 +0200566
Jens Axboe756867b2007-03-06 15:19:24 +0100567 usr_cpu = (double) ts->usr_time * 100 / runt;
568 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboe3c39a372006-06-06 20:56:12 +0200569 } else {
570 usr_cpu = 0;
571 sys_cpu = 0;
572 }
573
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100574 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu,"
575 " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf);
Jens Axboe71619dc2007-01-13 23:56:33 +0100576
Jens Axboe838bc702008-05-22 13:08:23 +0200577 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100578 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%,"
579 " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
580 io_u_dist[1], io_u_dist[2],
581 io_u_dist[3], io_u_dist[4],
582 io_u_dist[5], io_u_dist[6]);
Jens Axboe838bc702008-05-22 13:08:23 +0200583
584 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
585 log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
586 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
587 io_u_dist[1], io_u_dist[2],
588 io_u_dist[3], io_u_dist[4],
589 io_u_dist[5], io_u_dist[6]);
590 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
591 log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
592 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
593 io_u_dist[1], io_u_dist[2],
594 io_u_dist[3], io_u_dist[4],
595 io_u_dist[5], io_u_dist[6]);
Jens Axboe7e1773b2011-10-14 12:47:56 +0200596 log_info(" issued : total=r=%lu/w=%lu/d=%lu,"
597 " short=r=%lu/w=%lu/d=%lu\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100598 ts->total_io_u[0], ts->total_io_u[1],
Jens Axboe0d29de82010-09-01 13:54:15 +0200599 ts->total_io_u[2],
600 ts->short_io_u[0], ts->short_io_u[1],
601 ts->short_io_u[2]);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200602 if (ts->continue_on_error) {
Jens Axboe1ec99ee2009-06-15 12:37:30 +0200603 log_info(" errors : total=%lu, first_error=%d/<%s>\n",
604 ts->total_err_count,
605 ts->first_error,
606 strerror(ts->first_error));
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200607 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200608}
609
Jens Axboe756867b2007-03-06 15:19:24 +0100610static void show_ddir_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200611 struct group_run_stats *rs, int ddir)
612{
613 unsigned long min, max;
Jens Axboe312b4af2011-10-13 13:11:42 +0200614 unsigned long long bw, iops;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200615 unsigned int *ovals = NULL;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200616 double mean, dev;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200617 unsigned int len, minv, maxv;
618 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200619
Jens Axboeff58fce2010-08-25 12:02:08 +0200620 assert(ddir_rw(ddir));
621
Jens Axboe312b4af2011-10-13 13:11:42 +0200622 iops = bw = 0;
623 if (ts->runtime[ddir]) {
624 uint64_t runt = ts->runtime[ddir];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200625
Jens Axboe033bbb52012-05-07 09:46:40 +0200626 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
Jens Axboe312b4af2011-10-13 13:11:42 +0200627 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
628 }
629
630 log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops,
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100631 ts->runtime[ddir]);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200632
Jens Axboe079ad092007-02-20 13:58:20 +0100633 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100634 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200635 else
Jens Axboe6d861442007-03-15 09:22:23 +0100636 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200637
Jens Axboe079ad092007-02-20 13:58:20 +0100638 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100639 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200640 else
Jens Axboe6d861442007-03-15 09:22:23 +0100641 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200642
Jens Axboe1db92cb2011-10-13 13:43:36 +0200643 if (ts->clat_percentiles) {
644 len = calc_clat_percentiles(ts->io_u_plat[ddir],
645 ts->clat_stat[ddir].samples,
646 ts->percentile_list, &ovals, &maxv,
647 &minv);
648 } else
649 len = 0;
650
651 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
652 if (i >= len) {
653 log_info(";0%%=0");
654 continue;
655 }
656 log_info(";%2.2f%%=%u", ts->percentile_list[i].u.f, ovals[i]);
657 }
Keplar kramer2341a372011-10-19 21:31:27 +0200658
659 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
660 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
661 else
662 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
663
Jens Axboe1db92cb2011-10-13 13:43:36 +0200664 if (ovals)
665 free(ovals);
666
Jens Axboe079ad092007-02-20 13:58:20 +0100667 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100668 double p_of_agg = 100.0;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200669
Jens Axboe19d3e962012-02-07 12:27:28 +0100670 if (rs->agg[ddir]) {
671 p_of_agg = mean * 100 / (double) rs->agg[ddir];
672 if (p_of_agg > 100.0)
673 p_of_agg = 100.0;
674 }
675
Jens Axboe6d861442007-03-15 09:22:23 +0100676 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200677 } else
Jens Axboe6d861442007-03-15 09:22:23 +0100678 log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200679}
680
Jens Axboe4d658652011-10-17 15:05:47 +0200681static void show_thread_status_terse_v2(struct thread_stat *ts,
682 struct group_run_stats *rs)
683{
684 double io_u_dist[FIO_IO_U_MAP_NR];
685 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
686 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
687 double usr_cpu, sys_cpu;
688 int i;
689
690 /* General Info */
691 log_info("2;%s;%d;%d", ts->name, ts->groupid, ts->error);
692 /* Log Read Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200693 show_ddir_status_terse(ts, rs, DDIR_READ);
Jens Axboe4d658652011-10-17 15:05:47 +0200694 /* Log Write Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200695 show_ddir_status_terse(ts, rs, DDIR_WRITE);
696 /* Log Trim Status */
697 show_ddir_status_terse(ts, rs, DDIR_TRIM);
Jens Axboe4d658652011-10-17 15:05:47 +0200698
699 /* CPU Usage */
700 if (ts->total_run_time) {
701 double runt = (double) ts->total_run_time;
702
703 usr_cpu = (double) ts->usr_time * 100 / runt;
704 sys_cpu = (double) ts->sys_time * 100 / runt;
705 } else {
706 usr_cpu = 0;
707 sys_cpu = 0;
708 }
709
710 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
711 ts->minf);
712
713 /* Calc % distribution of IO depths, usecond, msecond latency */
714 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
715 stat_calc_lat_u(ts, io_u_lat_u);
716 stat_calc_lat_m(ts, io_u_lat_m);
717
718 /* Only show fixed 7 I/O depth levels*/
719 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
720 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
721 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
722
723 /* Microsecond latency */
724 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
725 log_info(";%3.2f%%", io_u_lat_u[i]);
726 /* Millisecond latency */
727 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
728 log_info(";%3.2f%%", io_u_lat_m[i]);
729 /* Additional output if continue_on_error set - default off*/
730 if (ts->continue_on_error)
731 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
732 log_info("\n");
733
734 /* Additional output if description is set */
735 if (ts->description)
736 log_info(";%s", ts->description);
737
738 log_info("\n");
739}
740
Jens Axboe312b4af2011-10-13 13:11:42 +0200741#define FIO_TERSE_VERSION "3"
Jens Axboec6ae0a52006-06-12 11:04:44 +0200742
Jens Axboe4d658652011-10-17 15:05:47 +0200743static void show_thread_status_terse_v3(struct thread_stat *ts,
744 struct group_run_stats *rs)
Jens Axboec6ae0a52006-06-12 11:04:44 +0200745{
Jens Axboe22708902007-03-06 17:05:32 +0100746 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200747 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
748 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200749 double usr_cpu, sys_cpu;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200750 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200751
David Nellans562c2d22010-09-23 08:38:17 +0200752 /* General Info */
Jens Axboe5e726d02011-10-14 08:08:10 +0200753 log_info("%s;%s;%s;%d;%d", FIO_TERSE_VERSION, fio_version_string,
754 ts->name, ts->groupid, ts->error);
David Nellans562c2d22010-09-23 08:38:17 +0200755 /* Log Read Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200756 show_ddir_status_terse(ts, rs, DDIR_READ);
David Nellans562c2d22010-09-23 08:38:17 +0200757 /* Log Write Status */
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200758 show_ddir_status_terse(ts, rs, DDIR_WRITE);
759 /* Log Trim Status */
760 show_ddir_status_terse(ts, rs, DDIR_TRIM);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200761
David Nellans562c2d22010-09-23 08:38:17 +0200762 /* CPU Usage */
Jens Axboe756867b2007-03-06 15:19:24 +0100763 if (ts->total_run_time) {
764 double runt = (double) ts->total_run_time;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200765
Jens Axboe756867b2007-03-06 15:19:24 +0100766 usr_cpu = (double) ts->usr_time * 100 / runt;
767 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200768 } else {
769 usr_cpu = 0;
770 sys_cpu = 0;
771 }
772
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100773 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
774 ts->minf);
Jens Axboe22708902007-03-06 17:05:32 +0100775
David Nellans562c2d22010-09-23 08:38:17 +0200776 /* Calc % distribution of IO depths, usecond, msecond latency */
Jens Axboe838bc702008-05-22 13:08:23 +0200777 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200778 stat_calc_lat_u(ts, io_u_lat_u);
779 stat_calc_lat_m(ts, io_u_lat_m);
Jens Axboe22708902007-03-06 17:05:32 +0100780
David Nellans562c2d22010-09-23 08:38:17 +0200781 /* Only show fixed 7 I/O depth levels*/
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100782 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
783 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
784 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
Jens Axboe22708902007-03-06 17:05:32 +0100785
David Nellans562c2d22010-09-23 08:38:17 +0200786 /* Microsecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200787 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
788 log_info(";%3.2f%%", io_u_lat_u[i]);
David Nellans562c2d22010-09-23 08:38:17 +0200789 /* Millisecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200790 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
791 log_info(";%3.2f%%", io_u_lat_m[i]);
Jens Axboef2f788d2011-10-13 14:03:52 +0200792
793 /* disk util stats, if any */
794 show_disk_util(1);
795
David Nellans562c2d22010-09-23 08:38:17 +0200796 /* Additional output if continue_on_error set - default off*/
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200797 if (ts->continue_on_error)
798 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
Jens Axboe22708902007-03-06 17:05:32 +0100799
David Nellans562c2d22010-09-23 08:38:17 +0200800 /* Additional output if description is set */
Jens Axboe4b0f2252011-10-13 15:03:25 +0200801 if (strlen(ts->description))
Jens Axboe946e4272012-03-23 19:22:21 +0100802 log_info(";%s", ts->description);
803
804 log_info("\n");
Jens Axboe756867b2007-03-06 15:19:24 +0100805}
806
Jens Axboe4d658652011-10-17 15:05:47 +0200807static void show_thread_status_terse(struct thread_stat *ts,
808 struct group_run_stats *rs)
809{
810 if (terse_version == 2)
811 show_thread_status_terse_v2(ts, rs);
812 else if (terse_version == 3)
813 show_thread_status_terse_v3(ts, rs);
814 else
815 log_err("fio: bad terse version!? %d\n", terse_version);
816}
817
Jens Axboe197574e2007-03-08 15:35:11 +0100818static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
Jens Axboe756867b2007-03-06 15:19:24 +0100819{
820 double mean, S;
821
Zheng Liue09231c2011-09-16 08:20:12 +0200822 if (src->samples == 0)
823 return;
824
Jens Axboe756867b2007-03-06 15:19:24 +0100825 dst->min_val = min(dst->min_val, src->min_val);
826 dst->max_val = max(dst->max_val, src->max_val);
Jens Axboe756867b2007-03-06 15:19:24 +0100827
828 /*
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200829 * Compute new mean and S after the merge
830 * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
831 * #Parallel_algorithm>
Jens Axboe756867b2007-03-06 15:19:24 +0100832 */
833 if (nr == 1) {
Jens Axboe802ad4a2011-10-05 09:51:58 +0200834 mean = src->mean.u.f;
835 S = src->S.u.f;
Jens Axboe756867b2007-03-06 15:19:24 +0100836 } else {
Jens Axboe802ad4a2011-10-05 09:51:58 +0200837 double delta = src->mean.u.f - dst->mean.u.f;
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200838
Jens Axboe802ad4a2011-10-05 09:51:58 +0200839 mean = ((src->mean.u.f * src->samples) +
840 (dst->mean.u.f * dst->samples)) /
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200841 (dst->samples + src->samples);
842
Jens Axboe802ad4a2011-10-05 09:51:58 +0200843 S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) *
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200844 (dst->samples * src->samples) /
845 (dst->samples + src->samples);
Jens Axboe756867b2007-03-06 15:19:24 +0100846 }
847
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200848 dst->samples += src->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200849 dst->mean.u.f = mean;
850 dst->S.u.f = S;
Jens Axboe756867b2007-03-06 15:19:24 +0100851}
852
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200853void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src)
854{
855 int i;
856
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200857 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200858 if (dst->max_run[i] < src->max_run[i])
859 dst->max_run[i] = src->max_run[i];
860 if (dst->min_run[i] && dst->min_run[i] > src->min_run[i])
861 dst->min_run[i] = src->min_run[i];
862 if (dst->max_bw[i] < src->max_bw[i])
863 dst->max_bw[i] = src->max_bw[i];
864 if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i])
865 dst->min_bw[i] = src->min_bw[i];
866
867 dst->io_kb[i] += src->io_kb[i];
868 dst->agg[i] += src->agg[i];
869 }
870
871}
872
Jens Axboe5b9babb2011-10-10 12:14:30 +0200873void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr)
874{
875 int l, k;
876
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200877 for (l = 0; l < DDIR_RWDIR_CNT; l++) {
Jens Axboe5b9babb2011-10-10 12:14:30 +0200878 sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr);
879 sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr);
880 sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr);
881 sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr);
882
883 dst->io_bytes[l] += src->io_bytes[l];
884
885 if (dst->runtime[l] < src->runtime[l])
886 dst->runtime[l] = src->runtime[l];
887 }
888
889 dst->usr_time += src->usr_time;
890 dst->sys_time += src->sys_time;
891 dst->ctx += src->ctx;
892 dst->majf += src->majf;
893 dst->minf += src->minf;
894
895 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
896 dst->io_u_map[k] += src->io_u_map[k];
897 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
898 dst->io_u_submit[k] += src->io_u_submit[k];
899 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
900 dst->io_u_complete[k] += src->io_u_complete[k];
901 for (k = 0; k < FIO_IO_U_LAT_U_NR; k++)
902 dst->io_u_lat_u[k] += src->io_u_lat_u[k];
903 for (k = 0; k < FIO_IO_U_LAT_M_NR; k++)
904 dst->io_u_lat_m[k] += src->io_u_lat_m[k];
905
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200906 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
Jens Axboe5b9babb2011-10-10 12:14:30 +0200907 dst->total_io_u[k] += src->total_io_u[k];
908 dst->short_io_u[k] += src->short_io_u[k];
909 }
910
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200911 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
Jens Axboe5b9babb2011-10-10 12:14:30 +0200912 int m;
913 for (m = 0; m < FIO_IO_U_PLAT_NR; m++)
914 dst->io_u_plat[k][m] += src->io_u_plat[k][m];
915 }
916
917 dst->total_run_time += src->total_run_time;
918 dst->total_submit += src->total_submit;
919 dst->total_complete += src->total_complete;
920}
921
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200922void init_group_run_stat(struct group_run_stats *gs)
923{
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200924 int i;
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200925 memset(gs, 0, sizeof(*gs));
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200926
927 for (i = 0; i < DDIR_RWDIR_CNT; i++)
928 gs->min_bw[i] = gs->min_run[i] = ~0UL;
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200929}
930
931void init_thread_stat(struct thread_stat *ts)
932{
933 int j;
934
935 memset(ts, 0, sizeof(*ts));
936
Shaohua Li6eaf09d2012-09-14 08:49:43 +0200937 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200938 ts->lat_stat[j].min_val = -1UL;
939 ts->clat_stat[j].min_val = -1UL;
940 ts->slat_stat[j].min_val = -1UL;
941 ts->bw_stat[j].min_val = -1UL;
942 }
943 ts->groupid = -1;
944}
945
Jens Axboe3c39a372006-06-06 20:56:12 +0200946void show_run_stats(void)
947{
948 struct group_run_stats *runstats, *rs;
949 struct thread_data *td;
Jens Axboe756867b2007-03-06 15:19:24 +0100950 struct thread_stat *threadstats, *ts;
Jens Axboe5b9babb2011-10-10 12:14:30 +0200951 int i, j, nr_ts, last_ts, idx;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200952 int kb_base_warned = 0;
Jens Axboe3c39a372006-06-06 20:56:12 +0200953
954 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
955
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200956 for (i = 0; i < groupid + 1; i++)
957 init_group_run_stat(&runstats[i]);
Jens Axboe3c39a372006-06-06 20:56:12 +0200958
Jens Axboe756867b2007-03-06 15:19:24 +0100959 /*
960 * find out how many threads stats we need. if group reporting isn't
961 * enabled, it's one-per-td.
962 */
963 nr_ts = 0;
964 last_ts = -1;
Jens Axboe34572e22006-10-20 09:33:18 +0200965 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100966 if (!td->o.group_reporting) {
Jens Axboe756867b2007-03-06 15:19:24 +0100967 nr_ts++;
968 continue;
969 }
970 if (last_ts == td->groupid)
971 continue;
972
973 last_ts = td->groupid;
974 nr_ts++;
975 }
976
977 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
978
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200979 for (i = 0; i < nr_ts; i++)
980 init_thread_stat(&threadstats[i]);
Jens Axboe756867b2007-03-06 15:19:24 +0100981
982 j = 0;
983 last_ts = -1;
Jens Axboe197574e2007-03-08 15:35:11 +0100984 idx = 0;
Jens Axboe756867b2007-03-06 15:19:24 +0100985 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100986 if (idx && (!td->o.group_reporting ||
987 (td->o.group_reporting && last_ts != td->groupid))) {
Jens Axboe7abd0e32007-03-12 15:24:43 +0100988 idx = 0;
989 j++;
990 }
991
992 last_ts = td->groupid;
993
Jens Axboe756867b2007-03-06 15:19:24 +0100994 ts = &threadstats[j];
995
Yu-ju Hong83349192011-08-13 00:53:44 +0200996 ts->clat_percentiles = td->o.clat_percentiles;
997 if (td->o.overwrite_plist)
Jens Axboe802ad4a2011-10-05 09:51:58 +0200998 memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +0200999 else
Jens Axboe802ad4a2011-10-05 09:51:58 +02001000 memcpy(ts->percentile_list, def_percentile_list, sizeof(def_percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +02001001
Jens Axboe197574e2007-03-08 15:35:11 +01001002 idx++;
Jens Axboe6586ee82007-03-06 19:46:09 +01001003 ts->members++;
Jens Axboe756867b2007-03-06 15:19:24 +01001004
Jens Axboe7abd0e32007-03-12 15:24:43 +01001005 if (ts->groupid == -1) {
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001006 /*
1007 * These are per-group shared already
1008 */
Jens Axboef6bb5b82011-10-03 12:21:25 +02001009 strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE);
Jens Axboea64e88d2011-10-03 14:20:01 +02001010 if (td->o.description)
1011 strncpy(ts->description, td->o.description,
1012 FIO_JOBNAME_SIZE);
1013 else
1014 memset(ts->description, 0, FIO_JOBNAME_SIZE);
1015
Jens Axboe756867b2007-03-06 15:19:24 +01001016 ts->groupid = td->groupid;
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001017
1018 /*
1019 * first pid in group, not very useful...
1020 */
Jens Axboe756867b2007-03-06 15:19:24 +01001021 ts->pid = td->pid;
Jens Axboe90fef2d2009-07-17 22:33:32 +02001022
1023 ts->kb_base = td->o.kb_base;
1024 } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) {
1025 log_info("fio: kb_base differs for jobs in group, using"
1026 " %u as the base\n", ts->kb_base);
1027 kb_base_warned = 1;
Jens Axboe2dc84ba2007-03-06 15:46:33 +01001028 }
1029
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001030 ts->continue_on_error = td->o.continue_on_error;
1031 ts->total_err_count += td->total_err_count;
1032 ts->first_error = td->first_error;
1033 if (!ts->error) {
1034 if (!td->error && td->o.continue_on_error &&
1035 td->first_error) {
1036 ts->error = td->first_error;
Jens Axboef6bb5b82011-10-03 12:21:25 +02001037 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001038 } else if (td->error) {
1039 ts->error = td->error;
Jens Axboef6bb5b82011-10-03 12:21:25 +02001040 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +02001041 }
Jens Axboe756867b2007-03-06 15:19:24 +01001042 }
1043
Jens Axboe5b9babb2011-10-10 12:14:30 +02001044 sum_thread_stats(ts, &td->ts, idx);
Jens Axboe756867b2007-03-06 15:19:24 +01001045 }
1046
1047 for (i = 0; i < nr_ts; i++) {
Jens Axboe94370ac2007-03-08 15:28:10 +01001048 unsigned long long bw;
Jens Axboe3c39a372006-06-06 20:56:12 +02001049
Jens Axboe756867b2007-03-06 15:19:24 +01001050 ts = &threadstats[i];
1051 rs = &runstats[ts->groupid];
Jens Axboe90fef2d2009-07-17 22:33:32 +02001052 rs->kb_base = ts->kb_base;
Jens Axboe3c39a372006-06-06 20:56:12 +02001053
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001054 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
Jens Axboe94370ac2007-03-08 15:28:10 +01001055 if (!ts->runtime[j])
1056 continue;
1057 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
1058 rs->min_run[j] = ts->runtime[j];
1059 if (ts->runtime[j] > rs->max_run[j])
1060 rs->max_run[j] = ts->runtime[j];
Jens Axboe3c39a372006-06-06 20:56:12 +02001061
Jens Axboe94370ac2007-03-08 15:28:10 +01001062 bw = 0;
Jens Axboe8879fd12009-04-20 10:06:02 +02001063 if (ts->runtime[j]) {
Jens Axboec857cfe2012-04-05 08:42:11 -06001064 unsigned long runt = ts->runtime[j];
1065 unsigned long long kb;
Jens Axboe8879fd12009-04-20 10:06:02 +02001066
Jens Axboec857cfe2012-04-05 08:42:11 -06001067 kb = ts->io_bytes[j] / rs->kb_base;
1068 bw = kb * 1000 / runt;
Jens Axboe8879fd12009-04-20 10:06:02 +02001069 }
Jens Axboe94370ac2007-03-08 15:28:10 +01001070 if (bw < rs->min_bw[j])
1071 rs->min_bw[j] = bw;
1072 if (bw > rs->max_bw[j])
1073 rs->max_bw[j] = bw;
Jens Axboe3c39a372006-06-06 20:56:12 +02001074
Jens Axboe90fef2d2009-07-17 22:33:32 +02001075 rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base;
Jens Axboe94370ac2007-03-08 15:28:10 +01001076 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001077 }
1078
1079 for (i = 0; i < groupid + 1; i++) {
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001080 int ddir;
1081
Jens Axboe3c39a372006-06-06 20:56:12 +02001082 rs = &runstats[i];
1083
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001084 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
1085 if (rs->max_run[ddir])
1086 rs->agg[ddir] = (rs->io_kb[ddir] * 1000) /
1087 rs->max_run[ddir];
1088 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001089 }
1090
1091 /*
1092 * don't overwrite last signal output
1093 */
Jens Axboec6ae0a52006-06-12 11:04:44 +02001094 if (!terse_output)
Jens Axboe4ceb30d2010-02-24 09:19:14 +01001095 log_info("\n");
Jens Axboe3c39a372006-06-06 20:56:12 +02001096
Jens Axboe756867b2007-03-06 15:19:24 +01001097 for (i = 0; i < nr_ts; i++) {
1098 ts = &threadstats[i];
1099 rs = &runstats[ts->groupid];
Jens Axboe3c39a372006-06-06 20:56:12 +02001100
Jens Axboea64e88d2011-10-03 14:20:01 +02001101 if (is_backend)
1102 fio_server_send_ts(ts, rs);
1103 else if (terse_output)
Jens Axboe756867b2007-03-06 15:19:24 +01001104 show_thread_status_terse(ts, rs);
Jens Axboec6ae0a52006-06-12 11:04:44 +02001105 else
Jens Axboe756867b2007-03-06 15:19:24 +01001106 show_thread_status(ts, rs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001107 }
1108
Jens Axboe72c27ff2011-10-16 11:50:31 +02001109 for (i = 0; i < groupid + 1; i++) {
1110 rs = &runstats[i];
Jens Axboea64e88d2011-10-03 14:20:01 +02001111
Jens Axboe72c27ff2011-10-16 11:50:31 +02001112 rs->groupid = i;
Jens Axboed09a64a2011-10-13 11:38:56 +02001113 if (is_backend)
Jens Axboe72c27ff2011-10-16 11:50:31 +02001114 fio_server_send_gs(rs);
1115 else if (!terse_output)
1116 show_group_stats(rs);
Jens Axboec6ae0a52006-06-12 11:04:44 +02001117 }
Jens Axboeeecf2722006-10-20 14:00:36 +02001118
Jens Axboe72c27ff2011-10-16 11:50:31 +02001119 if (is_backend)
1120 fio_server_send_du();
1121 else if (!terse_output)
1122 show_disk_util(0);
1123
Jens Axboeeecf2722006-10-20 14:00:36 +02001124 free(runstats);
Jens Axboe756867b2007-03-06 15:19:24 +01001125 free(threadstats);
Jens Axboe3c39a372006-06-06 20:56:12 +02001126}
1127
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001128static void *__show_running_run_stats(void *arg)
1129{
1130 struct thread_data *td;
1131 unsigned long long *rt;
1132 struct timeval tv;
1133 int i;
1134
1135 rt = malloc(thread_number * sizeof(unsigned long long));
1136 fio_gettime(&tv, NULL);
1137
1138 for_each_td(td, i) {
1139 rt[i] = mtime_since(&td->start, &tv);
1140 if (td_read(td) && td->io_bytes[DDIR_READ])
1141 td->ts.runtime[DDIR_READ] += rt[i];
1142 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1143 td->ts.runtime[DDIR_WRITE] += rt[i];
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001144 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1145 td->ts.runtime[DDIR_TRIM] += rt[i];
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001146
1147 update_rusage_stat(td);
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001148 td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ];
1149 td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
1150 td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001151 td->ts.total_run_time = mtime_since(&td->epoch, &tv);
1152 }
1153
1154 show_run_stats();
1155
1156 for_each_td(td, i) {
1157 if (td_read(td) && td->io_bytes[DDIR_READ])
1158 td->ts.runtime[DDIR_READ] -= rt[i];
1159 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1160 td->ts.runtime[DDIR_WRITE] -= rt[i];
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001161 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1162 td->ts.runtime[DDIR_TRIM] -= rt[i];
Jens Axboe4c6d91e2012-03-30 10:30:35 +02001163 }
1164
1165 free(rt);
1166 return NULL;
1167}
1168
1169/*
1170 * Called from signal handler. It _should_ be safe to just run this inline
1171 * in the sig handler, but we should be disturbing the system less by just
1172 * creating a thread to do it.
1173 */
1174void show_running_run_stats(void)
1175{
1176 pthread_t thread;
1177
1178 pthread_create(&thread, NULL, __show_running_run_stats, NULL);
1179 pthread_detach(thread);
1180}
1181
Jens Axboe68704082007-01-10 19:56:37 +01001182static inline void add_stat_sample(struct io_stat *is, unsigned long data)
Jens Axboe3c39a372006-06-06 20:56:12 +02001183{
Jens Axboe68704082007-01-10 19:56:37 +01001184 double val = data;
Jens Axboe6660cc62007-03-06 15:48:38 +01001185 double delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001186
Jens Axboe68704082007-01-10 19:56:37 +01001187 if (data > is->max_val)
1188 is->max_val = data;
1189 if (data < is->min_val)
1190 is->min_val = data;
1191
Jens Axboe802ad4a2011-10-05 09:51:58 +02001192 delta = val - is->mean.u.f;
Jens Axboeef11d732007-03-29 15:36:29 +02001193 if (delta) {
Jens Axboe802ad4a2011-10-05 09:51:58 +02001194 is->mean.u.f += delta / (is->samples + 1.0);
1195 is->S.u.f += delta * (val - is->mean.u.f);
Jens Axboeef11d732007-03-29 15:36:29 +02001196 }
Jens Axboe68704082007-01-10 19:56:37 +01001197
Jens Axboe3c39a372006-06-06 20:56:12 +02001198 is->samples++;
1199}
1200
Jens Axboebb3884d2007-01-17 17:23:11 +11001201static void __add_log_sample(struct io_log *iolog, unsigned long val,
Jens Axboe306ddc92009-05-18 13:08:12 +02001202 enum fio_ddir ddir, unsigned int bs,
Jens Axboe2b13e712011-01-19 14:04:16 -07001203 unsigned long t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001204{
Jens Axboe306ddc92009-05-18 13:08:12 +02001205 const int nr_samples = iolog->nr_samples;
1206
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001207 if (!iolog->nr_samples)
1208 iolog->avg_last = t;
1209
Jens Axboe3c39a372006-06-06 20:56:12 +02001210 if (iolog->nr_samples == iolog->max_samples) {
1211 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
1212
1213 iolog->log = realloc(iolog->log, new_size);
1214 iolog->max_samples <<= 1;
1215 }
1216
Jens Axboe306ddc92009-05-18 13:08:12 +02001217 iolog->log[nr_samples].val = val;
Jens Axboe2b13e712011-01-19 14:04:16 -07001218 iolog->log[nr_samples].time = t;
Jens Axboe306ddc92009-05-18 13:08:12 +02001219 iolog->log[nr_samples].ddir = ddir;
1220 iolog->log[nr_samples].bs = bs;
Jens Axboe3c39a372006-06-06 20:56:12 +02001221 iolog->nr_samples++;
1222}
1223
Jens Axboe7fb28d32011-12-01 15:17:24 +01001224static inline void reset_io_stat(struct io_stat *ios)
1225{
1226 ios->max_val = ios->min_val = ios->samples = 0;
1227 ios->mean.u.f = ios->S.u.f = 0;
1228}
1229
Jens Axboebb3884d2007-01-17 17:23:11 +11001230static void add_log_sample(struct thread_data *td, struct io_log *iolog,
Jens Axboe306ddc92009-05-18 13:08:12 +02001231 unsigned long val, enum fio_ddir ddir,
1232 unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001233{
Jens Axboe7fb28d32011-12-01 15:17:24 +01001234 unsigned long elapsed, this_window;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001235
Jens Axboeff58fce2010-08-25 12:02:08 +02001236 if (!ddir_rw(ddir))
1237 return;
1238
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001239 elapsed = mtime_since_now(&td->epoch);
1240
1241 /*
1242 * If no time averaging, just add the log sample.
1243 */
1244 if (!iolog->avg_msec) {
1245 __add_log_sample(iolog, val, ddir, bs, elapsed);
1246 return;
1247 }
1248
1249 /*
1250 * Add the sample. If the time period has passed, then
1251 * add that entry to the log and clear.
1252 */
1253 add_stat_sample(&iolog->avg_window[ddir], val);
1254
Jens Axboe7fb28d32011-12-01 15:17:24 +01001255 /*
1256 * If period hasn't passed, adding the above sample is all we
1257 * need to do.
1258 */
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001259 this_window = elapsed - iolog->avg_last;
1260 if (this_window < iolog->avg_msec)
1261 return;
1262
Jens Axboe7fb28d32011-12-01 15:17:24 +01001263 /*
1264 * Note an entry in the log. Use the mean from the logged samples,
1265 * making sure to properly round up. Only write a log entry if we
1266 * had actual samples done.
1267 */
1268 if (iolog->avg_window[DDIR_READ].samples) {
1269 unsigned long mr;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001270
Jens Axboe7fb28d32011-12-01 15:17:24 +01001271 mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001272 __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed);
Jens Axboe7fb28d32011-12-01 15:17:24 +01001273 }
1274 if (iolog->avg_window[DDIR_WRITE].samples) {
1275 unsigned long mw;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001276
Jens Axboe7fb28d32011-12-01 15:17:24 +01001277 mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50;
1278 __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed);
1279 }
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001280 if (iolog->avg_window[DDIR_TRIM].samples) {
1281 unsigned long mw;
1282
1283 mw = iolog->avg_window[DDIR_TRIM].mean.u.f + 0.50;
1284 __add_log_sample(iolog, mw, DDIR_TRIM, 0, elapsed);
1285 }
1286
Jens Axboe7fb28d32011-12-01 15:17:24 +01001287
1288 reset_io_stat(&iolog->avg_window[DDIR_READ]);
1289 reset_io_stat(&iolog->avg_window[DDIR_WRITE]);
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001290 reset_io_stat(&iolog->avg_window[DDIR_TRIM]);
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001291 iolog->avg_last = elapsed;
Jens Axboebb3884d2007-01-17 17:23:11 +11001292}
1293
Jens Axboe306ddc92009-05-18 13:08:12 +02001294void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001295{
Jens Axboeff58fce2010-08-25 12:02:08 +02001296 struct io_log *iolog;
Jens Axboebb3884d2007-01-17 17:23:11 +11001297
Jens Axboeff58fce2010-08-25 12:02:08 +02001298 if (!ddir_rw(ddir))
1299 return;
1300
1301 iolog = agg_io_log[ddir];
Jens Axboe306ddc92009-05-18 13:08:12 +02001302 __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis());
Jens Axboebb3884d2007-01-17 17:23:11 +11001303}
1304
Yu-ju Hong83349192011-08-13 00:53:44 +02001305static void add_clat_percentile_sample(struct thread_stat *ts,
1306 unsigned long usec, enum fio_ddir ddir)
1307{
1308 unsigned int idx = plat_val_to_idx(usec);
1309 assert(idx < FIO_IO_U_PLAT_NR);
1310
1311 ts->io_u_plat[ddir][idx]++;
1312}
1313
Jens Axboe1e97cce2006-12-05 11:44:16 +01001314void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001315 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001316{
Jens Axboe756867b2007-03-06 15:19:24 +01001317 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001318
Jens Axboeff58fce2010-08-25 12:02:08 +02001319 if (!ddir_rw(ddir))
1320 return;
1321
Jens Axboed85f5112007-06-18 09:41:23 +02001322 add_stat_sample(&ts->clat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001323
Jens Axboe7b9f7332011-10-03 10:06:44 +02001324 if (td->clat_log)
1325 add_log_sample(td, td->clat_log, usec, ddir, bs);
Yu-ju Hong83349192011-08-13 00:53:44 +02001326
1327 if (ts->clat_percentiles)
1328 add_clat_percentile_sample(ts, usec, ddir);
Jens Axboe3c39a372006-06-06 20:56:12 +02001329}
1330
Jens Axboe1e97cce2006-12-05 11:44:16 +01001331void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001332 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001333{
Jens Axboe756867b2007-03-06 15:19:24 +01001334 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001335
Jens Axboeff58fce2010-08-25 12:02:08 +02001336 if (!ddir_rw(ddir))
1337 return;
1338
Jens Axboed85f5112007-06-18 09:41:23 +02001339 add_stat_sample(&ts->slat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001340
Jens Axboe7b9f7332011-10-03 10:06:44 +02001341 if (td->slat_log)
1342 add_log_sample(td, td->slat_log, usec, ddir, bs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001343}
1344
Jens Axboe02af0982010-06-24 09:59:34 +02001345void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
1346 unsigned long usec, unsigned int bs)
1347{
1348 struct thread_stat *ts = &td->ts;
1349
Jens Axboeff58fce2010-08-25 12:02:08 +02001350 if (!ddir_rw(ddir))
1351 return;
1352
Jens Axboe02af0982010-06-24 09:59:34 +02001353 add_stat_sample(&ts->lat_stat[ddir], usec);
1354
Jens Axboe7b9f7332011-10-03 10:06:44 +02001355 if (td->lat_log)
1356 add_log_sample(td, td->lat_log, usec, ddir, bs);
Jens Axboe02af0982010-06-24 09:59:34 +02001357}
1358
Jens Axboe306ddc92009-05-18 13:08:12 +02001359void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
Jens Axboe1e97cce2006-12-05 11:44:16 +01001360 struct timeval *t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001361{
Jens Axboe756867b2007-03-06 15:19:24 +01001362 struct thread_stat *ts = &td->ts;
Jens Axboeff58fce2010-08-25 12:02:08 +02001363 unsigned long spent, rate;
Jens Axboe3c39a372006-06-06 20:56:12 +02001364
Jens Axboeff58fce2010-08-25 12:02:08 +02001365 if (!ddir_rw(ddir))
1366 return;
1367
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001368 spent = mtime_since(&td->bw_sample_time, t);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001369 if (spent < td->o.bw_avg_time)
Jens Axboe3c39a372006-06-06 20:56:12 +02001370 return;
Jens Axboe9602d8d2012-02-20 20:19:28 +01001371
1372 /*
Josh Carter5daa4eb2012-02-20 10:12:22 +01001373 * Compute both read and write rates for the interval.
1374 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001375 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
Josh Carter5daa4eb2012-02-20 10:12:22 +01001376 uint64_t delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001377
Josh Carter5daa4eb2012-02-20 10:12:22 +01001378 delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir];
1379 if (!delta)
1380 continue; /* No entries for interval */
Jens Axboe3c39a372006-06-06 20:56:12 +02001381
Josh Carter5daa4eb2012-02-20 10:12:22 +01001382 rate = delta * 1000 / spent / 1024;
1383 add_stat_sample(&ts->bw_stat[ddir], rate);
1384
1385 if (td->bw_log)
1386 add_log_sample(td, td->bw_log, rate, ddir, bs);
1387
1388 td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
1389 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001390
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001391 fio_gettime(&td->bw_sample_time, NULL);
Jens Axboe3c39a372006-06-06 20:56:12 +02001392}
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001393
1394void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,
1395 struct timeval *t)
1396{
1397 struct thread_stat *ts = &td->ts;
1398 unsigned long spent, iops;
1399
1400 if (!ddir_rw(ddir))
1401 return;
1402
1403 spent = mtime_since(&td->iops_sample_time, t);
1404 if (spent < td->o.iops_avg_time)
1405 return;
1406
Jens Axboe9602d8d2012-02-20 20:19:28 +01001407 /*
1408 * Compute both read and write rates for the interval.
1409 */
Shaohua Li6eaf09d2012-09-14 08:49:43 +02001410 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
Jens Axboe9602d8d2012-02-20 20:19:28 +01001411 uint64_t delta;
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001412
Jens Axboe9602d8d2012-02-20 20:19:28 +01001413 delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir];
1414 if (!delta)
1415 continue; /* No entries for interval */
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001416
Jens Axboe9602d8d2012-02-20 20:19:28 +01001417 iops = (delta * 1000) / spent;
1418 add_stat_sample(&ts->iops_stat[ddir], iops);
1419
1420 if (td->iops_log)
1421 add_log_sample(td, td->iops_log, iops, ddir, 0);
1422
Jens Axboe421f4a82012-02-28 08:20:26 +01001423 td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
Jens Axboe9602d8d2012-02-20 20:19:28 +01001424 }
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001425
1426 fio_gettime(&td->iops_sample_time, NULL);
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001427}