blob: e4ddfa8c54455a43a696f136143511179a215cdc [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 Axboea2697902012-03-05 16:43:49 +0100117unsigned int calc_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
118 fio_fp64_t *plist, unsigned int **output,
119 unsigned int *maxv, unsigned int *minv)
Yu-ju Hong83349192011-08-13 00:53:44 +0200120{
121 unsigned long sum = 0;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200122 unsigned int len, i, j = 0;
123 unsigned int oval_len = 0;
124 unsigned int *ovals = NULL;
125 int is_last;
126
127 *minv = -1U;
128 *maxv = 0;
Yu-ju Hong83349192011-08-13 00:53:44 +0200129
Jens Axboe802ad4a2011-10-05 09:51:58 +0200130 len = 0;
131 while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0)
132 len++;
Jens Axboe716050f2011-08-16 08:43:45 +0200133
Jens Axboe351de8d2011-10-12 21:03:45 +0200134 if (!len)
Jens Axboe1db92cb2011-10-13 13:43:36 +0200135 return 0;
Jens Axboe351de8d2011-10-12 21:03:45 +0200136
Jens Axboe716050f2011-08-16 08:43:45 +0200137 /*
Jens Axboe802ad4a2011-10-05 09:51:58 +0200138 * Sort the percentile list. Note that it may already be sorted if
139 * we are using the default values, but since it's a short list this
140 * isn't a worry. Also note that this does not work for NaN values.
Jens Axboe716050f2011-08-16 08:43:45 +0200141 */
Jens Axboe802ad4a2011-10-05 09:51:58 +0200142 if (len > 1)
143 qsort((void*)plist, len, sizeof(plist[0]), double_cmp);
Yu-ju Hong83349192011-08-13 00:53:44 +0200144
Jens Axboe4f6f8292011-10-13 09:28:21 +0200145 /*
146 * Calculate bucket values, note down max and min values
147 */
Jens Axboe07511a62011-10-13 12:00:24 +0200148 is_last = 0;
149 for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) {
Yu-ju Hong83349192011-08-13 00:53:44 +0200150 sum += io_u_plat[i];
Jens Axboe802ad4a2011-10-05 09:51:58 +0200151 while (sum >= (plist[j].u.f / 100.0 * nr)) {
152 assert(plist[j].u.f <= 100.0);
Yu-ju Hong83349192011-08-13 00:53:44 +0200153
Jens Axboe4f6f8292011-10-13 09:28:21 +0200154 if (j == oval_len) {
155 oval_len += 100;
156 ovals = realloc(ovals, oval_len * sizeof(unsigned int));
157 }
Yu-ju Hong83349192011-08-13 00:53:44 +0200158
Jens Axboe4f6f8292011-10-13 09:28:21 +0200159 ovals[j] = plat_idx_to_val(i);
Jens Axboe1db92cb2011-10-13 13:43:36 +0200160 if (ovals[j] < *minv)
161 *minv = ovals[j];
162 if (ovals[j] > *maxv)
163 *maxv = ovals[j];
Jens Axboe07511a62011-10-13 12:00:24 +0200164
165 is_last = (j == len - 1);
166 if (is_last)
167 break;
168
Jens Axboe4f6f8292011-10-13 09:28:21 +0200169 j++;
Yu-ju Hong83349192011-08-13 00:53:44 +0200170 }
171 }
Jens Axboe4f6f8292011-10-13 09:28:21 +0200172
Jens Axboe1db92cb2011-10-13 13:43:36 +0200173 *output = ovals;
174 return len;
175}
176
177/*
178 * Find and display the p-th percentile of clat
179 */
180static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
181 fio_fp64_t *plist)
182{
183 unsigned int len, j = 0, minv, maxv;
184 unsigned int *ovals;
185 int is_last, scale_down;
186
187 len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
188 if (!len)
189 goto out;
190
Jens Axboe4f6f8292011-10-13 09:28:21 +0200191 /*
192 * We default to usecs, but if the value range is such that we
193 * should scale down to msecs, do that.
194 */
195 if (minv > 2000 && maxv > 99999) {
196 scale_down = 1;
197 log_info(" clat percentiles (msec):\n |");
198 } else {
199 scale_down = 0;
200 log_info(" clat percentiles (usec):\n |");
201 }
202
203 for (j = 0; j < len; j++) {
204 char fbuf[8];
205
206 /* for formatting */
207 if (j != 0 && (j % 4) == 0)
208 log_info(" |");
209
210 /* end of the list */
211 is_last = (j == len - 1);
212
213 if (plist[j].u.f < 10.0)
214 sprintf(fbuf, " %2.2f", plist[j].u.f);
215 else
216 sprintf(fbuf, "%2.2f", plist[j].u.f);
217
218 if (scale_down)
219 ovals[j] = (ovals[j] + 999) / 1000;
220
221 log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ',');
222
223 if (is_last)
224 break;
225
226 if (j % 4 == 3) /* for formatting */
227 log_info("\n");
228 }
229
Jens Axboe1db92cb2011-10-13 13:43:36 +0200230out:
Jens Axboe4f6f8292011-10-13 09:28:21 +0200231 if (ovals)
232 free(ovals);
Yu-ju Hong83349192011-08-13 00:53:44 +0200233}
234
Jens Axboeb29ad562012-03-05 13:08:51 +0100235int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
236 double *mean, double *dev)
Jens Axboe3c39a372006-06-06 20:56:12 +0200237{
Jens Axboe68704082007-01-10 19:56:37 +0100238 double n = is->samples;
Jens Axboe3c39a372006-06-06 20:56:12 +0200239
240 if (is->samples == 0)
241 return 0;
242
243 *min = is->min_val;
244 *max = is->max_val;
245
246 n = (double) is->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200247 *mean = is->mean.u.f;
Jens Axboe3c39a372006-06-06 20:56:12 +0200248
Jens Axboe68704082007-01-10 19:56:37 +0100249 if (n > 1.0)
Jens Axboe802ad4a2011-10-05 09:51:58 +0200250 *dev = sqrt(is->S.u.f / (n - 1.0));
Jens Axboeef9c5c42007-01-03 14:21:13 +0100251 else
Jens Axboe4b43f542007-07-19 21:38:35 +0200252 *dev = 0;
Jens Axboeef9c5c42007-01-03 14:21:13 +0100253
Jens Axboe3c39a372006-06-06 20:56:12 +0200254 return 1;
255}
256
Jens Axboea64e88d2011-10-03 14:20:01 +0200257void show_group_stats(struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200258{
Jens Axboedbe11252007-02-11 00:19:51 +0100259 char *p1, *p2, *p3, *p4;
260 const char *ddir_str[] = { " READ", " WRITE" };
261 int i;
262
Jens Axboe7e1773b2011-10-14 12:47:56 +0200263 log_info("\nRun status group %d (all jobs):\n", rs->groupid);
Jens Axboe3c39a372006-06-06 20:56:12 +0200264
Jens Axboedbe11252007-02-11 00:19:51 +0100265 for (i = 0; i <= DDIR_WRITE; i++) {
Jens Axboe90fef2d2009-07-17 22:33:32 +0200266 const int i2p = is_power_of_2(rs->kb_base);
267
Jens Axboedbe11252007-02-11 00:19:51 +0100268 if (!rs->max_run[i])
269 continue;
270
Jens Axboe90fef2d2009-07-17 22:33:32 +0200271 p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p);
272 p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p);
273 p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p);
274 p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p);
Jens Axboedbe11252007-02-11 00:19:51 +0100275
Jens Axboeb22989b2009-07-17 22:29:23 +0200276 log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s,"
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100277 " mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2,
278 p3, p4, rs->min_run[i],
279 rs->max_run[i]);
Jens Axboedbe11252007-02-11 00:19:51 +0100280
281 free(p1);
282 free(p2);
283 free(p3);
284 free(p4);
285 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200286}
287
Jens Axboeb3605062007-03-12 14:19:47 +0100288#define ts_total_io_u(ts) \
289 ((ts)->total_io_u[0] + (ts)->total_io_u[1])
290
Jens Axboe838bc702008-05-22 13:08:23 +0200291static void stat_calc_dist(unsigned int *map, unsigned long total,
292 double *io_u_dist)
Jens Axboe22708902007-03-06 17:05:32 +0100293{
294 int i;
295
296 /*
297 * Do depth distribution calculations
298 */
299 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200300 if (total) {
301 io_u_dist[i] = (double) map[i] / (double) total;
302 io_u_dist[i] *= 100.0;
303 if (io_u_dist[i] < 0.1 && map[i])
304 io_u_dist[i] = 0.1;
305 } else
306 io_u_dist[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100307 }
308}
309
Jens Axboe04a0fea2007-06-19 12:48:41 +0200310static void stat_calc_lat(struct thread_stat *ts, double *dst,
311 unsigned int *src, int nr)
Jens Axboe22708902007-03-06 17:05:32 +0100312{
Jens Axboe838bc702008-05-22 13:08:23 +0200313 unsigned long total = ts_total_io_u(ts);
Jens Axboe22708902007-03-06 17:05:32 +0100314 int i;
315
316 /*
317 * Do latency distribution calculations
318 */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200319 for (i = 0; i < nr; i++) {
Jens Axboe838bc702008-05-22 13:08:23 +0200320 if (total) {
321 dst[i] = (double) src[i] / (double) total;
322 dst[i] *= 100.0;
323 if (dst[i] < 0.01 && src[i])
324 dst[i] = 0.01;
325 } else
326 dst[i] = 0.0;
Jens Axboe22708902007-03-06 17:05:32 +0100327 }
328}
329
Jens Axboe04a0fea2007-06-19 12:48:41 +0200330static void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
331{
332 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
333}
334
335static void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
336{
337 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
338}
339
Jens Axboeb29ad562012-03-05 13:08:51 +0100340static void display_lat(const char *name, unsigned long min, unsigned long max,
341 double mean, double dev)
Jens Axboeea2accc2007-06-19 09:48:44 +0200342{
Jens Axboeb29ad562012-03-05 13:08:51 +0100343 const char *base = "(usec)";
344 char *minp, *maxp;
Jens Axboeea2accc2007-06-19 09:48:44 +0200345
Jens Axboeb29ad562012-03-05 13:08:51 +0100346 if (!usec_to_msec(&min, &max, &mean, &dev))
347 base = "(msec)";
348
349 minp = num2str(min, 6, 1, 0);
350 maxp = num2str(max, 6, 1, 0);
351
352 log_info(" %s %s: min=%s, max=%s, avg=%5.02f,"
353 " stdev=%5.02f\n", name, base, minp, maxp, mean, dev);
354
355 free(minp);
356 free(maxp);
Jens Axboeea2accc2007-06-19 09:48:44 +0200357}
358
Jens Axboe756867b2007-03-06 15:19:24 +0100359static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
Jens Axboe3c39a372006-06-06 20:56:12 +0200360 int ddir)
361{
Jens Axboe3c9b60c2006-11-07 08:36:14 +0100362 const char *ddir_str[] = { "read ", "write" };
Jens Axboe8879fd12009-04-20 10:06:02 +0200363 unsigned long min, max, runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100364 unsigned long long bw, iops;
Jens Axboe3c39a372006-06-06 20:56:12 +0200365 double mean, dev;
Jens Axboeb3605062007-03-12 14:19:47 +0100366 char *io_p, *bw_p, *iops_p;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200367 int i2p;
Jens Axboe3c39a372006-06-06 20:56:12 +0200368
Jens Axboeff58fce2010-08-25 12:02:08 +0200369 assert(ddir_rw(ddir));
370
Jens Axboe756867b2007-03-06 15:19:24 +0100371 if (!ts->runtime[ddir])
Jens Axboe3c39a372006-06-06 20:56:12 +0200372 return;
373
Jens Axboe90fef2d2009-07-17 22:33:32 +0200374 i2p = is_power_of_2(rs->kb_base);
Jens Axboe8879fd12009-04-20 10:06:02 +0200375 runt = ts->runtime[ddir];
376
377 bw = (1000 * ts->io_bytes[ddir]) / runt;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200378 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
379 bw_p = num2str(bw, 6, 1, i2p);
Jens Axboe8879fd12009-04-20 10:06:02 +0200380
Bruce Cran0aacc502011-07-09 08:19:53 +0200381 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
Jens Axboeb3605062007-03-12 14:19:47 +0100382 iops_p = num2str(iops, 6, 1, 0);
Jens Axboedbe11252007-02-11 00:19:51 +0100383
Signed-off-by Steven Prattcda99fa2010-12-14 08:31:36 +0100384 log_info(" %s: io=%sB, bw=%sB/s, iops=%s, runt=%6llumsec\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100385 ddir_str[ddir], io_p, bw_p, iops_p,
386 ts->runtime[ddir]);
Jens Axboedbe11252007-02-11 00:19:51 +0100387
388 free(io_p);
389 free(bw_p);
Jens Axboeb3605062007-03-12 14:19:47 +0100390 free(iops_p);
Jens Axboe3c39a372006-06-06 20:56:12 +0200391
Jens Axboeb29ad562012-03-05 13:08:51 +0100392 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
393 display_lat("slat", min, max, mean, dev);
394 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
395 display_lat("clat", min, max, mean, dev);
396 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
397 display_lat(" lat", min, max, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200398
Yu-ju Hong83349192011-08-13 00:53:44 +0200399 if (ts->clat_percentiles) {
400 show_clat_percentiles(ts->io_u_plat[ddir],
401 ts->clat_stat[ddir].samples,
402 ts->percentile_list);
403 }
Jens Axboe079ad092007-02-20 13:58:20 +0100404 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100405 double p_of_agg = 100.0;
Jens Axboeb7017e32011-10-14 09:30:01 +0200406 const char *bw_str = "KB";
Jens Axboe3c39a372006-06-06 20:56:12 +0200407
Jens Axboe2f2c6922012-02-07 16:42:43 +0100408 if (rs->agg[ddir]) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100409 p_of_agg = mean * 100 / (double) rs->agg[ddir];
410 if (p_of_agg > 100.0)
411 p_of_agg = 100.0;
412 }
Jens Axboeb7017e32011-10-14 09:30:01 +0200413
414 if (mean > 999999.9) {
415 min /= 1000.0;
416 max /= 1000.0;
417 mean /= 1000.0;
418 dev /= 1000.0;
419 bw_str = "MB";
420 }
421
Jens Axboe7e1773b2011-10-14 12:47:56 +0200422 log_info(" bw (%s/s) : min=%5lu, max=%5lu, per=%3.2f%%,"
Jens Axboeb7017e32011-10-14 09:30:01 +0200423 " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max,
424 p_of_agg, mean, dev);
Jens Axboe3c39a372006-06-06 20:56:12 +0200425 }
426}
427
Jens Axboe7e1773b2011-10-14 12:47:56 +0200428static int show_lat(double *io_u_lat, int nr, const char **ranges,
429 const char *msg)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200430{
Jens Axboe7e1773b2011-10-14 12:47:56 +0200431 int new_line = 1, i, line = 0, shown = 0;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200432
433 for (i = 0; i < nr; i++) {
434 if (io_u_lat[i] <= 0.0)
435 continue;
Jens Axboe7e1773b2011-10-14 12:47:56 +0200436 shown = 1;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200437 if (new_line) {
Jens Axboe4539ed72007-07-23 14:21:17 +0200438 if (line)
439 log_info("\n");
Jens Axboe7e1773b2011-10-14 12:47:56 +0200440 log_info(" lat (%s) : ", msg);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200441 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 Axboe7e1773b2011-10-14 12:47:56 +0200451
452 if (shown)
453 log_info("\n");
454
455 return shown;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200456}
457
458static void show_lat_u(double *io_u_lat_u)
459{
460 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
461 "250=", "500=", "750=", "1000=", };
462
463 show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec");
464}
465
466static void show_lat_m(double *io_u_lat_m)
467{
468 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
469 "250=", "500=", "750=", "1000=", "2000=",
470 ">=2000=", };
471
472 show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec");
473}
474
Jens Axboec551f652012-03-05 20:49:10 +0100475static void show_latencies(struct thread_stat *ts)
Jens Axboe04a0fea2007-06-19 12:48:41 +0200476{
Jens Axboec551f652012-03-05 20:49:10 +0100477 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
478 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
479
Jens Axboe5a189882012-03-05 14:08:34 +0100480 stat_calc_lat_u(ts, io_u_lat_u);
481 stat_calc_lat_m(ts, io_u_lat_m);
482
Jens Axboe04a0fea2007-06-19 12:48:41 +0200483 show_lat_u(io_u_lat_u);
484 show_lat_m(io_u_lat_m);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200485}
486
Jens Axboea64e88d2011-10-03 14:20:01 +0200487void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs)
Jens Axboe3c39a372006-06-06 20:56:12 +0200488{
489 double usr_cpu, sys_cpu;
Jens Axboe69008992006-11-24 13:12:56 +0100490 unsigned long runtime;
Jens Axboe71619dc2007-01-13 23:56:33 +0100491 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe3c39a372006-06-06 20:56:12 +0200492
Jens Axboeb4c5e1a2007-10-25 18:44:45 +0200493 if (!(ts->io_bytes[0] + ts->io_bytes[1]) &&
494 !(ts->total_io_u[0] + ts->total_io_u[1]))
Jens Axboe3c39a372006-06-06 20:56:12 +0200495 return;
496
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100497 if (!ts->error) {
498 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n",
499 ts->name, ts->groupid, ts->members,
Jens Axboe5921e802008-05-30 15:02:38 +0200500 ts->error, (int) ts->pid);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100501 } else {
502 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d\n",
503 ts->name, ts->groupid, ts->members,
Jens Axboe5921e802008-05-30 15:02:38 +0200504 ts->error, ts->verror, (int) ts->pid);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100505 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200506
Jens Axboe259e47d2011-10-13 21:05:59 +0200507 if (strlen(ts->description))
Jens Axboe6d861442007-03-15 09:22:23 +0100508 log_info(" Description : [%s]\n", ts->description);
Jens Axboe7bdce1b2007-03-06 20:01:13 +0100509
Jens Axboe756867b2007-03-06 15:19:24 +0100510 if (ts->io_bytes[DDIR_READ])
511 show_ddir_status(rs, ts, DDIR_READ);
512 if (ts->io_bytes[DDIR_WRITE])
513 show_ddir_status(rs, ts, DDIR_WRITE);
Jens Axboe3c39a372006-06-06 20:56:12 +0200514
Jens Axboec551f652012-03-05 20:49:10 +0100515 show_latencies(ts);
Jens Axboe7e1773b2011-10-14 12:47:56 +0200516
Jens Axboe756867b2007-03-06 15:19:24 +0100517 runtime = ts->total_run_time;
Jens Axboe69008992006-11-24 13:12:56 +0100518 if (runtime) {
Jens Axboe1e97cce2006-12-05 11:44:16 +0100519 double runt = (double) runtime;
Jens Axboe3c39a372006-06-06 20:56:12 +0200520
Jens Axboe756867b2007-03-06 15:19:24 +0100521 usr_cpu = (double) ts->usr_time * 100 / runt;
522 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboe3c39a372006-06-06 20:56:12 +0200523 } else {
524 usr_cpu = 0;
525 sys_cpu = 0;
526 }
527
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100528 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu,"
529 " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf);
Jens Axboe71619dc2007-01-13 23:56:33 +0100530
Jens Axboe838bc702008-05-22 13:08:23 +0200531 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100532 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%,"
533 " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
534 io_u_dist[1], io_u_dist[2],
535 io_u_dist[3], io_u_dist[4],
536 io_u_dist[5], io_u_dist[6]);
Jens Axboe838bc702008-05-22 13:08:23 +0200537
538 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
539 log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
540 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
541 io_u_dist[1], io_u_dist[2],
542 io_u_dist[3], io_u_dist[4],
543 io_u_dist[5], io_u_dist[6]);
544 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
545 log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
546 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
547 io_u_dist[1], io_u_dist[2],
548 io_u_dist[3], io_u_dist[4],
549 io_u_dist[5], io_u_dist[6]);
Jens Axboe7e1773b2011-10-14 12:47:56 +0200550 log_info(" issued : total=r=%lu/w=%lu/d=%lu,"
551 " short=r=%lu/w=%lu/d=%lu\n",
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100552 ts->total_io_u[0], ts->total_io_u[1],
Jens Axboe0d29de82010-09-01 13:54:15 +0200553 ts->total_io_u[2],
554 ts->short_io_u[0], ts->short_io_u[1],
555 ts->short_io_u[2]);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200556 if (ts->continue_on_error) {
Jens Axboe1ec99ee2009-06-15 12:37:30 +0200557 log_info(" errors : total=%lu, first_error=%d/<%s>\n",
558 ts->total_err_count,
559 ts->first_error,
560 strerror(ts->first_error));
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200561 }
Jens Axboe3c39a372006-06-06 20:56:12 +0200562}
563
Jens Axboe756867b2007-03-06 15:19:24 +0100564static void show_ddir_status_terse(struct thread_stat *ts,
Jens Axboec6ae0a52006-06-12 11:04:44 +0200565 struct group_run_stats *rs, int ddir)
566{
567 unsigned long min, max;
Jens Axboe312b4af2011-10-13 13:11:42 +0200568 unsigned long long bw, iops;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200569 unsigned int *ovals = NULL;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200570 double mean, dev;
Jens Axboe1db92cb2011-10-13 13:43:36 +0200571 unsigned int len, minv, maxv;
572 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200573
Jens Axboeff58fce2010-08-25 12:02:08 +0200574 assert(ddir_rw(ddir));
575
Jens Axboe312b4af2011-10-13 13:11:42 +0200576 iops = bw = 0;
577 if (ts->runtime[ddir]) {
578 uint64_t runt = ts->runtime[ddir];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200579
Jens Axboe312b4af2011-10-13 13:11:42 +0200580 bw = ts->io_bytes[ddir] / runt;
581 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
582 }
583
584 log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops,
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100585 ts->runtime[ddir]);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200586
Jens Axboe079ad092007-02-20 13:58:20 +0100587 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100588 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200589 else
Jens Axboe6d861442007-03-15 09:22:23 +0100590 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200591
Jens Axboe079ad092007-02-20 13:58:20 +0100592 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboe6d861442007-03-15 09:22:23 +0100593 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200594 else
Jens Axboe6d861442007-03-15 09:22:23 +0100595 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200596
Jens Axboe1db92cb2011-10-13 13:43:36 +0200597 if (ts->clat_percentiles) {
598 len = calc_clat_percentiles(ts->io_u_plat[ddir],
599 ts->clat_stat[ddir].samples,
600 ts->percentile_list, &ovals, &maxv,
601 &minv);
602 } else
603 len = 0;
604
605 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
606 if (i >= len) {
607 log_info(";0%%=0");
608 continue;
609 }
610 log_info(";%2.2f%%=%u", ts->percentile_list[i].u.f, ovals[i]);
611 }
Keplar kramer2341a372011-10-19 21:31:27 +0200612
613 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
614 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
615 else
616 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
617
Jens Axboe1db92cb2011-10-13 13:43:36 +0200618 if (ovals)
619 free(ovals);
620
Jens Axboe079ad092007-02-20 13:58:20 +0100621 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
Jens Axboe19d3e962012-02-07 12:27:28 +0100622 double p_of_agg = 100.0;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200623
Jens Axboe19d3e962012-02-07 12:27:28 +0100624 if (rs->agg[ddir]) {
625 p_of_agg = mean * 100 / (double) rs->agg[ddir];
626 if (p_of_agg > 100.0)
627 p_of_agg = 100.0;
628 }
629
Jens Axboe6d861442007-03-15 09:22:23 +0100630 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200631 } else
Jens Axboe6d861442007-03-15 09:22:23 +0100632 log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200633}
634
Jens Axboe4d658652011-10-17 15:05:47 +0200635static void show_thread_status_terse_v2(struct thread_stat *ts,
636 struct group_run_stats *rs)
637{
638 double io_u_dist[FIO_IO_U_MAP_NR];
639 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
640 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
641 double usr_cpu, sys_cpu;
642 int i;
643
644 /* General Info */
645 log_info("2;%s;%d;%d", ts->name, ts->groupid, ts->error);
646 /* Log Read Status */
647 show_ddir_status_terse(ts, rs, 0);
648 /* Log Write Status */
649 show_ddir_status_terse(ts, rs, 1);
650
651 /* CPU Usage */
652 if (ts->total_run_time) {
653 double runt = (double) ts->total_run_time;
654
655 usr_cpu = (double) ts->usr_time * 100 / runt;
656 sys_cpu = (double) ts->sys_time * 100 / runt;
657 } else {
658 usr_cpu = 0;
659 sys_cpu = 0;
660 }
661
662 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
663 ts->minf);
664
665 /* Calc % distribution of IO depths, usecond, msecond latency */
666 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
667 stat_calc_lat_u(ts, io_u_lat_u);
668 stat_calc_lat_m(ts, io_u_lat_m);
669
670 /* Only show fixed 7 I/O depth levels*/
671 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
672 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
673 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
674
675 /* Microsecond latency */
676 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
677 log_info(";%3.2f%%", io_u_lat_u[i]);
678 /* Millisecond latency */
679 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
680 log_info(";%3.2f%%", io_u_lat_m[i]);
681 /* Additional output if continue_on_error set - default off*/
682 if (ts->continue_on_error)
683 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
684 log_info("\n");
685
686 /* Additional output if description is set */
687 if (ts->description)
688 log_info(";%s", ts->description);
689
690 log_info("\n");
691}
692
Jens Axboe312b4af2011-10-13 13:11:42 +0200693#define FIO_TERSE_VERSION "3"
Jens Axboec6ae0a52006-06-12 11:04:44 +0200694
Jens Axboe4d658652011-10-17 15:05:47 +0200695static void show_thread_status_terse_v3(struct thread_stat *ts,
696 struct group_run_stats *rs)
Jens Axboec6ae0a52006-06-12 11:04:44 +0200697{
Jens Axboe22708902007-03-06 17:05:32 +0100698 double io_u_dist[FIO_IO_U_MAP_NR];
Jens Axboe04a0fea2007-06-19 12:48:41 +0200699 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
700 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
Jens Axboec6ae0a52006-06-12 11:04:44 +0200701 double usr_cpu, sys_cpu;
Jens Axboe04a0fea2007-06-19 12:48:41 +0200702 int i;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200703
David Nellans562c2d22010-09-23 08:38:17 +0200704 /* General Info */
Jens Axboe5e726d02011-10-14 08:08:10 +0200705 log_info("%s;%s;%s;%d;%d", FIO_TERSE_VERSION, fio_version_string,
706 ts->name, ts->groupid, ts->error);
David Nellans562c2d22010-09-23 08:38:17 +0200707 /* Log Read Status */
Jens Axboe756867b2007-03-06 15:19:24 +0100708 show_ddir_status_terse(ts, rs, 0);
David Nellans562c2d22010-09-23 08:38:17 +0200709 /* Log Write Status */
Jens Axboe756867b2007-03-06 15:19:24 +0100710 show_ddir_status_terse(ts, rs, 1);
Jens Axboec6ae0a52006-06-12 11:04:44 +0200711
David Nellans562c2d22010-09-23 08:38:17 +0200712 /* CPU Usage */
Jens Axboe756867b2007-03-06 15:19:24 +0100713 if (ts->total_run_time) {
714 double runt = (double) ts->total_run_time;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200715
Jens Axboe756867b2007-03-06 15:19:24 +0100716 usr_cpu = (double) ts->usr_time * 100 / runt;
717 sys_cpu = (double) ts->sys_time * 100 / runt;
Jens Axboec6ae0a52006-06-12 11:04:44 +0200718 } else {
719 usr_cpu = 0;
720 sys_cpu = 0;
721 }
722
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100723 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
724 ts->minf);
Jens Axboe22708902007-03-06 17:05:32 +0100725
David Nellans562c2d22010-09-23 08:38:17 +0200726 /* Calc % distribution of IO depths, usecond, msecond latency */
Jens Axboe838bc702008-05-22 13:08:23 +0200727 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200728 stat_calc_lat_u(ts, io_u_lat_u);
729 stat_calc_lat_m(ts, io_u_lat_m);
Jens Axboe22708902007-03-06 17:05:32 +0100730
David Nellans562c2d22010-09-23 08:38:17 +0200731 /* Only show fixed 7 I/O depth levels*/
Jens Axboe5ec10ea2008-03-06 15:42:00 +0100732 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
733 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
734 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
Jens Axboe22708902007-03-06 17:05:32 +0100735
David Nellans562c2d22010-09-23 08:38:17 +0200736 /* Microsecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200737 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
738 log_info(";%3.2f%%", io_u_lat_u[i]);
David Nellans562c2d22010-09-23 08:38:17 +0200739 /* Millisecond latency */
Jens Axboe04a0fea2007-06-19 12:48:41 +0200740 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
741 log_info(";%3.2f%%", io_u_lat_m[i]);
Jens Axboef2f788d2011-10-13 14:03:52 +0200742
743 /* disk util stats, if any */
744 show_disk_util(1);
745
David Nellans562c2d22010-09-23 08:38:17 +0200746 /* Additional output if continue_on_error set - default off*/
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200747 if (ts->continue_on_error)
748 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
Jens Axboe04a0fea2007-06-19 12:48:41 +0200749 log_info("\n");
Jens Axboe22708902007-03-06 17:05:32 +0100750
David Nellans562c2d22010-09-23 08:38:17 +0200751 /* Additional output if description is set */
Jens Axboe4b0f2252011-10-13 15:03:25 +0200752 if (strlen(ts->description))
Jens Axboe6d861442007-03-15 09:22:23 +0100753 log_info(";%s", ts->description);
Jens Axboe756867b2007-03-06 15:19:24 +0100754}
755
Jens Axboe4d658652011-10-17 15:05:47 +0200756static void show_thread_status_terse(struct thread_stat *ts,
757 struct group_run_stats *rs)
758{
759 if (terse_version == 2)
760 show_thread_status_terse_v2(ts, rs);
761 else if (terse_version == 3)
762 show_thread_status_terse_v3(ts, rs);
763 else
764 log_err("fio: bad terse version!? %d\n", terse_version);
765}
766
Jens Axboe197574e2007-03-08 15:35:11 +0100767static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
Jens Axboe756867b2007-03-06 15:19:24 +0100768{
769 double mean, S;
770
Zheng Liue09231c2011-09-16 08:20:12 +0200771 if (src->samples == 0)
772 return;
773
Jens Axboe756867b2007-03-06 15:19:24 +0100774 dst->min_val = min(dst->min_val, src->min_val);
775 dst->max_val = max(dst->max_val, src->max_val);
Jens Axboe756867b2007-03-06 15:19:24 +0100776
777 /*
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200778 * Compute new mean and S after the merge
779 * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
780 * #Parallel_algorithm>
Jens Axboe756867b2007-03-06 15:19:24 +0100781 */
782 if (nr == 1) {
Jens Axboe802ad4a2011-10-05 09:51:58 +0200783 mean = src->mean.u.f;
784 S = src->S.u.f;
Jens Axboe756867b2007-03-06 15:19:24 +0100785 } else {
Jens Axboe802ad4a2011-10-05 09:51:58 +0200786 double delta = src->mean.u.f - dst->mean.u.f;
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200787
Jens Axboe802ad4a2011-10-05 09:51:58 +0200788 mean = ((src->mean.u.f * src->samples) +
789 (dst->mean.u.f * dst->samples)) /
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200790 (dst->samples + src->samples);
791
Jens Axboe802ad4a2011-10-05 09:51:58 +0200792 S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) *
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200793 (dst->samples * src->samples) /
794 (dst->samples + src->samples);
Jens Axboe756867b2007-03-06 15:19:24 +0100795 }
796
Yu-ju Hongcdcac5c2011-07-30 09:18:13 +0200797 dst->samples += src->samples;
Jens Axboe802ad4a2011-10-05 09:51:58 +0200798 dst->mean.u.f = mean;
799 dst->S.u.f = S;
Jens Axboe756867b2007-03-06 15:19:24 +0100800}
801
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200802void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src)
803{
804 int i;
805
806 for (i = 0; i < 2; i++) {
807 if (dst->max_run[i] < src->max_run[i])
808 dst->max_run[i] = src->max_run[i];
809 if (dst->min_run[i] && dst->min_run[i] > src->min_run[i])
810 dst->min_run[i] = src->min_run[i];
811 if (dst->max_bw[i] < src->max_bw[i])
812 dst->max_bw[i] = src->max_bw[i];
813 if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i])
814 dst->min_bw[i] = src->min_bw[i];
815
816 dst->io_kb[i] += src->io_kb[i];
817 dst->agg[i] += src->agg[i];
818 }
819
820}
821
Jens Axboe5b9babb2011-10-10 12:14:30 +0200822void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr)
823{
824 int l, k;
825
826 for (l = 0; l <= DDIR_WRITE; l++) {
827 sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr);
828 sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr);
829 sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr);
830 sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr);
831
832 dst->io_bytes[l] += src->io_bytes[l];
833
834 if (dst->runtime[l] < src->runtime[l])
835 dst->runtime[l] = src->runtime[l];
836 }
837
838 dst->usr_time += src->usr_time;
839 dst->sys_time += src->sys_time;
840 dst->ctx += src->ctx;
841 dst->majf += src->majf;
842 dst->minf += src->minf;
843
844 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
845 dst->io_u_map[k] += src->io_u_map[k];
846 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
847 dst->io_u_submit[k] += src->io_u_submit[k];
848 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
849 dst->io_u_complete[k] += src->io_u_complete[k];
850 for (k = 0; k < FIO_IO_U_LAT_U_NR; k++)
851 dst->io_u_lat_u[k] += src->io_u_lat_u[k];
852 for (k = 0; k < FIO_IO_U_LAT_M_NR; k++)
853 dst->io_u_lat_m[k] += src->io_u_lat_m[k];
854
855 for (k = 0; k <= 2; k++) {
856 dst->total_io_u[k] += src->total_io_u[k];
857 dst->short_io_u[k] += src->short_io_u[k];
858 }
859
860 for (k = 0; k <= DDIR_WRITE; k++) {
861 int m;
862 for (m = 0; m < FIO_IO_U_PLAT_NR; m++)
863 dst->io_u_plat[k][m] += src->io_u_plat[k][m];
864 }
865
866 dst->total_run_time += src->total_run_time;
867 dst->total_submit += src->total_submit;
868 dst->total_complete += src->total_complete;
869}
870
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200871void init_group_run_stat(struct group_run_stats *gs)
872{
873 memset(gs, 0, sizeof(*gs));
874 gs->min_bw[0] = gs->min_run[0] = ~0UL;
875 gs->min_bw[1] = gs->min_run[1] = ~0UL;
876}
877
878void init_thread_stat(struct thread_stat *ts)
879{
880 int j;
881
882 memset(ts, 0, sizeof(*ts));
883
884 for (j = 0; j <= DDIR_WRITE; j++) {
885 ts->lat_stat[j].min_val = -1UL;
886 ts->clat_stat[j].min_val = -1UL;
887 ts->slat_stat[j].min_val = -1UL;
888 ts->bw_stat[j].min_val = -1UL;
889 }
890 ts->groupid = -1;
891}
892
Jens Axboe3c39a372006-06-06 20:56:12 +0200893void show_run_stats(void)
894{
895 struct group_run_stats *runstats, *rs;
896 struct thread_data *td;
Jens Axboe756867b2007-03-06 15:19:24 +0100897 struct thread_stat *threadstats, *ts;
Jens Axboe5b9babb2011-10-10 12:14:30 +0200898 int i, j, nr_ts, last_ts, idx;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200899 int kb_base_warned = 0;
Jens Axboe3c39a372006-06-06 20:56:12 +0200900
901 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
902
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200903 for (i = 0; i < groupid + 1; i++)
904 init_group_run_stat(&runstats[i]);
Jens Axboe3c39a372006-06-06 20:56:12 +0200905
Jens Axboe756867b2007-03-06 15:19:24 +0100906 /*
907 * find out how many threads stats we need. if group reporting isn't
908 * enabled, it's one-per-td.
909 */
910 nr_ts = 0;
911 last_ts = -1;
Jens Axboe34572e22006-10-20 09:33:18 +0200912 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100913 if (!td->o.group_reporting) {
Jens Axboe756867b2007-03-06 15:19:24 +0100914 nr_ts++;
915 continue;
916 }
917 if (last_ts == td->groupid)
918 continue;
919
920 last_ts = td->groupid;
921 nr_ts++;
922 }
923
924 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
925
Jens Axboe37f0c1a2011-10-11 14:08:33 +0200926 for (i = 0; i < nr_ts; i++)
927 init_thread_stat(&threadstats[i]);
Jens Axboe756867b2007-03-06 15:19:24 +0100928
929 j = 0;
930 last_ts = -1;
Jens Axboe197574e2007-03-08 15:35:11 +0100931 idx = 0;
Jens Axboe756867b2007-03-06 15:19:24 +0100932 for_each_td(td, i) {
Jens Axboe2dc1bbe2007-03-15 15:01:33 +0100933 if (idx && (!td->o.group_reporting ||
934 (td->o.group_reporting && last_ts != td->groupid))) {
Jens Axboe7abd0e32007-03-12 15:24:43 +0100935 idx = 0;
936 j++;
937 }
938
939 last_ts = td->groupid;
940
Jens Axboe756867b2007-03-06 15:19:24 +0100941 ts = &threadstats[j];
942
Yu-ju Hong83349192011-08-13 00:53:44 +0200943 ts->clat_percentiles = td->o.clat_percentiles;
944 if (td->o.overwrite_plist)
Jens Axboe802ad4a2011-10-05 09:51:58 +0200945 memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +0200946 else
Jens Axboe802ad4a2011-10-05 09:51:58 +0200947 memcpy(ts->percentile_list, def_percentile_list, sizeof(def_percentile_list));
Yu-ju Hong83349192011-08-13 00:53:44 +0200948
Jens Axboe197574e2007-03-08 15:35:11 +0100949 idx++;
Jens Axboe6586ee82007-03-06 19:46:09 +0100950 ts->members++;
Jens Axboe756867b2007-03-06 15:19:24 +0100951
Jens Axboe7abd0e32007-03-12 15:24:43 +0100952 if (ts->groupid == -1) {
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100953 /*
954 * These are per-group shared already
955 */
Jens Axboef6bb5b82011-10-03 12:21:25 +0200956 strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE);
Jens Axboea64e88d2011-10-03 14:20:01 +0200957 if (td->o.description)
958 strncpy(ts->description, td->o.description,
959 FIO_JOBNAME_SIZE);
960 else
961 memset(ts->description, 0, FIO_JOBNAME_SIZE);
962
Jens Axboe756867b2007-03-06 15:19:24 +0100963 ts->groupid = td->groupid;
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100964
965 /*
966 * first pid in group, not very useful...
967 */
Jens Axboe756867b2007-03-06 15:19:24 +0100968 ts->pid = td->pid;
Jens Axboe90fef2d2009-07-17 22:33:32 +0200969
970 ts->kb_base = td->o.kb_base;
971 } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) {
972 log_info("fio: kb_base differs for jobs in group, using"
973 " %u as the base\n", ts->kb_base);
974 kb_base_warned = 1;
Jens Axboe2dc84ba2007-03-06 15:46:33 +0100975 }
976
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200977 ts->continue_on_error = td->o.continue_on_error;
978 ts->total_err_count += td->total_err_count;
979 ts->first_error = td->first_error;
980 if (!ts->error) {
981 if (!td->error && td->o.continue_on_error &&
982 td->first_error) {
983 ts->error = td->first_error;
Jens Axboef6bb5b82011-10-03 12:21:25 +0200984 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200985 } else if (td->error) {
986 ts->error = td->error;
Jens Axboef6bb5b82011-10-03 12:21:25 +0200987 strcpy(ts->verror, td->verror);
Radha Ramachandranf2bba182009-06-15 08:40:16 +0200988 }
Jens Axboe756867b2007-03-06 15:19:24 +0100989 }
990
Jens Axboe5b9babb2011-10-10 12:14:30 +0200991 sum_thread_stats(ts, &td->ts, idx);
Jens Axboe756867b2007-03-06 15:19:24 +0100992 }
993
994 for (i = 0; i < nr_ts; i++) {
Jens Axboe94370ac2007-03-08 15:28:10 +0100995 unsigned long long bw;
Jens Axboe3c39a372006-06-06 20:56:12 +0200996
Jens Axboe756867b2007-03-06 15:19:24 +0100997 ts = &threadstats[i];
998 rs = &runstats[ts->groupid];
Jens Axboe90fef2d2009-07-17 22:33:32 +0200999 rs->kb_base = ts->kb_base;
Jens Axboe3c39a372006-06-06 20:56:12 +02001000
Jens Axboede64df02007-03-08 19:09:49 +01001001 for (j = 0; j <= DDIR_WRITE; j++) {
Jens Axboe94370ac2007-03-08 15:28:10 +01001002 if (!ts->runtime[j])
1003 continue;
1004 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
1005 rs->min_run[j] = ts->runtime[j];
1006 if (ts->runtime[j] > rs->max_run[j])
1007 rs->max_run[j] = ts->runtime[j];
Jens Axboe3c39a372006-06-06 20:56:12 +02001008
Jens Axboe94370ac2007-03-08 15:28:10 +01001009 bw = 0;
Jens Axboe8879fd12009-04-20 10:06:02 +02001010 if (ts->runtime[j]) {
1011 unsigned long runt;
1012
Jens Axboe90fef2d2009-07-17 22:33:32 +02001013 runt = ts->runtime[j];
Jens Axboe8879fd12009-04-20 10:06:02 +02001014 bw = ts->io_bytes[j] / runt;
1015 }
Jens Axboe94370ac2007-03-08 15:28:10 +01001016 if (bw < rs->min_bw[j])
1017 rs->min_bw[j] = bw;
1018 if (bw > rs->max_bw[j])
1019 rs->max_bw[j] = bw;
Jens Axboe3c39a372006-06-06 20:56:12 +02001020
Jens Axboe90fef2d2009-07-17 22:33:32 +02001021 rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base;
Jens Axboe94370ac2007-03-08 15:28:10 +01001022 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001023 }
1024
1025 for (i = 0; i < groupid + 1; i++) {
Jens Axboe8879fd12009-04-20 10:06:02 +02001026 unsigned long max_run[2];
1027
Jens Axboe3c39a372006-06-06 20:56:12 +02001028 rs = &runstats[i];
Jens Axboe90fef2d2009-07-17 22:33:32 +02001029 max_run[0] = rs->max_run[0];
1030 max_run[1] = rs->max_run[1];
Jens Axboe3c39a372006-06-06 20:56:12 +02001031
1032 if (rs->max_run[0])
Jens Axboe4cf1abc2010-06-25 14:33:37 +02001033 rs->agg[0] = (rs->io_kb[0] * 1000) / max_run[0];
Jens Axboe3c39a372006-06-06 20:56:12 +02001034 if (rs->max_run[1])
Jens Axboe4cf1abc2010-06-25 14:33:37 +02001035 rs->agg[1] = (rs->io_kb[1] * 1000) / max_run[1];
Jens Axboe3c39a372006-06-06 20:56:12 +02001036 }
1037
1038 /*
1039 * don't overwrite last signal output
1040 */
Jens Axboec6ae0a52006-06-12 11:04:44 +02001041 if (!terse_output)
Jens Axboe4ceb30d2010-02-24 09:19:14 +01001042 log_info("\n");
Jens Axboe3c39a372006-06-06 20:56:12 +02001043
Jens Axboe756867b2007-03-06 15:19:24 +01001044 for (i = 0; i < nr_ts; i++) {
1045 ts = &threadstats[i];
1046 rs = &runstats[ts->groupid];
Jens Axboe3c39a372006-06-06 20:56:12 +02001047
Jens Axboea64e88d2011-10-03 14:20:01 +02001048 if (is_backend)
1049 fio_server_send_ts(ts, rs);
1050 else if (terse_output)
Jens Axboe756867b2007-03-06 15:19:24 +01001051 show_thread_status_terse(ts, rs);
Jens Axboec6ae0a52006-06-12 11:04:44 +02001052 else
Jens Axboe756867b2007-03-06 15:19:24 +01001053 show_thread_status(ts, rs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001054 }
1055
Jens Axboe72c27ff2011-10-16 11:50:31 +02001056 for (i = 0; i < groupid + 1; i++) {
1057 rs = &runstats[i];
Jens Axboea64e88d2011-10-03 14:20:01 +02001058
Jens Axboe72c27ff2011-10-16 11:50:31 +02001059 rs->groupid = i;
Jens Axboed09a64a2011-10-13 11:38:56 +02001060 if (is_backend)
Jens Axboe72c27ff2011-10-16 11:50:31 +02001061 fio_server_send_gs(rs);
1062 else if (!terse_output)
1063 show_group_stats(rs);
Jens Axboec6ae0a52006-06-12 11:04:44 +02001064 }
Jens Axboeeecf2722006-10-20 14:00:36 +02001065
Jens Axboe72c27ff2011-10-16 11:50:31 +02001066 if (is_backend)
1067 fio_server_send_du();
1068 else if (!terse_output)
1069 show_disk_util(0);
1070
1071 free_disk_util();
1072
Jens Axboeeecf2722006-10-20 14:00:36 +02001073 free(runstats);
Jens Axboe756867b2007-03-06 15:19:24 +01001074 free(threadstats);
Jens Axboe3c39a372006-06-06 20:56:12 +02001075}
1076
Jens Axboe68704082007-01-10 19:56:37 +01001077static inline void add_stat_sample(struct io_stat *is, unsigned long data)
Jens Axboe3c39a372006-06-06 20:56:12 +02001078{
Jens Axboe68704082007-01-10 19:56:37 +01001079 double val = data;
Jens Axboe6660cc62007-03-06 15:48:38 +01001080 double delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001081
Jens Axboe68704082007-01-10 19:56:37 +01001082 if (data > is->max_val)
1083 is->max_val = data;
1084 if (data < is->min_val)
1085 is->min_val = data;
1086
Jens Axboe802ad4a2011-10-05 09:51:58 +02001087 delta = val - is->mean.u.f;
Jens Axboeef11d732007-03-29 15:36:29 +02001088 if (delta) {
Jens Axboe802ad4a2011-10-05 09:51:58 +02001089 is->mean.u.f += delta / (is->samples + 1.0);
1090 is->S.u.f += delta * (val - is->mean.u.f);
Jens Axboeef11d732007-03-29 15:36:29 +02001091 }
Jens Axboe68704082007-01-10 19:56:37 +01001092
Jens Axboe3c39a372006-06-06 20:56:12 +02001093 is->samples++;
1094}
1095
Jens Axboebb3884d2007-01-17 17:23:11 +11001096static void __add_log_sample(struct io_log *iolog, unsigned long val,
Jens Axboe306ddc92009-05-18 13:08:12 +02001097 enum fio_ddir ddir, unsigned int bs,
Jens Axboe2b13e712011-01-19 14:04:16 -07001098 unsigned long t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001099{
Jens Axboe306ddc92009-05-18 13:08:12 +02001100 const int nr_samples = iolog->nr_samples;
1101
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001102 if (!iolog->nr_samples)
1103 iolog->avg_last = t;
1104
Jens Axboe3c39a372006-06-06 20:56:12 +02001105 if (iolog->nr_samples == iolog->max_samples) {
1106 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
1107
1108 iolog->log = realloc(iolog->log, new_size);
1109 iolog->max_samples <<= 1;
1110 }
1111
Jens Axboe306ddc92009-05-18 13:08:12 +02001112 iolog->log[nr_samples].val = val;
Jens Axboe2b13e712011-01-19 14:04:16 -07001113 iolog->log[nr_samples].time = t;
Jens Axboe306ddc92009-05-18 13:08:12 +02001114 iolog->log[nr_samples].ddir = ddir;
1115 iolog->log[nr_samples].bs = bs;
Jens Axboe3c39a372006-06-06 20:56:12 +02001116 iolog->nr_samples++;
1117}
1118
Jens Axboe7fb28d32011-12-01 15:17:24 +01001119static inline void reset_io_stat(struct io_stat *ios)
1120{
1121 ios->max_val = ios->min_val = ios->samples = 0;
1122 ios->mean.u.f = ios->S.u.f = 0;
1123}
1124
Jens Axboebb3884d2007-01-17 17:23:11 +11001125static void add_log_sample(struct thread_data *td, struct io_log *iolog,
Jens Axboe306ddc92009-05-18 13:08:12 +02001126 unsigned long val, enum fio_ddir ddir,
1127 unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001128{
Jens Axboe7fb28d32011-12-01 15:17:24 +01001129 unsigned long elapsed, this_window;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001130
Jens Axboeff58fce2010-08-25 12:02:08 +02001131 if (!ddir_rw(ddir))
1132 return;
1133
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001134 elapsed = mtime_since_now(&td->epoch);
1135
1136 /*
1137 * If no time averaging, just add the log sample.
1138 */
1139 if (!iolog->avg_msec) {
1140 __add_log_sample(iolog, val, ddir, bs, elapsed);
1141 return;
1142 }
1143
1144 /*
1145 * Add the sample. If the time period has passed, then
1146 * add that entry to the log and clear.
1147 */
1148 add_stat_sample(&iolog->avg_window[ddir], val);
1149
Jens Axboe7fb28d32011-12-01 15:17:24 +01001150 /*
1151 * If period hasn't passed, adding the above sample is all we
1152 * need to do.
1153 */
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001154 this_window = elapsed - iolog->avg_last;
1155 if (this_window < iolog->avg_msec)
1156 return;
1157
Jens Axboe7fb28d32011-12-01 15:17:24 +01001158 /*
1159 * Note an entry in the log. Use the mean from the logged samples,
1160 * making sure to properly round up. Only write a log entry if we
1161 * had actual samples done.
1162 */
1163 if (iolog->avg_window[DDIR_READ].samples) {
1164 unsigned long mr;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001165
Jens Axboe7fb28d32011-12-01 15:17:24 +01001166 mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001167 __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed);
Jens Axboe7fb28d32011-12-01 15:17:24 +01001168 }
1169 if (iolog->avg_window[DDIR_WRITE].samples) {
1170 unsigned long mw;
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001171
Jens Axboe7fb28d32011-12-01 15:17:24 +01001172 mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50;
1173 __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed);
1174 }
1175
1176 reset_io_stat(&iolog->avg_window[DDIR_READ]);
1177 reset_io_stat(&iolog->avg_window[DDIR_WRITE]);
Jens Axboeb8bc8cb2011-12-01 09:04:31 +01001178 iolog->avg_last = elapsed;
Jens Axboebb3884d2007-01-17 17:23:11 +11001179}
1180
Jens Axboe306ddc92009-05-18 13:08:12 +02001181void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs)
Jens Axboebb3884d2007-01-17 17:23:11 +11001182{
Jens Axboeff58fce2010-08-25 12:02:08 +02001183 struct io_log *iolog;
Jens Axboebb3884d2007-01-17 17:23:11 +11001184
Jens Axboeff58fce2010-08-25 12:02:08 +02001185 if (!ddir_rw(ddir))
1186 return;
1187
1188 iolog = agg_io_log[ddir];
Jens Axboe306ddc92009-05-18 13:08:12 +02001189 __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis());
Jens Axboebb3884d2007-01-17 17:23:11 +11001190}
1191
Yu-ju Hong83349192011-08-13 00:53:44 +02001192static void add_clat_percentile_sample(struct thread_stat *ts,
1193 unsigned long usec, enum fio_ddir ddir)
1194{
1195 unsigned int idx = plat_val_to_idx(usec);
1196 assert(idx < FIO_IO_U_PLAT_NR);
1197
1198 ts->io_u_plat[ddir][idx]++;
1199}
1200
Jens Axboe1e97cce2006-12-05 11:44:16 +01001201void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001202 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001203{
Jens Axboe756867b2007-03-06 15:19:24 +01001204 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001205
Jens Axboeff58fce2010-08-25 12:02:08 +02001206 if (!ddir_rw(ddir))
1207 return;
1208
Jens Axboed85f5112007-06-18 09:41:23 +02001209 add_stat_sample(&ts->clat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001210
Jens Axboe7b9f7332011-10-03 10:06:44 +02001211 if (td->clat_log)
1212 add_log_sample(td, td->clat_log, usec, ddir, bs);
Yu-ju Hong83349192011-08-13 00:53:44 +02001213
1214 if (ts->clat_percentiles)
1215 add_clat_percentile_sample(ts, usec, ddir);
Jens Axboe3c39a372006-06-06 20:56:12 +02001216}
1217
Jens Axboe1e97cce2006-12-05 11:44:16 +01001218void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
Jens Axboe306ddc92009-05-18 13:08:12 +02001219 unsigned long usec, unsigned int bs)
Jens Axboe3c39a372006-06-06 20:56:12 +02001220{
Jens Axboe756867b2007-03-06 15:19:24 +01001221 struct thread_stat *ts = &td->ts;
Jens Axboe3c39a372006-06-06 20:56:12 +02001222
Jens Axboeff58fce2010-08-25 12:02:08 +02001223 if (!ddir_rw(ddir))
1224 return;
1225
Jens Axboed85f5112007-06-18 09:41:23 +02001226 add_stat_sample(&ts->slat_stat[ddir], usec);
Jens Axboe079ad092007-02-20 13:58:20 +01001227
Jens Axboe7b9f7332011-10-03 10:06:44 +02001228 if (td->slat_log)
1229 add_log_sample(td, td->slat_log, usec, ddir, bs);
Jens Axboe3c39a372006-06-06 20:56:12 +02001230}
1231
Jens Axboe02af0982010-06-24 09:59:34 +02001232void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
1233 unsigned long usec, unsigned int bs)
1234{
1235 struct thread_stat *ts = &td->ts;
1236
Jens Axboeff58fce2010-08-25 12:02:08 +02001237 if (!ddir_rw(ddir))
1238 return;
1239
Jens Axboe02af0982010-06-24 09:59:34 +02001240 add_stat_sample(&ts->lat_stat[ddir], usec);
1241
Jens Axboe7b9f7332011-10-03 10:06:44 +02001242 if (td->lat_log)
1243 add_log_sample(td, td->lat_log, usec, ddir, bs);
Jens Axboe02af0982010-06-24 09:59:34 +02001244}
1245
Jens Axboe306ddc92009-05-18 13:08:12 +02001246void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
Jens Axboe1e97cce2006-12-05 11:44:16 +01001247 struct timeval *t)
Jens Axboe3c39a372006-06-06 20:56:12 +02001248{
Jens Axboe756867b2007-03-06 15:19:24 +01001249 struct thread_stat *ts = &td->ts;
Jens Axboeff58fce2010-08-25 12:02:08 +02001250 unsigned long spent, rate;
Jens Axboe3c39a372006-06-06 20:56:12 +02001251
Jens Axboeff58fce2010-08-25 12:02:08 +02001252 if (!ddir_rw(ddir))
1253 return;
1254
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001255 spent = mtime_since(&td->bw_sample_time, t);
Jens Axboe2dc1bbe2007-03-15 15:01:33 +01001256 if (spent < td->o.bw_avg_time)
Jens Axboe3c39a372006-06-06 20:56:12 +02001257 return;
Jens Axboe9602d8d2012-02-20 20:19:28 +01001258
1259 /*
Josh Carter5daa4eb2012-02-20 10:12:22 +01001260 * Compute both read and write rates for the interval.
1261 */
1262 for (ddir = DDIR_READ; ddir <= DDIR_WRITE; ddir++) {
1263 uint64_t delta;
Jens Axboe3c39a372006-06-06 20:56:12 +02001264
Josh Carter5daa4eb2012-02-20 10:12:22 +01001265 delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir];
1266 if (!delta)
1267 continue; /* No entries for interval */
Jens Axboe3c39a372006-06-06 20:56:12 +02001268
Josh Carter5daa4eb2012-02-20 10:12:22 +01001269 rate = delta * 1000 / spent / 1024;
1270 add_stat_sample(&ts->bw_stat[ddir], rate);
1271
1272 if (td->bw_log)
1273 add_log_sample(td, td->bw_log, rate, ddir, bs);
1274
1275 td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
1276 }
Jens Axboe3c39a372006-06-06 20:56:12 +02001277
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001278 fio_gettime(&td->bw_sample_time, NULL);
Jens Axboe3c39a372006-06-06 20:56:12 +02001279}
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001280
1281void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,
1282 struct timeval *t)
1283{
1284 struct thread_stat *ts = &td->ts;
1285 unsigned long spent, iops;
1286
1287 if (!ddir_rw(ddir))
1288 return;
1289
1290 spent = mtime_since(&td->iops_sample_time, t);
1291 if (spent < td->o.iops_avg_time)
1292 return;
1293
Jens Axboe9602d8d2012-02-20 20:19:28 +01001294 /*
1295 * Compute both read and write rates for the interval.
1296 */
1297 for (ddir = DDIR_READ; ddir <= DDIR_WRITE; ddir++) {
1298 uint64_t delta;
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001299
Jens Axboe9602d8d2012-02-20 20:19:28 +01001300 delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir];
1301 if (!delta)
1302 continue; /* No entries for interval */
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001303
Jens Axboe9602d8d2012-02-20 20:19:28 +01001304 iops = (delta * 1000) / spent;
1305 add_stat_sample(&ts->iops_stat[ddir], iops);
1306
1307 if (td->iops_log)
1308 add_log_sample(td, td->iops_log, iops, ddir, 0);
1309
Jens Axboe421f4a82012-02-28 08:20:26 +01001310 td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
Jens Axboe9602d8d2012-02-20 20:19:28 +01001311 }
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001312
1313 fio_gettime(&td->iops_sample_time, NULL);
Jens Axboec8eeb9d2011-10-05 14:02:22 +02001314}