blob: f399e912c2196717574fada5f6554bcfbdad4c2d [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 Axboe802ad4a2011-10-05 09:51:58 +020012#include "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
117/*
118 * Find and display the p-th percentile of clat
119 */
Jens Axboec59971e2011-10-04 10:34:03 +0200120static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
Jens Axboe802ad4a2011-10-05 09:51:58 +0200121 fio_fp64_t *plist)
Yu-ju Hong83349192011-08-13 00:53:44 +0200122{
123 unsigned long sum = 0;
Jens Axboe4f6f8292011-10-13 09:28:21 +0200124 unsigned int len, i, j = 0, minv = -1U, maxv = 0;
125 unsigned int *ovals = NULL, oval_len = 0;
Jens Axboe07511a62011-10-13 12:00:24 +0200126 int is_last, scale_down;
Yu-ju Hong83349192011-08-13 00:53:44 +0200127
Jens Axboe802ad4a2011-10-05 09:51:58 +0200128 len = 0;
129 while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0)
130 len++;
Jens Axboe716050f2011-08-16 08:43:45 +0200131
Jens Axboe351de8d2011-10-12 21:03:45 +0200132 if (!len)
133 return;
134
Jens Axboe716050f2011-08-16 08:43:45 +0200135 /*
Jens Axboe802ad4a2011-10-05 09:51:58 +0200136 * Sort the percentile list. Note that it may already be sorted if
137 * we are using the default values, but since it's a short list this
138 * isn't a worry. Also note that this does not work for NaN values.
Jens Axboe716050f2011-08-16 08:43:45 +0200139 */
Jens Axboe802ad4a2011-10-05 09:51:58 +0200140 if (len > 1)
141 qsort((void*)plist, len, sizeof(plist[0]), double_cmp);
Yu-ju Hong83349192011-08-13 00:53:44 +0200142
Jens Axboe4f6f8292011-10-13 09:28:21 +0200143 /*
144 * Calculate bucket values, note down max and min values
145 */
Jens Axboe07511a62011-10-13 12:00:24 +0200146 is_last = 0;
147 for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) {
Yu-ju Hong83349192011-08-13 00:53:44 +0200148 sum += io_u_plat[i];
Jens Axboe802ad4a2011-10-05 09:51:58 +0200149 while (sum >= (plist[j].u.f / 100.0 * nr)) {
150 assert(plist[j].u.f <= 100.0);
Yu-ju Hong83349192011-08-13 00:53:44 +0200151
Jens Axboe4f6f8292011-10-13 09:28:21 +0200152 if (j == oval_len) {
153 oval_len += 100;
154 ovals = realloc(ovals, oval_len * sizeof(unsigned int));
155 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200156
Jens Axboe4f6f8292011-10-13 09:28:21 +0200157 ovals[j] = plat_idx_to_val(i);
158 if (ovals[j] < minv)
159 minv = ovals[j];
160 if (ovals[j] > maxv)
161 maxv = ovals[j];
Jens Axboe07511a62011-10-13 12:00:24 +0200162
163 is_last = (j == len - 1);
164 if (is_last)
165 break;
166
Jens Axboe4f6f8292011-10-13 09:28:21 +0200167 j++;
Yu-ju Hong83349192011-08-13 00:53:44 +0200168 }
169 }
Jens Axboe4f6f8292011-10-13 09:28:21 +0200170
171 /*
172 * We default to usecs, but if the value range is such that we
173 * should scale down to msecs, do that.
174 */
175 if (minv > 2000 && maxv > 99999) {
176 scale_down = 1;
177 log_info(" clat percentiles (msec):\n |");
178 } else {
179 scale_down = 0;
180 log_info(" clat percentiles (usec):\n |");
181 }
182
183 for (j = 0; j < len; j++) {
184 char fbuf[8];
185
186 /* for formatting */
187 if (j != 0 && (j % 4) == 0)
188 log_info(" |");
189
190 /* end of the list */
191 is_last = (j == len - 1);
192
193 if (plist[j].u.f < 10.0)
194 sprintf(fbuf, " %2.2f", plist[j].u.f);
195 else
196 sprintf(fbuf, "%2.2f", plist[j].u.f);
197
198 if (scale_down)
199 ovals[j] = (ovals[j] + 999) / 1000;
200
201 log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ',');
202
203 if (is_last)
204 break;
205
206 if (j % 4 == 3) /* for formatting */
207 log_info("\n");
208 }
209
210 if (ovals)
211 free(ovals);
Yu-ju Hong83349192011-08-13 00:53:44 +0200212}
213
Jens Axboe3c39a372006-06-06 20:56:12 +0200214static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
215 double *mean, double *dev)
216{
Jens Axboe68704082007-01-10 19:56:37 +0100217 double n = is->samples;
Jens Axboe3c39a372006-06-06 20:56:12 +0200218
219 if (is->samples == 0)
220 return 0;
221
222 *min = is->min_val;
223 *max = is->max_val;
224
225 n = (double) is->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200226 *mean = is->mean.u.f;
Jens Axboe3c39a372006-06-06 20:56:12 +0200227
Jens Axboe68704082007-01-10 19:56:37 +0100228 if (n > 1.0)
Jens Axboe802ad4a2011-10-05 09:51:58 +0200229 *dev = sqrt(is->S.u.f / (n - 1.0));
Jens Axboeef9c5c42007-01-03 14:21:13 +0100230 else
Jens Axboe4b43f542007-07-19 21:38:35 +0200231 *dev = 0;
Jens Axboeef9c5c42007-01-03 14:21:13 +0100232
Jens Axboe3c39a372006-06-06 20:56:12 +0200233 return 1;
234}
235
Jens Axboea64e88d2011-10-03 14:20:01 +0200236void show_group_stats(struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200237{
Jens Axboedbe11252007-02-11 00:19:51 +0100238 char *p1, *p2, *p3, *p4;
239 const char *ddir_str[] = { " READ", " WRITE" };
240 int i;
241
Jens Axboe25050622011-10-13 08:50:46 +0200242 log_info("Run status group %d (all jobs):\n", rs->groupid);
Jens Axboe3c39a372006-06-06 20:56:12 +0200243
Jens Axboedbe11252007-02-11 00:19:51 +0100244 for (i = 0; i <= DDIR_WRITE; i++) {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200245 const int i2p = is_power_of_2(rs->kb_base);
246
Jens Axboedbe11252007-02-11 00:19:51 +0100247 if (!rs->max_run[i])
248 continue;
249
Jens Axboe90fef2d2009-07-17 22:33:32 +0200250 p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p);
251 p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p);
252 p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p);
253 p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p);
Jens Axboedbe11252007-02-11 00:19:51 +0100254
Jens Axboeb22989b2009-07-17 22:29:23 +0200255 log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s,"
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100256 " mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2,
257 p3, p4, rs->min_run[i],
258 rs->max_run[i]);
Jens Axboedbe11252007-02-11 00:19:51 +0100259
260 free(p1);
261 free(p2);
262 free(p3);
263 free(p4);
264 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200265}
266
Jens Axboeb3605062007-03-12 14:19:47 +0100267#define ts_total_io_u(ts) \
268 ((ts)->total_io_u[0] + (ts)->total_io_u[1])
269
Jens Axboe838bc702008-05-22 13:08:23 +0200270static void stat_calc_dist(unsigned int *map, unsigned long total,
271 double *io_u_dist)
Jens Axboe22708902007-03-06 17:05:32 +0100272{
273 int i;
274
275 /*
276 * Do depth distribution calculations
277 */
278 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200279 if (total) {
280 io_u_dist[i] = (double) map[i] / (double) total;
281 io_u_dist[i] *= 100.0;
282 if (io_u_dist[i] < 0.1 && map[i])
283 io_u_dist[i] = 0.1;
284 } else
285 io_u_dist[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100286 }
287}
288
Jens Axboe04a0fea2007-06-19 12:48:41 +0200289static void stat_calc_lat(struct thread_stat *ts, double *dst,
290 unsigned int *src, int nr)
Jens Axboe22708902007-03-06 17:05:32 +0100291{
Jens Axboe838bc702008-05-22 13:08:23 +0200292 unsigned long total = ts_total_io_u(ts);
Jens Axboe22708902007-03-06 17:05:32 +0100293 int i;
294
295 /*
296 * Do latency distribution calculations
297 */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200298 for (i = 0; i < nr; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200299 if (total) {
300 dst[i] = (double) src[i] / (double) total;
301 dst[i] *= 100.0;
302 if (dst[i] < 0.01 && src[i])
303 dst[i] = 0.01;
304 } else
305 dst[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100306 }
307}
308
Jens Axboe04a0fea2007-06-19 12:48:41 +0200309static void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
310{
311 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
312}
313
314static void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
315{
316 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
317}
318
Jens Axboeea2accc2007-06-19 09:48:44 +0200319static int usec_to_msec(unsigned long *min, unsigned long *max, double *mean,
320 double *dev)
321{
322 if (*min > 1000 && *max > 1000 && *mean > 1000.0 && *dev > 1000.0) {
323 *min /= 1000;
324 *max /= 1000;
325 *mean /= 1000.0;
326 *dev /= 1000.0;
327 return 0;
328 }
329
330 return 1;
331}
332
Jens Axboe756867b2007-03-06 15:19:24 +0100333static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
Jens Axboe3c39a372006-06-06 20:56:12 +0200334 int ddir)
335{
Jens Axboe3c9b60c2006-11-07 08:36:14 +0100336 const char *ddir_str[] = { "read ", "write" };
Jens Axboe8879fd12009-04-20 10:06:02 +0200337 unsigned long min, max, runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100338 unsigned long long bw, iops;
Jens Axboe3c39a372006-06-06 20:56:12 +0200339 double mean, dev;
Jens Axboeb3605062007-03-12 14:19:47 +0100340 char *io_p, *bw_p, *iops_p;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200341 int i2p;
Jens Axboe3c39a372006-06-06 20:56:12 +0200342
Jens Axboeff58fce2010-08-25 12:02:08 +0200343 assert(ddir_rw(ddir));
344
Jens Axboe756867b2007-03-06 15:19:24 +0100345 if (!ts->runtime[ddir])
Jens Axboe3c39a372006-06-06 20:56:12 +0200346 return;
347
Jens Axboe90fef2d2009-07-17 22:33:32 +0200348 i2p = is_power_of_2(rs->kb_base);
Jens Axboe8879fd12009-04-20 10:06:02 +0200349 runt = ts->runtime[ddir];
350
351 bw = (1000 * ts->io_bytes[ddir]) / runt;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200352 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
353 bw_p = num2str(bw, 6, 1, i2p);
Jens Axboe8879fd12009-04-20 10:06:02 +0200354
Bruce Cran0aacc502011-07-09 08:19:53 +0200355 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100356 iops_p = num2str(iops, 6, 1, 0);
Jens Axboedbe11252007-02-11 00:19:51 +0100357
Signed-off-by Steven Prattcda99fa2010-12-14 08:31:36 +0100358 log_info(" %s: io=%sB, bw=%sB/s, iops=%s, runt=%6llumsec\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100359 ddir_str[ddir], io_p, bw_p, iops_p,
360 ts->runtime[ddir]);
Jens Axboedbe11252007-02-11 00:19:51 +0100361
362 free(io_p);
363 free(bw_p);
Jens Axboeb3605062007-03-12 14:19:47 +0100364 free(iops_p);
Jens Axboe3c39a372006-06-06 20:56:12 +0200365
Jens Axboed85f5112007-06-18 09:41:23 +0200366 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
367 const char *base = "(usec)";
Jens Axboed9309cb2007-08-16 13:07:46 +0200368 char *minp, *maxp;
Jens Axboe3c39a372006-06-06 20:56:12 +0200369
Jens Axboeea2accc2007-06-19 09:48:44 +0200370 if (!usec_to_msec(&min, &max, &mean, &dev))
Jens Axboed85f5112007-06-18 09:41:23 +0200371 base = "(msec)";
Jens Axboeea2accc2007-06-19 09:48:44 +0200372
Jens Axboed9309cb2007-08-16 13:07:46 +0200373 minp = num2str(min, 6, 1, 0);
374 maxp = num2str(max, 6, 1, 0);
375
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100376 log_info(" slat %s: min=%s, max=%s, avg=%5.02f,"
377 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
Jens Axboed9309cb2007-08-16 13:07:46 +0200378
379 free(minp);
380 free(maxp);
Jens Axboed85f5112007-06-18 09:41:23 +0200381 }
382 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
383 const char *base = "(usec)";
Jens Axboed9309cb2007-08-16 13:07:46 +0200384 char *minp, *maxp;
Jens Axboe3c39a372006-06-06 20:56:12 +0200385
Jens Axboeea2accc2007-06-19 09:48:44 +0200386 if (!usec_to_msec(&min, &max, &mean, &dev))
387 base = "(msec)";
388
Jens Axboed9309cb2007-08-16 13:07:46 +0200389 minp = num2str(min, 6, 1, 0);
390 maxp = num2str(max, 6, 1, 0);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100391
392 log_info(" clat %s: min=%s, max=%s, avg=%5.02f,"
393 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
Jens Axboed9309cb2007-08-16 13:07:46 +0200394
395 free(minp);
396 free(maxp);
Jens Axboed85f5112007-06-18 09:41:23 +0200397 }
Jens Axboe02af0982010-06-24 09:59:34 +0200398 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) {
399 const char *base = "(usec)";
400 char *minp, *maxp;
401
402 if (!usec_to_msec(&min, &max, &mean, &dev))
403 base = "(msec)";
404
405 minp = num2str(min, 6, 1, 0);
406 maxp = num2str(max, 6, 1, 0);
407
408 log_info(" lat %s: min=%s, max=%s, avg=%5.02f,"
409 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
410
411 free(minp);
412 free(maxp);
413 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200414 if (ts->clat_percentiles) {
415 show_clat_percentiles(ts->io_u_plat[ddir],
416 ts->clat_stat[ddir].samples,
417 ts->percentile_list);
418 }
Jens Axboe079ad092007-02-20 13:58:20 +0100419 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe3c39a372006-06-06 20:56:12 +0200420 double p_of_agg;
421
422 p_of_agg = mean * 100 / (double) rs->agg[ddir];
Jens Axboec8eeb9d2011-10-05 14:02:22 +0200423 log_info(" bw (KB/s) : min=%5lu, max=%5lu, per=%3.2f%%,"
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100424 " avg=%5.02f, stdev=%5.02f\n", min, max, p_of_agg,
425 mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200426 }
427}
428
Jens Axboe04a0fea2007-06-19 12:48:41 +0200429static void show_lat(double *io_u_lat, int nr, const char **ranges,
430 const char *msg)
431{
432 int new_line = 1, i, line = 0;
433
434 for (i = 0; i < nr; i++) {
435 if (io_u_lat[i] <= 0.0)
436 continue;
437 if (new_line) {
Jens Axboe4539ed72007-07-23 14:21:17 +0200438 if (line)
439 log_info("\n");
Jens Axboe04a0fea2007-06-19 12:48:41 +0200440 log_info(" lat (%s): ", msg);
441 new_line = 0;
442 line = 0;
443 }
444 if (line)
445 log_info(", ");
446 log_info("%s%3.2f%%", ranges[i], io_u_lat[i]);
447 line++;
448 if (line == 5)
449 new_line = 1;
450 }
Jens Axboe04a0fea2007-06-19 12:48:41 +0200451}
452
453static void show_lat_u(double *io_u_lat_u)
454{
455 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
456 "250=", "500=", "750=", "1000=", };
457
458 show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec");
459}
460
461static void show_lat_m(double *io_u_lat_m)
462{
463 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
464 "250=", "500=", "750=", "1000=", "2000=",
465 ">=2000=", };
466
467 show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec");
468}
469
470static void show_latencies(double *io_u_lat_u, double *io_u_lat_m)
471{
472 show_lat_u(io_u_lat_u);
Jens Axboe4539ed72007-07-23 14:21:17 +0200473 log_info("\n");
Jens Axboe04a0fea2007-06-19 12:48:41 +0200474 show_lat_m(io_u_lat_m);
475 log_info("\n");
476}
477
Jens Axboea64e88d2011-10-03 14:20:01 +0200478void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200479{
480 double usr_cpu, sys_cpu;
Jens Axboe69008992006-11-24 13:12:56 +0100481 unsigned long runtime;
Jens Axboe71619dc2007-01-13 23:56:33 +0100482 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200483 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
484 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboe3c39a372006-06-06 20:56:12 +0200485
Jens Axboeb4c5e1a2007-10-25 18:44:45 +0200486 if (!(ts->io_bytes[0] + ts->io_bytes[1]) &&
487 !(ts->total_io_u[0] + ts->total_io_u[1]))
Jens Axboe3c39a372006-06-06 20:56:12 +0200488 return;
489
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100490 if (!ts->error) {
491 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n",
492 ts->name, ts->groupid, ts->members,
Jens Axboe5921e802008-05-30 15:02:38 +0200493 ts->error, (int) ts->pid);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100494 } else {
495 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d\n",
496 ts->name, ts->groupid, ts->members,
Jens Axboe5921e802008-05-30 15:02:38 +0200497 ts->error, ts->verror, (int) ts->pid);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100498 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200499
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100500 if (ts->description)
Jens Axboe6d861442007-03-15 09:22:23 +0100501 log_info(" Description : [%s]\n", ts->description);
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100502
Jens Axboe756867b2007-03-06 15:19:24 +0100503 if (ts->io_bytes[DDIR_READ])
504 show_ddir_status(rs, ts, DDIR_READ);
505 if (ts->io_bytes[DDIR_WRITE])
506 show_ddir_status(rs, ts, DDIR_WRITE);
Jens Axboe3c39a372006-06-06 20:56:12 +0200507
Jens Axboe756867b2007-03-06 15:19:24 +0100508 runtime = ts->total_run_time;
Jens Axboe69008992006-11-24 13:12:56 +0100509 if (runtime) {
Jens Axboe1e97cce2006-12-05 11:44:16 +0100510 double runt = (double) runtime;
Jens Axboe3c39a372006-06-06 20:56:12 +0200511
Jens Axboe756867b2007-03-06 15:19:24 +0100512 usr_cpu = (double) ts->usr_time * 100 / runt;
513 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboe3c39a372006-06-06 20:56:12 +0200514 } else {
515 usr_cpu = 0;
516 sys_cpu = 0;
517 }
518
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100519 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu,"
520 " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf);
Jens Axboe71619dc2007-01-13 23:56:33 +0100521
Jens Axboe838bc702008-05-22 13:08:23 +0200522 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100523 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%,"
524 " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
525 io_u_dist[1], io_u_dist[2],
526 io_u_dist[3], io_u_dist[4],
527 io_u_dist[5], io_u_dist[6]);
Jens Axboe838bc702008-05-22 13:08:23 +0200528
529 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
530 log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
531 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
532 io_u_dist[1], io_u_dist[2],
533 io_u_dist[3], io_u_dist[4],
534 io_u_dist[5], io_u_dist[6]);
535 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
536 log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
537 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
538 io_u_dist[1], io_u_dist[2],
539 io_u_dist[3], io_u_dist[4],
540 io_u_dist[5], io_u_dist[6]);
Jens Axboe0d29de82010-09-01 13:54:15 +0200541 log_info(" issued r/w/d: total=%lu/%lu/%lu, short=%lu/%lu/%lu\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100542 ts->total_io_u[0], ts->total_io_u[1],
Jens Axboe0d29de82010-09-01 13:54:15 +0200543 ts->total_io_u[2],
544 ts->short_io_u[0], ts->short_io_u[1],
545 ts->short_io_u[2]);
Jens Axboe838bc702008-05-22 13:08:23 +0200546 stat_calc_lat_u(ts, io_u_lat_u);
547 stat_calc_lat_m(ts, io_u_lat_m);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200548 show_latencies(io_u_lat_u, io_u_lat_m);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200549 if (ts->continue_on_error) {
Jens Axboe1ec99ee2009-06-15 12:37:30 +0200550 log_info(" errors : total=%lu, first_error=%d/<%s>\n",
551 ts->total_err_count,
552 ts->first_error,
553 strerror(ts->first_error));
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200554 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200555}
556
Jens Axboe756867b2007-03-06 15:19:24 +0100557static void show_ddir_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200558 struct group_run_stats *rs, int ddir)
559{
560 unsigned long min, max;
Jens Axboe312b4af2011-10-13 13:11:42 +0200561 unsigned long long bw, iops;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200562 double mean, dev;
563
Jens Axboeff58fce2010-08-25 12:02:08 +0200564 assert(ddir_rw(ddir));
565
Jens Axboe312b4af2011-10-13 13:11:42 +0200566 iops = bw = 0;
567 if (ts->runtime[ddir]) {
568 uint64_t runt = ts->runtime[ddir];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200569
Jens Axboe312b4af2011-10-13 13:11:42 +0200570 bw = ts->io_bytes[ddir] / runt;
571 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
572 }
573
574 log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops,
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100575 ts->runtime[ddir]);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200576
Jens Axboe079ad092007-02-20 13:58:20 +0100577 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100578 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200579 else
Jens Axboe6d861442007-03-15 09:22:23 +0100580 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200581
Jens Axboe079ad092007-02-20 13:58:20 +0100582 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100583 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200584 else
Jens Axboe6d861442007-03-15 09:22:23 +0100585 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200586
Jens Axboe02af0982010-06-24 09:59:34 +0200587 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
588 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
589 else
590 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
591
Jens Axboe079ad092007-02-20 13:58:20 +0100592 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboec6ae0a52006-06-12 11:04:44 +0200593 double p_of_agg;
594
595 p_of_agg = mean * 100 / (double) rs->agg[ddir];
Jens Axboe6d861442007-03-15 09:22:23 +0100596 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200597 } else
Jens Axboe6d861442007-03-15 09:22:23 +0100598 log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200599}
600
Jens Axboe312b4af2011-10-13 13:11:42 +0200601#define FIO_TERSE_VERSION "3"
Jens Axboec6ae0a52006-06-12 11:04:44 +0200602
Jens Axboe756867b2007-03-06 15:19:24 +0100603static void show_thread_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200604 struct group_run_stats *rs)
605{
Jens Axboe22708902007-03-06 17:05:32 +0100606 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200607 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
608 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200609 double usr_cpu, sys_cpu;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200610 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200611
David Nellans562c2d22010-09-23 08:38:17 +0200612 /* General Info */
Jens Axboe525c2bf2010-06-30 15:22:21 +0200613 log_info("%s;%s;%d;%d", FIO_TERSE_VERSION, ts->name, ts->groupid,
614 ts->error);
David Nellans562c2d22010-09-23 08:38:17 +0200615 /* Log Read Status */
Jens Axboe756867b2007-03-06 15:19:24 +0100616 show_ddir_status_terse(ts, rs, 0);
David Nellans562c2d22010-09-23 08:38:17 +0200617 /* Log Write Status */
Jens Axboe756867b2007-03-06 15:19:24 +0100618 show_ddir_status_terse(ts, rs, 1);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200619
David Nellans562c2d22010-09-23 08:38:17 +0200620 /* CPU Usage */
Jens Axboe756867b2007-03-06 15:19:24 +0100621 if (ts->total_run_time) {
622 double runt = (double) ts->total_run_time;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200623
Jens Axboe756867b2007-03-06 15:19:24 +0100624 usr_cpu = (double) ts->usr_time * 100 / runt;
625 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200626 } else {
627 usr_cpu = 0;
628 sys_cpu = 0;
629 }
630
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100631 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
632 ts->minf);
Jens Axboe22708902007-03-06 17:05:32 +0100633
David Nellans562c2d22010-09-23 08:38:17 +0200634 /* Calc % distribution of IO depths, usecond, msecond latency */
Jens Axboe838bc702008-05-22 13:08:23 +0200635 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200636 stat_calc_lat_u(ts, io_u_lat_u);
637 stat_calc_lat_m(ts, io_u_lat_m);
Jens Axboe22708902007-03-06 17:05:32 +0100638
David Nellans562c2d22010-09-23 08:38:17 +0200639 /* Only show fixed 7 I/O depth levels*/
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100640 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
641 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
642 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
Jens Axboe22708902007-03-06 17:05:32 +0100643
David Nellans562c2d22010-09-23 08:38:17 +0200644 /* Microsecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200645 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
646 log_info(";%3.2f%%", io_u_lat_u[i]);
David Nellans562c2d22010-09-23 08:38:17 +0200647 /* Millisecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200648 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
649 log_info(";%3.2f%%", io_u_lat_m[i]);
David Nellans562c2d22010-09-23 08:38:17 +0200650 /* Additional output if continue_on_error set - default off*/
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200651 if (ts->continue_on_error)
652 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200653 log_info("\n");
Jens Axboe22708902007-03-06 17:05:32 +0100654
David Nellans562c2d22010-09-23 08:38:17 +0200655 /* Additional output if description is set */
Jens Axboe22708902007-03-06 17:05:32 +0100656 if (ts->description)
Jens Axboe6d861442007-03-15 09:22:23 +0100657 log_info(";%s", ts->description);
Jens Axboe22708902007-03-06 17:05:32 +0100658
Jens Axboe6d861442007-03-15 09:22:23 +0100659 log_info("\n");
Jens Axboe756867b2007-03-06 15:19:24 +0100660}
661
Jens Axboe197574e2007-03-08 15:35:11 +0100662static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
Jens Axboe756867b2007-03-06 15:19:24 +0100663{
664 double mean, S;
665
Zheng Liue09231c2011-09-16 08:20:12 +0200666 if (src->samples == 0)
667 return;
668
Jens Axboe756867b2007-03-06 15:19:24 +0100669 dst->min_val = min(dst->min_val, src->min_val);
670 dst->max_val = max(dst->max_val, src->max_val);
Jens Axboe756867b2007-03-06 15:19:24 +0100671
672 /*
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200673 * Compute new mean and S after the merge
674 * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
675 * #Parallel_algorithm>
Jens Axboe756867b2007-03-06 15:19:24 +0100676 */
677 if (nr == 1) {
Jens Axboe802ad4a2011-10-05 09:51:58 +0200678 mean = src->mean.u.f;
679 S = src->S.u.f;
Jens Axboe756867b2007-03-06 15:19:24 +0100680 } else {
Jens Axboe802ad4a2011-10-05 09:51:58 +0200681 double delta = src->mean.u.f - dst->mean.u.f;
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200682
Jens Axboe802ad4a2011-10-05 09:51:58 +0200683 mean = ((src->mean.u.f * src->samples) +
684 (dst->mean.u.f * dst->samples)) /
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200685 (dst->samples + src->samples);
686
Jens Axboe802ad4a2011-10-05 09:51:58 +0200687 S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) *
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200688 (dst->samples * src->samples) /
689 (dst->samples + src->samples);
Jens Axboe756867b2007-03-06 15:19:24 +0100690 }
691
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200692 dst->samples += src->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200693 dst->mean.u.f = mean;
694 dst->S.u.f = S;
Jens Axboe756867b2007-03-06 15:19:24 +0100695}
696
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200697void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src)
698{
699 int i;
700
701 for (i = 0; i < 2; i++) {
702 if (dst->max_run[i] < src->max_run[i])
703 dst->max_run[i] = src->max_run[i];
704 if (dst->min_run[i] && dst->min_run[i] > src->min_run[i])
705 dst->min_run[i] = src->min_run[i];
706 if (dst->max_bw[i] < src->max_bw[i])
707 dst->max_bw[i] = src->max_bw[i];
708 if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i])
709 dst->min_bw[i] = src->min_bw[i];
710
711 dst->io_kb[i] += src->io_kb[i];
712 dst->agg[i] += src->agg[i];
713 }
714
715}
716
Jens Axboe5b9babb2011-10-10 12:14:30 +0200717void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr)
718{
719 int l, k;
720
721 for (l = 0; l <= DDIR_WRITE; l++) {
722 sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr);
723 sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr);
724 sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr);
725 sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr);
726
727 dst->io_bytes[l] += src->io_bytes[l];
728
729 if (dst->runtime[l] < src->runtime[l])
730 dst->runtime[l] = src->runtime[l];
731 }
732
733 dst->usr_time += src->usr_time;
734 dst->sys_time += src->sys_time;
735 dst->ctx += src->ctx;
736 dst->majf += src->majf;
737 dst->minf += src->minf;
738
739 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
740 dst->io_u_map[k] += src->io_u_map[k];
741 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
742 dst->io_u_submit[k] += src->io_u_submit[k];
743 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
744 dst->io_u_complete[k] += src->io_u_complete[k];
745 for (k = 0; k < FIO_IO_U_LAT_U_NR; k++)
746 dst->io_u_lat_u[k] += src->io_u_lat_u[k];
747 for (k = 0; k < FIO_IO_U_LAT_M_NR; k++)
748 dst->io_u_lat_m[k] += src->io_u_lat_m[k];
749
750 for (k = 0; k <= 2; k++) {
751 dst->total_io_u[k] += src->total_io_u[k];
752 dst->short_io_u[k] += src->short_io_u[k];
753 }
754
755 for (k = 0; k <= DDIR_WRITE; k++) {
756 int m;
757 for (m = 0; m < FIO_IO_U_PLAT_NR; m++)
758 dst->io_u_plat[k][m] += src->io_u_plat[k][m];
759 }
760
761 dst->total_run_time += src->total_run_time;
762 dst->total_submit += src->total_submit;
763 dst->total_complete += src->total_complete;
764}
765
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200766void init_group_run_stat(struct group_run_stats *gs)
767{
768 memset(gs, 0, sizeof(*gs));
769 gs->min_bw[0] = gs->min_run[0] = ~0UL;
770 gs->min_bw[1] = gs->min_run[1] = ~0UL;
771}
772
773void init_thread_stat(struct thread_stat *ts)
774{
775 int j;
776
777 memset(ts, 0, sizeof(*ts));
778
779 for (j = 0; j <= DDIR_WRITE; j++) {
780 ts->lat_stat[j].min_val = -1UL;
781 ts->clat_stat[j].min_val = -1UL;
782 ts->slat_stat[j].min_val = -1UL;
783 ts->bw_stat[j].min_val = -1UL;
784 }
785 ts->groupid = -1;
786}
787
Jens Axboe3c39a372006-06-06 20:56:12 +0200788void show_run_stats(void)
789{
790 struct group_run_stats *runstats, *rs;
791 struct thread_data *td;
Jens Axboe756867b2007-03-06 15:19:24 +0100792 struct thread_stat *threadstats, *ts;
Jens Axboe5b9babb2011-10-10 12:14:30 +0200793 int i, j, nr_ts, last_ts, idx;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200794 int kb_base_warned = 0;
Jens Axboe3c39a372006-06-06 20:56:12 +0200795
796 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
797
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200798 for (i = 0; i < groupid + 1; i++)
799 init_group_run_stat(&runstats[i]);
Jens Axboe3c39a372006-06-06 20:56:12 +0200800
Jens Axboe756867b2007-03-06 15:19:24 +0100801 /*
802 * find out how many threads stats we need. if group reporting isn't
803 * enabled, it's one-per-td.
804 */
805 nr_ts = 0;
806 last_ts = -1;
Jens Axboe34572e22006-10-20 09:33:18 +0200807 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100808 if (!td->o.group_reporting) {
Jens Axboe756867b2007-03-06 15:19:24 +0100809 nr_ts++;
810 continue;
811 }
812 if (last_ts == td->groupid)
813 continue;
814
815 last_ts = td->groupid;
816 nr_ts++;
817 }
818
819 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
820
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200821 for (i = 0; i < nr_ts; i++)
822 init_thread_stat(&threadstats[i]);
Jens Axboe756867b2007-03-06 15:19:24 +0100823
824 j = 0;
825 last_ts = -1;
Jens Axboe197574e2007-03-08 15:35:11 +0100826 idx = 0;
Jens Axboe756867b2007-03-06 15:19:24 +0100827 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100828 if (idx && (!td->o.group_reporting ||
829 (td->o.group_reporting && last_ts != td->groupid))) {
Jens Axboe7abd0e32007-03-12 15:24:43 +0100830 idx = 0;
831 j++;
832 }
833
834 last_ts = td->groupid;
835
Jens Axboe756867b2007-03-06 15:19:24 +0100836 ts = &threadstats[j];
837
Yu-ju Hong83349192011-08-13 00:53:44 +0200838 ts->clat_percentiles = td->o.clat_percentiles;
839 if (td->o.overwrite_plist)
Jens Axboe802ad4a2011-10-05 09:51:58 +0200840 memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +0200841 else
Jens Axboe802ad4a2011-10-05 09:51:58 +0200842 memcpy(ts->percentile_list, def_percentile_list, sizeof(def_percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +0200843
Jens Axboe197574e2007-03-08 15:35:11 +0100844 idx++;
Jens Axboe6586ee82007-03-06 19:46:09 +0100845 ts->members++;
Jens Axboe756867b2007-03-06 15:19:24 +0100846
Jens Axboe7abd0e32007-03-12 15:24:43 +0100847 if (ts->groupid == -1) {
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100848 /*
849 * These are per-group shared already
850 */
Jens Axboef6bb5b82011-10-03 12:21:25 +0200851 strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE);
Jens Axboea64e88d2011-10-03 14:20:01 +0200852 if (td->o.description)
853 strncpy(ts->description, td->o.description,
854 FIO_JOBNAME_SIZE);
855 else
856 memset(ts->description, 0, FIO_JOBNAME_SIZE);
857
Jens Axboe756867b2007-03-06 15:19:24 +0100858 ts->groupid = td->groupid;
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100859
860 /*
861 * first pid in group, not very useful...
862 */
Jens Axboe756867b2007-03-06 15:19:24 +0100863 ts->pid = td->pid;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200864
865 ts->kb_base = td->o.kb_base;
866 } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) {
867 log_info("fio: kb_base differs for jobs in group, using"
868 " %u as the base\n", ts->kb_base);
869 kb_base_warned = 1;
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100870 }
871
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200872 ts->continue_on_error = td->o.continue_on_error;
873 ts->total_err_count += td->total_err_count;
874 ts->first_error = td->first_error;
875 if (!ts->error) {
876 if (!td->error && td->o.continue_on_error &&
877 td->first_error) {
878 ts->error = td->first_error;
Jens Axboef6bb5b82011-10-03 12:21:25 +0200879 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200880 } else if (td->error) {
881 ts->error = td->error;
Jens Axboef6bb5b82011-10-03 12:21:25 +0200882 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200883 }
Jens Axboe756867b2007-03-06 15:19:24 +0100884 }
885
Jens Axboe5b9babb2011-10-10 12:14:30 +0200886 sum_thread_stats(ts, &td->ts, idx);
Jens Axboe756867b2007-03-06 15:19:24 +0100887 }
888
889 for (i = 0; i < nr_ts; i++) {
Jens Axboe94370ac2007-03-08 15:28:10 +0100890 unsigned long long bw;
Jens Axboe3c39a372006-06-06 20:56:12 +0200891
Jens Axboe756867b2007-03-06 15:19:24 +0100892 ts = &threadstats[i];
893 rs = &runstats[ts->groupid];
Jens Axboe90fef2d2009-07-17 22:33:32 +0200894 rs->kb_base = ts->kb_base;
Jens Axboe3c39a372006-06-06 20:56:12 +0200895
Jens Axboede64df02007-03-08 19:09:49 +0100896 for (j = 0; j <= DDIR_WRITE; j++) {
Jens Axboe94370ac2007-03-08 15:28:10 +0100897 if (!ts->runtime[j])
898 continue;
899 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
900 rs->min_run[j] = ts->runtime[j];
901 if (ts->runtime[j] > rs->max_run[j])
902 rs->max_run[j] = ts->runtime[j];
Jens Axboe3c39a372006-06-06 20:56:12 +0200903
Jens Axboe94370ac2007-03-08 15:28:10 +0100904 bw = 0;
Jens Axboe8879fd12009-04-20 10:06:02 +0200905 if (ts->runtime[j]) {
906 unsigned long runt;
907
Jens Axboe90fef2d2009-07-17 22:33:32 +0200908 runt = ts->runtime[j];
Jens Axboe8879fd12009-04-20 10:06:02 +0200909 bw = ts->io_bytes[j] / runt;
910 }
Jens Axboe94370ac2007-03-08 15:28:10 +0100911 if (bw < rs->min_bw[j])
912 rs->min_bw[j] = bw;
913 if (bw > rs->max_bw[j])
914 rs->max_bw[j] = bw;
Jens Axboe3c39a372006-06-06 20:56:12 +0200915
Jens Axboe90fef2d2009-07-17 22:33:32 +0200916 rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base;
Jens Axboe94370ac2007-03-08 15:28:10 +0100917 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200918 }
919
920 for (i = 0; i < groupid + 1; i++) {
Jens Axboe8879fd12009-04-20 10:06:02 +0200921 unsigned long max_run[2];
922
Jens Axboe3c39a372006-06-06 20:56:12 +0200923 rs = &runstats[i];
Jens Axboe90fef2d2009-07-17 22:33:32 +0200924 max_run[0] = rs->max_run[0];
925 max_run[1] = rs->max_run[1];
Jens Axboe3c39a372006-06-06 20:56:12 +0200926
927 if (rs->max_run[0])
Jens Axboe4cf1abc2010-06-25 14:33:37 +0200928 rs->agg[0] = (rs->io_kb[0] * 1000) / max_run[0];
Jens Axboe3c39a372006-06-06 20:56:12 +0200929 if (rs->max_run[1])
Jens Axboe4cf1abc2010-06-25 14:33:37 +0200930 rs->agg[1] = (rs->io_kb[1] * 1000) / max_run[1];
Jens Axboe3c39a372006-06-06 20:56:12 +0200931 }
932
933 /*
934 * don't overwrite last signal output
935 */
Jens Axboec6ae0a52006-06-12 11:04:44 +0200936 if (!terse_output)
Jens Axboe4ceb30d2010-02-24 09:19:14 +0100937 log_info("\n");
Jens Axboe3c39a372006-06-06 20:56:12 +0200938
Jens Axboe756867b2007-03-06 15:19:24 +0100939 for (i = 0; i < nr_ts; i++) {
940 ts = &threadstats[i];
941 rs = &runstats[ts->groupid];
Jens Axboe3c39a372006-06-06 20:56:12 +0200942
Jens Axboea64e88d2011-10-03 14:20:01 +0200943 if (is_backend)
944 fio_server_send_ts(ts, rs);
945 else if (terse_output)
Jens Axboe756867b2007-03-06 15:19:24 +0100946 show_thread_status_terse(ts, rs);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200947 else
Jens Axboe756867b2007-03-06 15:19:24 +0100948 show_thread_status(ts, rs);
Jens Axboe3c39a372006-06-06 20:56:12 +0200949 }
950
Jens Axboec6ae0a52006-06-12 11:04:44 +0200951 if (!terse_output) {
Jens Axboea64e88d2011-10-03 14:20:01 +0200952 for (i = 0; i < groupid + 1; i++) {
953 rs = &runstats[i];
954
955 rs->groupid = i;
956 if (is_backend)
957 fio_server_send_gs(rs);
958 else
959 show_group_stats(rs);
960 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200961
Jens Axboed09a64a2011-10-13 11:38:56 +0200962 if (is_backend)
963 fio_server_send_du();
964 else
965 show_disk_util();
966
967 free_disk_util();
Jens Axboec6ae0a52006-06-12 11:04:44 +0200968 }
Jens Axboeeecf2722006-10-20 14:00:36 +0200969
970 free(runstats);
Jens Axboe756867b2007-03-06 15:19:24 +0100971 free(threadstats);
Jens Axboe3c39a372006-06-06 20:56:12 +0200972}
973
Jens Axboe68704082007-01-10 19:56:37 +0100974static inline void add_stat_sample(struct io_stat *is, unsigned long data)
Jens Axboe3c39a372006-06-06 20:56:12 +0200975{
Jens Axboe68704082007-01-10 19:56:37 +0100976 double val = data;
Jens Axboe6660cc62007-03-06 15:48:38 +0100977 double delta;
Jens Axboe3c39a372006-06-06 20:56:12 +0200978
Jens Axboe68704082007-01-10 19:56:37 +0100979 if (data > is->max_val)
980 is->max_val = data;
981 if (data < is->min_val)
982 is->min_val = data;
983
Jens Axboe802ad4a2011-10-05 09:51:58 +0200984 delta = val - is->mean.u.f;
Jens Axboeef11d732007-03-29 15:36:29 +0200985 if (delta) {
Jens Axboe802ad4a2011-10-05 09:51:58 +0200986 is->mean.u.f += delta / (is->samples + 1.0);
987 is->S.u.f += delta * (val - is->mean.u.f);
Jens Axboeef11d732007-03-29 15:36:29 +0200988 }
Jens Axboe68704082007-01-10 19:56:37 +0100989
Jens Axboe3c39a372006-06-06 20:56:12 +0200990 is->samples++;
991}
992
Jens Axboebb3884d2007-01-17 17:23:11 +1100993static void __add_log_sample(struct io_log *iolog, unsigned long val,
Jens Axboe306ddc92009-05-18 13:08:12 +0200994 enum fio_ddir ddir, unsigned int bs,
Jens Axboe2b13e712011-01-19 14:04:16 -0700995 unsigned long t)
Jens Axboe3c39a372006-06-06 20:56:12 +0200996{
Jens Axboe306ddc92009-05-18 13:08:12 +0200997 const int nr_samples = iolog->nr_samples;
998
Jens Axboe3c39a372006-06-06 20:56:12 +0200999 if (iolog->nr_samples == iolog->max_samples) {
1000 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
1001
1002 iolog->log = realloc(iolog->log, new_size);
1003 iolog->max_samples <<= 1;
1004 }
1005
Jens Axboe306ddc92009-05-18 13:08:12 +02001006 iolog->log[nr_samples].val = val;
Jens Axboe2b13e712011-01-19 14:04:16 -07001007 iolog->log[nr_samples].time = t;
Jens Axboe306ddc92009-05-18 13:08:12 +02001008 iolog->log[nr_samples].ddir = ddir;
1009 iolog->log[nr_samples].bs = bs;
Jens Axboe3c39a372006-06-06 20:56:12 +02001010 iolog->nr_samples++;
1011}
1012
Jens Axboebb3884d2007-01-17 17:23:11 +11001013static void add_log_sample(struct thread_data *td, struct io_log *iolog,
Jens Axboe306ddc92009-05-18 13:08:12 +02001014 unsigned long val, enum fio_ddir ddir,
1015 unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001016{
Jens Axboeff58fce2010-08-25 12:02:08 +02001017 if (!ddir_rw(ddir))
1018 return;
1019
Jens Axboe306ddc92009-05-18 13:08:12 +02001020 __add_log_sample(iolog, val, ddir, bs, mtime_since_now(&td->epoch));
Jens Axboebb3884d2007-01-17 17:23:11 +11001021}
1022
Jens Axboe306ddc92009-05-18 13:08:12 +02001023void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001024{
Jens Axboeff58fce2010-08-25 12:02:08 +02001025 struct io_log *iolog;
Jens Axboebb3884d2007-01-17 17:23:11 +11001026
Jens Axboeff58fce2010-08-25 12:02:08 +02001027 if (!ddir_rw(ddir))
1028 return;
1029
1030 iolog = agg_io_log[ddir];
Jens Axboe306ddc92009-05-18 13:08:12 +02001031 __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis());
Jens Axboebb3884d2007-01-17 17:23:11 +11001032}
1033
Yu-ju Hong83349192011-08-13 00:53:44 +02001034static void add_clat_percentile_sample(struct thread_stat *ts,
1035 unsigned long usec, enum fio_ddir ddir)
1036{
1037 unsigned int idx = plat_val_to_idx(usec);
1038 assert(idx < FIO_IO_U_PLAT_NR);
1039
1040 ts->io_u_plat[ddir][idx]++;
1041}
1042
Jens Axboe1e97cce2006-12-05 11:44:16 +01001043void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001044 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001045{
Jens Axboe756867b2007-03-06 15:19:24 +01001046 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001047
Jens Axboeff58fce2010-08-25 12:02:08 +02001048 if (!ddir_rw(ddir))
1049 return;
1050
Jens Axboed85f5112007-06-18 09:41:23 +02001051 add_stat_sample(&ts->clat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001052
Jens Axboe7b9f7332011-10-03 10:06:44 +02001053 if (td->clat_log)
1054 add_log_sample(td, td->clat_log, usec, ddir, bs);
Yu-ju Hong83349192011-08-13 00:53:44 +02001055
1056 if (ts->clat_percentiles)
1057 add_clat_percentile_sample(ts, usec, ddir);
Jens Axboe3c39a372006-06-06 20:56:12 +02001058}
1059
Jens Axboe1e97cce2006-12-05 11:44:16 +01001060void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001061 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001062{
Jens Axboe756867b2007-03-06 15:19:24 +01001063 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001064
Jens Axboeff58fce2010-08-25 12:02:08 +02001065 if (!ddir_rw(ddir))
1066 return;
1067
Jens Axboed85f5112007-06-18 09:41:23 +02001068 add_stat_sample(&ts->slat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001069
Jens Axboe7b9f7332011-10-03 10:06:44 +02001070 if (td->slat_log)
1071 add_log_sample(td, td->slat_log, usec, ddir, bs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001072}
1073
Jens Axboe02af0982010-06-24 09:59:34 +02001074void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
1075 unsigned long usec, unsigned int bs)
1076{
1077 struct thread_stat *ts = &td->ts;
1078
Jens Axboeff58fce2010-08-25 12:02:08 +02001079 if (!ddir_rw(ddir))
1080 return;
1081
Jens Axboe02af0982010-06-24 09:59:34 +02001082 add_stat_sample(&ts->lat_stat[ddir], usec);
1083
Jens Axboe7b9f7332011-10-03 10:06:44 +02001084 if (td->lat_log)
1085 add_log_sample(td, td->lat_log, usec, ddir, bs);
Jens Axboe02af0982010-06-24 09:59:34 +02001086}
1087
Jens Axboe306ddc92009-05-18 13:08:12 +02001088void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
Jens Axboe1e97cce2006-12-05 11:44:16 +01001089 struct timeval *t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001090{
Jens Axboe756867b2007-03-06 15:19:24 +01001091 struct thread_stat *ts = &td->ts;
Jens Axboeff58fce2010-08-25 12:02:08 +02001092 unsigned long spent, rate;
Jens Axboe3c39a372006-06-06 20:56:12 +02001093
Jens Axboeff58fce2010-08-25 12:02:08 +02001094 if (!ddir_rw(ddir))
1095 return;
1096
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001097 spent = mtime_since(&td->bw_sample_time, t);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001098 if (spent < td->o.bw_avg_time)
Jens Axboe3c39a372006-06-06 20:56:12 +02001099 return;
1100
Jens Axboef0505a12011-10-03 12:12:03 +02001101 rate = (td->this_io_bytes[ddir] - td->stat_io_bytes[ddir]) *
Jens Axboe0b9d69e2009-09-11 22:29:54 +02001102 1000 / spent / 1024;
Jens Axboe079ad092007-02-20 13:58:20 +01001103 add_stat_sample(&ts->bw_stat[ddir], rate);
Jens Axboe3c39a372006-06-06 20:56:12 +02001104
Jens Axboe7b9f7332011-10-03 10:06:44 +02001105 if (td->bw_log)
1106 add_log_sample(td, td->bw_log, rate, ddir, bs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001107
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001108 fio_gettime(&td->bw_sample_time, NULL);
Jens Axboef0505a12011-10-03 12:12:03 +02001109 td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
Jens Axboe3c39a372006-06-06 20:56:12 +02001110}
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001111
1112void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,
1113 struct timeval *t)
1114{
1115 struct thread_stat *ts = &td->ts;
1116 unsigned long spent, iops;
1117
1118 if (!ddir_rw(ddir))
1119 return;
1120
1121 spent = mtime_since(&td->iops_sample_time, t);
1122 if (spent < td->o.iops_avg_time)
1123 return;
1124
1125 iops = ((td->this_io_blocks[ddir] - td->stat_io_blocks[ddir]) * 1000) / spent;
1126
1127 add_stat_sample(&ts->iops_stat[ddir], iops);
1128
1129 if (td->iops_log) {
1130 assert(iops);
1131 add_log_sample(td, td->iops_log, iops, ddir, 0);
1132 }
1133
1134 fio_gettime(&td->iops_sample_time, NULL);
1135 td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
1136}