Commit | Line | Data |
---|---|---|
3c39a379 JA |
1 | #include <stdio.h> |
2 | #include <string.h> | |
3 | #include <sys/time.h> | |
4 | #include <sys/types.h> | |
5c4e1dbc | 5 | #include <sys/stat.h> |
3c39a379 JA |
6 | #include <dirent.h> |
7 | #include <libgen.h> | |
8 | #include <math.h> | |
9 | ||
10 | #include "fio.h" | |
7c9b1bce | 11 | #include "diskutil.h" |
c7c6cb4c | 12 | #include "lib/ieee754.h" |
cc372b17 | 13 | #include "json.h" |
44404c5a | 14 | #include "lib/getrusage.h" |
f2a2ce0e | 15 | #include "idletime.h" |
0f38bbef | 16 | #include "lib/pow2.h" |
a666cab8 | 17 | #include "lib/output_buffer.h" |
3c39a379 | 18 | |
e5437a07 | 19 | struct fio_mutex *stat_mutex; |
cef9175e | 20 | |
3c39a379 JA |
21 | void update_rusage_stat(struct thread_data *td) |
22 | { | |
756867bd | 23 | struct thread_stat *ts = &td->ts; |
3c39a379 | 24 | |
44404c5a | 25 | fio_getrusage(&td->ru_end); |
c8aaba19 JA |
26 | ts->usr_time += mtime_since(&td->ru_start.ru_utime, |
27 | &td->ru_end.ru_utime); | |
28 | ts->sys_time += mtime_since(&td->ru_start.ru_stime, | |
29 | &td->ru_end.ru_stime); | |
30 | ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw | |
31 | - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw); | |
32 | ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt; | |
33 | ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt; | |
5ec10eaa | 34 | |
c8aaba19 | 35 | memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end)); |
3c39a379 JA |
36 | } |
37 | ||
83349190 YH |
38 | /* |
39 | * Given a latency, return the index of the corresponding bucket in | |
40 | * the structure tracking percentiles. | |
41 | * | |
42 | * (1) find the group (and error bits) that the value (latency) | |
43 | * belongs to by looking at its MSB. (2) find the bucket number in the | |
44 | * group by looking at the index bits. | |
45 | * | |
46 | */ | |
47 | static unsigned int plat_val_to_idx(unsigned int val) | |
48 | { | |
49 | unsigned int msb, error_bits, base, offset, idx; | |
50 | ||
51 | /* Find MSB starting from bit 0 */ | |
52 | if (val == 0) | |
53 | msb = 0; | |
54 | else | |
55 | msb = (sizeof(val)*8) - __builtin_clz(val) - 1; | |
56 | ||
716050f2 JA |
57 | /* |
58 | * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use | |
59 | * all bits of the sample as index | |
60 | */ | |
83349190 YH |
61 | if (msb <= FIO_IO_U_PLAT_BITS) |
62 | return val; | |
63 | ||
64 | /* Compute the number of error bits to discard*/ | |
65 | error_bits = msb - FIO_IO_U_PLAT_BITS; | |
66 | ||
67 | /* Compute the number of buckets before the group */ | |
68 | base = (error_bits + 1) << FIO_IO_U_PLAT_BITS; | |
69 | ||
716050f2 JA |
70 | /* |
71 | * Discard the error bits and apply the mask to find the | |
3c3ed070 | 72 | * index for the buckets in the group |
716050f2 | 73 | */ |
83349190 YH |
74 | offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits); |
75 | ||
76 | /* Make sure the index does not exceed (array size - 1) */ | |
3c3ed070 | 77 | idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1) ? |
83349190 YH |
78 | (base + offset) : (FIO_IO_U_PLAT_NR - 1); |
79 | ||
80 | return idx; | |
81 | } | |
82 | ||
83 | /* | |
84 | * Convert the given index of the bucket array to the value | |
85 | * represented by the bucket | |
86 | */ | |
87 | static unsigned int plat_idx_to_val(unsigned int idx) | |
88 | { | |
89 | unsigned int error_bits, k, base; | |
90 | ||
91 | assert(idx < FIO_IO_U_PLAT_NR); | |
92 | ||
93 | /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use | |
94 | * all bits of the sample as index */ | |
3c3ed070 | 95 | if (idx < (FIO_IO_U_PLAT_VAL << 1)) |
83349190 YH |
96 | return idx; |
97 | ||
98 | /* Find the group and compute the minimum value of that group */ | |
3c3ed070 | 99 | error_bits = (idx >> FIO_IO_U_PLAT_BITS) - 1; |
83349190 YH |
100 | base = 1 << (error_bits + FIO_IO_U_PLAT_BITS); |
101 | ||
102 | /* Find its bucket number of the group */ | |
103 | k = idx % FIO_IO_U_PLAT_VAL; | |
104 | ||
105 | /* Return the mean of the range of the bucket */ | |
106 | return base + ((k + 0.5) * (1 << error_bits)); | |
107 | } | |
108 | ||
109 | static int double_cmp(const void *a, const void *b) | |
110 | { | |
802ad4a8 JA |
111 | const fio_fp64_t fa = *(const fio_fp64_t *) a; |
112 | const fio_fp64_t fb = *(const fio_fp64_t *) b; | |
83349190 YH |
113 | int cmp = 0; |
114 | ||
802ad4a8 | 115 | if (fa.u.f > fb.u.f) |
83349190 | 116 | cmp = 1; |
802ad4a8 | 117 | else if (fa.u.f < fb.u.f) |
83349190 YH |
118 | cmp = -1; |
119 | ||
120 | return cmp; | |
121 | } | |
122 | ||
a269790c JA |
123 | unsigned int calc_clat_percentiles(unsigned int *io_u_plat, unsigned long nr, |
124 | fio_fp64_t *plist, unsigned int **output, | |
125 | unsigned int *maxv, unsigned int *minv) | |
83349190 YH |
126 | { |
127 | unsigned long sum = 0; | |
1db92cb6 JA |
128 | unsigned int len, i, j = 0; |
129 | unsigned int oval_len = 0; | |
130 | unsigned int *ovals = NULL; | |
131 | int is_last; | |
132 | ||
133 | *minv = -1U; | |
134 | *maxv = 0; | |
83349190 | 135 | |
802ad4a8 JA |
136 | len = 0; |
137 | while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0) | |
138 | len++; | |
716050f2 | 139 | |
351de8de | 140 | if (!len) |
1db92cb6 | 141 | return 0; |
351de8de | 142 | |
716050f2 | 143 | /* |
802ad4a8 JA |
144 | * Sort the percentile list. Note that it may already be sorted if |
145 | * we are using the default values, but since it's a short list this | |
146 | * isn't a worry. Also note that this does not work for NaN values. | |
716050f2 | 147 | */ |
802ad4a8 | 148 | if (len > 1) |
3c3ed070 | 149 | qsort((void *)plist, len, sizeof(plist[0]), double_cmp); |
83349190 | 150 | |
4f6f8298 JA |
151 | /* |
152 | * Calculate bucket values, note down max and min values | |
153 | */ | |
07511a63 JA |
154 | is_last = 0; |
155 | for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) { | |
83349190 | 156 | sum += io_u_plat[i]; |
802ad4a8 JA |
157 | while (sum >= (plist[j].u.f / 100.0 * nr)) { |
158 | assert(plist[j].u.f <= 100.0); | |
83349190 | 159 | |
4f6f8298 JA |
160 | if (j == oval_len) { |
161 | oval_len += 100; | |
162 | ovals = realloc(ovals, oval_len * sizeof(unsigned int)); | |
163 | } | |
164 | ||
165 | ovals[j] = plat_idx_to_val(i); | |
1db92cb6 JA |
166 | if (ovals[j] < *minv) |
167 | *minv = ovals[j]; | |
168 | if (ovals[j] > *maxv) | |
169 | *maxv = ovals[j]; | |
07511a63 JA |
170 | |
171 | is_last = (j == len - 1); | |
172 | if (is_last) | |
173 | break; | |
174 | ||
4f6f8298 JA |
175 | j++; |
176 | } | |
177 | } | |
83349190 | 178 | |
1db92cb6 JA |
179 | *output = ovals; |
180 | return len; | |
181 | } | |
182 | ||
183 | /* | |
184 | * Find and display the p-th percentile of clat | |
185 | */ | |
186 | static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr, | |
a666cab8 JA |
187 | fio_fp64_t *plist, unsigned int precision, |
188 | struct buf_output *out) | |
1db92cb6 JA |
189 | { |
190 | unsigned int len, j = 0, minv, maxv; | |
191 | unsigned int *ovals; | |
eef02441 JA |
192 | int is_last, per_line, scale_down; |
193 | char fmt[32]; | |
1db92cb6 JA |
194 | |
195 | len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv); | |
196 | if (!len) | |
197 | goto out; | |
198 | ||
4f6f8298 JA |
199 | /* |
200 | * We default to usecs, but if the value range is such that we | |
201 | * should scale down to msecs, do that. | |
202 | */ | |
203 | if (minv > 2000 && maxv > 99999) { | |
204 | scale_down = 1; | |
a666cab8 | 205 | log_buf(out, " clat percentiles (msec):\n |"); |
4f6f8298 JA |
206 | } else { |
207 | scale_down = 0; | |
a666cab8 | 208 | log_buf(out, " clat percentiles (usec):\n |"); |
4f6f8298 | 209 | } |
83349190 | 210 | |
3dc1e5b2 | 211 | snprintf(fmt, sizeof(fmt), "%%1.%uf", precision); |
eef02441 | 212 | per_line = (80 - 7) / (precision + 14); |
619adf9c | 213 | |
4f6f8298 | 214 | for (j = 0; j < len; j++) { |
619adf9c | 215 | char fbuf[16], *ptr = fbuf; |
81ab0b3a | 216 | |
4f6f8298 | 217 | /* for formatting */ |
eef02441 | 218 | if (j != 0 && (j % per_line) == 0) |
a666cab8 | 219 | log_buf(out, " |"); |
83349190 | 220 | |
4f6f8298 JA |
221 | /* end of the list */ |
222 | is_last = (j == len - 1); | |
83349190 | 223 | |
4f6f8298 | 224 | if (plist[j].u.f < 10.0) |
619adf9c JA |
225 | ptr += sprintf(fbuf, " "); |
226 | ||
eef02441 | 227 | snprintf(ptr, sizeof(fbuf), fmt, plist[j].u.f); |
4f6f8298 JA |
228 | |
229 | if (scale_down) | |
230 | ovals[j] = (ovals[j] + 999) / 1000; | |
231 | ||
a666cab8 | 232 | log_buf(out, " %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ','); |
4f6f8298 JA |
233 | |
234 | if (is_last) | |
235 | break; | |
236 | ||
eef02441 | 237 | if ((j % per_line) == per_line - 1) /* for formatting */ |
a666cab8 | 238 | log_buf(out, "\n"); |
83349190 | 239 | } |
4f6f8298 | 240 | |
1db92cb6 | 241 | out: |
4f6f8298 JA |
242 | if (ovals) |
243 | free(ovals); | |
83349190 YH |
244 | } |
245 | ||
b29ad562 JA |
246 | int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max, |
247 | double *mean, double *dev) | |
3c39a379 | 248 | { |
ee0ccb79 | 249 | double n = (double) is->samples; |
3c39a379 | 250 | |
ee0ccb79 | 251 | if (n == 0) |
3c39a379 JA |
252 | return 0; |
253 | ||
254 | *min = is->min_val; | |
255 | *max = is->max_val; | |
802ad4a8 | 256 | *mean = is->mean.u.f; |
e6d276f2 | 257 | |
68704084 | 258 | if (n > 1.0) |
802ad4a8 | 259 | *dev = sqrt(is->S.u.f / (n - 1.0)); |
ef9c5c40 | 260 | else |
4b43f54e | 261 | *dev = 0; |
ef9c5c40 | 262 | |
3c39a379 JA |
263 | return 1; |
264 | } | |
265 | ||
a666cab8 | 266 | void show_group_stats(struct group_run_stats *rs, struct buf_output *out) |
3c39a379 | 267 | { |
dbe1125e | 268 | char *p1, *p2, *p3, *p4; |
42da5c8b | 269 | const char *str[] = { " READ", " WRITE" , " TRIM"}; |
dbe1125e JA |
270 | int i; |
271 | ||
a666cab8 | 272 | log_buf(out, "\nRun status group %d (all jobs):\n", rs->groupid); |
3c39a379 | 273 | |
6eaf09d6 | 274 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
90fef2d1 JA |
275 | const int i2p = is_power_of_2(rs->kb_base); |
276 | ||
dbe1125e JA |
277 | if (!rs->max_run[i]) |
278 | continue; | |
279 | ||
73798eb2 | 280 | p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p, 8); |
ad705bcb SN |
281 | p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p, rs->unit_base); |
282 | p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p, rs->unit_base); | |
283 | p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p, rs->unit_base); | |
dbe1125e | 284 | |
a666cab8 | 285 | log_buf(out, "%s: io=%s, aggrb=%s/s, minb=%s/s, maxb=%s/s," |
771e58be | 286 | " mint=%llumsec, maxt=%llumsec\n", |
42da5c8b | 287 | rs->unified_rw_rep ? " MIXED" : str[i], |
4e0a8fa2 JA |
288 | p1, p2, p3, p4, |
289 | (unsigned long long) rs->min_run[i], | |
290 | (unsigned long long) rs->max_run[i]); | |
dbe1125e JA |
291 | |
292 | free(p1); | |
293 | free(p2); | |
294 | free(p3); | |
295 | free(p4); | |
296 | } | |
3c39a379 JA |
297 | } |
298 | ||
2e33101f | 299 | void stat_calc_dist(unsigned int *map, unsigned long total, double *io_u_dist) |
2270890c JA |
300 | { |
301 | int i; | |
302 | ||
303 | /* | |
304 | * Do depth distribution calculations | |
305 | */ | |
306 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { | |
838bc709 JA |
307 | if (total) { |
308 | io_u_dist[i] = (double) map[i] / (double) total; | |
309 | io_u_dist[i] *= 100.0; | |
310 | if (io_u_dist[i] < 0.1 && map[i]) | |
311 | io_u_dist[i] = 0.1; | |
312 | } else | |
313 | io_u_dist[i] = 0.0; | |
2270890c JA |
314 | } |
315 | } | |
316 | ||
04a0feae JA |
317 | static void stat_calc_lat(struct thread_stat *ts, double *dst, |
318 | unsigned int *src, int nr) | |
2270890c | 319 | { |
d79db122 | 320 | unsigned long total = ddir_rw_sum(ts->total_io_u); |
2270890c JA |
321 | int i; |
322 | ||
323 | /* | |
324 | * Do latency distribution calculations | |
325 | */ | |
04a0feae | 326 | for (i = 0; i < nr; i++) { |
838bc709 JA |
327 | if (total) { |
328 | dst[i] = (double) src[i] / (double) total; | |
329 | dst[i] *= 100.0; | |
330 | if (dst[i] < 0.01 && src[i]) | |
331 | dst[i] = 0.01; | |
332 | } else | |
333 | dst[i] = 0.0; | |
2270890c JA |
334 | } |
335 | } | |
336 | ||
e5bd1347 | 337 | void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat) |
04a0feae JA |
338 | { |
339 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR); | |
340 | } | |
341 | ||
e5bd1347 | 342 | void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat) |
04a0feae JA |
343 | { |
344 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR); | |
345 | } | |
346 | ||
b29ad562 | 347 | static void display_lat(const char *name, unsigned long min, unsigned long max, |
a666cab8 | 348 | double mean, double dev, struct buf_output *out) |
ea2accc5 | 349 | { |
b29ad562 JA |
350 | const char *base = "(usec)"; |
351 | char *minp, *maxp; | |
ea2accc5 | 352 | |
b29ad562 JA |
353 | if (!usec_to_msec(&min, &max, &mean, &dev)) |
354 | base = "(msec)"; | |
355 | ||
22f80458 JA |
356 | minp = num2str(min, 6, 1, 0, 0); |
357 | maxp = num2str(max, 6, 1, 0, 0); | |
b29ad562 | 358 | |
a666cab8 | 359 | log_buf(out, " %s %s: min=%s, max=%s, avg=%5.02f," |
b29ad562 JA |
360 | " stdev=%5.02f\n", name, base, minp, maxp, mean, dev); |
361 | ||
362 | free(minp); | |
363 | free(maxp); | |
ea2accc5 JA |
364 | } |
365 | ||
756867bd | 366 | static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, |
a666cab8 | 367 | int ddir, struct buf_output *out) |
3c39a379 | 368 | { |
42da5c8b | 369 | const char *str[] = { "read ", "write", "trim" }; |
8879fd15 | 370 | unsigned long min, max, runt; |
b3605062 | 371 | unsigned long long bw, iops; |
3c39a379 | 372 | double mean, dev; |
b3605062 | 373 | char *io_p, *bw_p, *iops_p; |
90fef2d1 | 374 | int i2p; |
3c39a379 | 375 | |
ff58fced JA |
376 | assert(ddir_rw(ddir)); |
377 | ||
756867bd | 378 | if (!ts->runtime[ddir]) |
3c39a379 JA |
379 | return; |
380 | ||
90fef2d1 | 381 | i2p = is_power_of_2(rs->kb_base); |
8879fd15 JA |
382 | runt = ts->runtime[ddir]; |
383 | ||
384 | bw = (1000 * ts->io_bytes[ddir]) / runt; | |
73798eb2 | 385 | io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p, 8); |
ad705bcb | 386 | bw_p = num2str(bw, 6, 1, i2p, ts->unit_base); |
8879fd15 | 387 | |
0aacc50c | 388 | iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt; |
73798eb2 | 389 | iops_p = num2str(iops, 6, 1, 0, 0); |
dbe1125e | 390 | |
a666cab8 | 391 | log_buf(out, " %s: io=%s, bw=%s/s, iops=%s, runt=%6llumsec\n", |
42da5c8b | 392 | rs->unified_rw_rep ? "mixed" : str[ddir], |
4e0a8fa2 JA |
393 | io_p, bw_p, iops_p, |
394 | (unsigned long long) ts->runtime[ddir]); | |
dbe1125e JA |
395 | |
396 | free(io_p); | |
397 | free(bw_p); | |
b3605062 | 398 | free(iops_p); |
3c39a379 | 399 | |
b29ad562 | 400 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
a666cab8 | 401 | display_lat("slat", min, max, mean, dev, out); |
b29ad562 | 402 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) |
a666cab8 | 403 | display_lat("clat", min, max, mean, dev, out); |
b29ad562 | 404 | if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) |
a666cab8 | 405 | display_lat(" lat", min, max, mean, dev, out); |
02af0988 | 406 | |
83349190 YH |
407 | if (ts->clat_percentiles) { |
408 | show_clat_percentiles(ts->io_u_plat[ddir], | |
409 | ts->clat_stat[ddir].samples, | |
435d195a | 410 | ts->percentile_list, |
a666cab8 | 411 | ts->percentile_precision, out); |
83349190 | 412 | } |
079ad09b | 413 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
142c7f2d | 414 | double p_of_agg = 100.0, fkb_base = (double)rs->kb_base; |
d686990a SN |
415 | const char *bw_str = (rs->unit_base == 1 ? "Kbit" : "KB"); |
416 | ||
417 | if (rs->unit_base == 1) { | |
418 | min *= 8.0; | |
419 | max *= 8.0; | |
420 | mean *= 8.0; | |
421 | dev *= 8.0; | |
422 | } | |
3c39a379 | 423 | |
2f2c6924 | 424 | if (rs->agg[ddir]) { |
19d3e967 JA |
425 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; |
426 | if (p_of_agg > 100.0) | |
427 | p_of_agg = 100.0; | |
428 | } | |
b7017e32 | 429 | |
142c7f2d SN |
430 | if (mean > fkb_base * fkb_base) { |
431 | min /= fkb_base; | |
432 | max /= fkb_base; | |
433 | mean /= fkb_base; | |
434 | dev /= fkb_base; | |
d686990a | 435 | bw_str = (rs->unit_base == 1 ? "Mbit" : "MB"); |
b7017e32 JA |
436 | } |
437 | ||
a666cab8 | 438 | log_buf(out, " bw (%-4s/s): min=%5lu, max=%5lu, per=%3.2f%%," |
b7017e32 JA |
439 | " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max, |
440 | p_of_agg, mean, dev); | |
3c39a379 JA |
441 | } |
442 | } | |
443 | ||
7e1773ba | 444 | static int show_lat(double *io_u_lat, int nr, const char **ranges, |
a666cab8 | 445 | const char *msg, struct buf_output *out) |
04a0feae | 446 | { |
7e1773ba | 447 | int new_line = 1, i, line = 0, shown = 0; |
04a0feae JA |
448 | |
449 | for (i = 0; i < nr; i++) { | |
450 | if (io_u_lat[i] <= 0.0) | |
451 | continue; | |
7e1773ba | 452 | shown = 1; |
04a0feae | 453 | if (new_line) { |
4539ed73 | 454 | if (line) |
a666cab8 JA |
455 | log_buf(out, "\n"); |
456 | log_buf(out, " lat (%s) : ", msg); | |
04a0feae JA |
457 | new_line = 0; |
458 | line = 0; | |
459 | } | |
460 | if (line) | |
a666cab8 JA |
461 | log_buf(out, ", "); |
462 | log_buf(out, "%s%3.2f%%", ranges[i], io_u_lat[i]); | |
04a0feae JA |
463 | line++; |
464 | if (line == 5) | |
465 | new_line = 1; | |
466 | } | |
7e1773ba JA |
467 | |
468 | if (shown) | |
a666cab8 | 469 | log_buf(out, "\n"); |
7e1773ba JA |
470 | |
471 | return shown; | |
04a0feae JA |
472 | } |
473 | ||
a666cab8 | 474 | static void show_lat_u(double *io_u_lat_u, struct buf_output *out) |
04a0feae JA |
475 | { |
476 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", | |
477 | "250=", "500=", "750=", "1000=", }; | |
478 | ||
a666cab8 | 479 | show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec", out); |
04a0feae JA |
480 | } |
481 | ||
a666cab8 | 482 | static void show_lat_m(double *io_u_lat_m, struct buf_output *out) |
04a0feae JA |
483 | { |
484 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", | |
485 | "250=", "500=", "750=", "1000=", "2000=", | |
486 | ">=2000=", }; | |
487 | ||
a666cab8 | 488 | show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec", out); |
04a0feae JA |
489 | } |
490 | ||
a666cab8 | 491 | static void show_latencies(struct thread_stat *ts, struct buf_output *out) |
04a0feae | 492 | { |
c551f65a JA |
493 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
494 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
495 | ||
5a18988e JA |
496 | stat_calc_lat_u(ts, io_u_lat_u); |
497 | stat_calc_lat_m(ts, io_u_lat_m); | |
498 | ||
a666cab8 JA |
499 | show_lat_u(io_u_lat_u, out); |
500 | show_lat_m(io_u_lat_m, out); | |
04a0feae JA |
501 | } |
502 | ||
66347cfa DE |
503 | static int block_state_category(int block_state) |
504 | { | |
505 | switch (block_state) { | |
506 | case BLOCK_STATE_UNINIT: | |
507 | return 0; | |
508 | case BLOCK_STATE_TRIMMED: | |
509 | case BLOCK_STATE_WRITTEN: | |
510 | return 1; | |
511 | case BLOCK_STATE_WRITE_FAILURE: | |
512 | case BLOCK_STATE_TRIM_FAILURE: | |
513 | return 2; | |
514 | default: | |
081c2dc3 | 515 | /* Silence compile warning on some BSDs and have a return */ |
66347cfa | 516 | assert(0); |
07ff5841 | 517 | return -1; |
66347cfa DE |
518 | } |
519 | } | |
520 | ||
521 | static int compare_block_infos(const void *bs1, const void *bs2) | |
522 | { | |
523 | uint32_t block1 = *(uint32_t *)bs1; | |
524 | uint32_t block2 = *(uint32_t *)bs2; | |
525 | int state1 = BLOCK_INFO_STATE(block1); | |
526 | int state2 = BLOCK_INFO_STATE(block2); | |
527 | int bscat1 = block_state_category(state1); | |
528 | int bscat2 = block_state_category(state2); | |
529 | int cycles1 = BLOCK_INFO_TRIMS(block1); | |
530 | int cycles2 = BLOCK_INFO_TRIMS(block2); | |
531 | ||
532 | if (bscat1 < bscat2) | |
533 | return -1; | |
534 | if (bscat1 > bscat2) | |
535 | return 1; | |
536 | ||
537 | if (cycles1 < cycles2) | |
538 | return -1; | |
539 | if (cycles1 > cycles2) | |
540 | return 1; | |
541 | ||
542 | if (state1 < state2) | |
543 | return -1; | |
544 | if (state1 > state2) | |
545 | return 1; | |
546 | ||
547 | assert(block1 == block2); | |
548 | return 0; | |
549 | } | |
550 | ||
551 | static int calc_block_percentiles(int nr_block_infos, uint32_t *block_infos, | |
552 | fio_fp64_t *plist, unsigned int **percentiles, | |
553 | unsigned int *types) | |
554 | { | |
555 | int len = 0; | |
556 | int i, nr_uninit; | |
557 | ||
558 | qsort(block_infos, nr_block_infos, sizeof(uint32_t), compare_block_infos); | |
559 | ||
560 | while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0) | |
561 | len++; | |
562 | ||
563 | if (!len) | |
564 | return 0; | |
565 | ||
566 | /* | |
567 | * Sort the percentile list. Note that it may already be sorted if | |
568 | * we are using the default values, but since it's a short list this | |
569 | * isn't a worry. Also note that this does not work for NaN values. | |
570 | */ | |
571 | if (len > 1) | |
572 | qsort((void *)plist, len, sizeof(plist[0]), double_cmp); | |
573 | ||
574 | nr_uninit = 0; | |
575 | /* Start only after the uninit entries end */ | |
576 | for (nr_uninit = 0; | |
577 | nr_uninit < nr_block_infos | |
578 | && BLOCK_INFO_STATE(block_infos[nr_uninit]) == BLOCK_STATE_UNINIT; | |
579 | nr_uninit ++) | |
580 | ; | |
581 | ||
582 | if (nr_uninit == nr_block_infos) | |
583 | return 0; | |
584 | ||
585 | *percentiles = calloc(len, sizeof(**percentiles)); | |
586 | ||
587 | for (i = 0; i < len; i++) { | |
588 | int idx = (plist[i].u.f * (nr_block_infos - nr_uninit) / 100) | |
589 | + nr_uninit; | |
590 | (*percentiles)[i] = BLOCK_INFO_TRIMS(block_infos[idx]); | |
591 | } | |
592 | ||
593 | memset(types, 0, sizeof(*types) * BLOCK_STATE_COUNT); | |
594 | for (i = 0; i < nr_block_infos; i++) | |
595 | types[BLOCK_INFO_STATE(block_infos[i])]++; | |
596 | ||
597 | return len; | |
598 | } | |
599 | ||
600 | static const char *block_state_names[] = { | |
601 | [BLOCK_STATE_UNINIT] = "unwritten", | |
602 | [BLOCK_STATE_TRIMMED] = "trimmed", | |
603 | [BLOCK_STATE_WRITTEN] = "written", | |
604 | [BLOCK_STATE_TRIM_FAILURE] = "trim failure", | |
605 | [BLOCK_STATE_WRITE_FAILURE] = "write failure", | |
606 | }; | |
607 | ||
608 | static void show_block_infos(int nr_block_infos, uint32_t *block_infos, | |
a666cab8 | 609 | fio_fp64_t *plist, struct buf_output *out) |
66347cfa DE |
610 | { |
611 | int len, pos, i; | |
612 | unsigned int *percentiles = NULL; | |
613 | unsigned int block_state_counts[BLOCK_STATE_COUNT]; | |
614 | ||
615 | len = calc_block_percentiles(nr_block_infos, block_infos, plist, | |
616 | &percentiles, block_state_counts); | |
617 | ||
a666cab8 | 618 | log_buf(out, " block lifetime percentiles :\n |"); |
66347cfa DE |
619 | pos = 0; |
620 | for (i = 0; i < len; i++) { | |
621 | uint32_t block_info = percentiles[i]; | |
622 | #define LINE_LENGTH 75 | |
623 | char str[LINE_LENGTH]; | |
624 | int strln = snprintf(str, LINE_LENGTH, " %3.2fth=%u%c", | |
625 | plist[i].u.f, block_info, | |
626 | i == len - 1 ? '\n' : ','); | |
627 | assert(strln < LINE_LENGTH); | |
628 | if (pos + strln > LINE_LENGTH) { | |
629 | pos = 0; | |
a666cab8 | 630 | log_buf(out, "\n |"); |
66347cfa | 631 | } |
a666cab8 | 632 | log_buf(out, "%s", str); |
66347cfa DE |
633 | pos += strln; |
634 | #undef LINE_LENGTH | |
635 | } | |
636 | if (percentiles) | |
637 | free(percentiles); | |
638 | ||
a666cab8 | 639 | log_buf(out, " states :"); |
66347cfa | 640 | for (i = 0; i < BLOCK_STATE_COUNT; i++) |
a666cab8 | 641 | log_buf(out, " %s=%u%c", |
66347cfa DE |
642 | block_state_names[i], block_state_counts[i], |
643 | i == BLOCK_STATE_COUNT - 1 ? '\n' : ','); | |
644 | } | |
645 | ||
10aa136b | 646 | static void show_thread_status_normal(struct thread_stat *ts, |
a666cab8 JA |
647 | struct group_run_stats *rs, |
648 | struct buf_output *out) | |
3c39a379 JA |
649 | { |
650 | double usr_cpu, sys_cpu; | |
69008999 | 651 | unsigned long runtime; |
71619dc2 | 652 | double io_u_dist[FIO_IO_U_MAP_NR]; |
57a64324 | 653 | time_t time_p; |
35326842 | 654 | char time_buf[32]; |
3c39a379 | 655 | |
9966af7b | 656 | if (!ddir_rw_sum(ts->io_bytes) && !ddir_rw_sum(ts->total_io_u)) |
3c39a379 JA |
657 | return; |
658 | ||
57a64324 | 659 | time(&time_p); |
45054cbe | 660 | os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf)); |
57a64324 | 661 | |
5ec10eaa | 662 | if (!ts->error) { |
a666cab8 | 663 | log_buf(out, "%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s", |
5ec10eaa | 664 | ts->name, ts->groupid, ts->members, |
57a64324 | 665 | ts->error, (int) ts->pid, time_buf); |
5ec10eaa | 666 | } else { |
a666cab8 | 667 | log_buf(out, "%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s", |
5ec10eaa | 668 | ts->name, ts->groupid, ts->members, |
57a64324 JA |
669 | ts->error, ts->verror, (int) ts->pid, |
670 | time_buf); | |
5ec10eaa | 671 | } |
3c39a379 | 672 | |
259e47de | 673 | if (strlen(ts->description)) |
a666cab8 | 674 | log_buf(out, " Description : [%s]\n", ts->description); |
7bdce1bd | 675 | |
756867bd | 676 | if (ts->io_bytes[DDIR_READ]) |
a666cab8 | 677 | show_ddir_status(rs, ts, DDIR_READ, out); |
756867bd | 678 | if (ts->io_bytes[DDIR_WRITE]) |
a666cab8 | 679 | show_ddir_status(rs, ts, DDIR_WRITE, out); |
6eaf09d6 | 680 | if (ts->io_bytes[DDIR_TRIM]) |
a666cab8 | 681 | show_ddir_status(rs, ts, DDIR_TRIM, out); |
3c39a379 | 682 | |
a666cab8 | 683 | show_latencies(ts, out); |
7e1773ba | 684 | |
756867bd | 685 | runtime = ts->total_run_time; |
69008999 | 686 | if (runtime) { |
1e97cce9 | 687 | double runt = (double) runtime; |
3c39a379 | 688 | |
756867bd JA |
689 | usr_cpu = (double) ts->usr_time * 100 / runt; |
690 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
3c39a379 JA |
691 | } else { |
692 | usr_cpu = 0; | |
693 | sys_cpu = 0; | |
694 | } | |
695 | ||
a666cab8 | 696 | log_buf(out, " cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%llu," |
4e0a8fa2 JA |
697 | " majf=%llu, minf=%llu\n", usr_cpu, sys_cpu, |
698 | (unsigned long long) ts->ctx, | |
699 | (unsigned long long) ts->majf, | |
700 | (unsigned long long) ts->minf); | |
71619dc2 | 701 | |
d79db122 | 702 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); |
a666cab8 | 703 | log_buf(out, " IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%," |
5ec10eaa JA |
704 | " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], |
705 | io_u_dist[1], io_u_dist[2], | |
706 | io_u_dist[3], io_u_dist[4], | |
707 | io_u_dist[5], io_u_dist[6]); | |
838bc709 JA |
708 | |
709 | stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist); | |
a666cab8 | 710 | log_buf(out, " submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," |
838bc709 JA |
711 | " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], |
712 | io_u_dist[1], io_u_dist[2], | |
713 | io_u_dist[3], io_u_dist[4], | |
714 | io_u_dist[5], io_u_dist[6]); | |
715 | stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist); | |
a666cab8 | 716 | log_buf(out, " complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," |
838bc709 JA |
717 | " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], |
718 | io_u_dist[1], io_u_dist[2], | |
719 | io_u_dist[3], io_u_dist[4], | |
720 | io_u_dist[5], io_u_dist[6]); | |
a666cab8 | 721 | log_buf(out, " issued : total=r=%llu/w=%llu/d=%llu," |
3bcb9d94 JA |
722 | " short=r=%llu/w=%llu/d=%llu," |
723 | " drop=r=%llu/w=%llu/d=%llu\n", | |
4e0a8fa2 JA |
724 | (unsigned long long) ts->total_io_u[0], |
725 | (unsigned long long) ts->total_io_u[1], | |
726 | (unsigned long long) ts->total_io_u[2], | |
727 | (unsigned long long) ts->short_io_u[0], | |
728 | (unsigned long long) ts->short_io_u[1], | |
3bcb9d94 JA |
729 | (unsigned long long) ts->short_io_u[2], |
730 | (unsigned long long) ts->drop_io_u[0], | |
731 | (unsigned long long) ts->drop_io_u[1], | |
732 | (unsigned long long) ts->drop_io_u[2]); | |
f2bba182 | 733 | if (ts->continue_on_error) { |
a666cab8 | 734 | log_buf(out, " errors : total=%llu, first_error=%d/<%s>\n", |
4e0a8fa2 | 735 | (unsigned long long)ts->total_err_count, |
1ec99eea JA |
736 | ts->first_error, |
737 | strerror(ts->first_error)); | |
f2bba182 | 738 | } |
3e260a46 | 739 | if (ts->latency_depth) { |
a666cab8 | 740 | log_buf(out, " latency : target=%llu, window=%llu, percentile=%.2f%%, depth=%u\n", |
3e260a46 JA |
741 | (unsigned long long)ts->latency_target, |
742 | (unsigned long long)ts->latency_window, | |
743 | ts->latency_percentile.u.f, | |
744 | ts->latency_depth); | |
745 | } | |
66347cfa DE |
746 | |
747 | if (ts->nr_block_infos) | |
748 | show_block_infos(ts->nr_block_infos, ts->block_infos, | |
a666cab8 | 749 | ts->percentile_list, out); |
3c39a379 JA |
750 | } |
751 | ||
756867bd | 752 | static void show_ddir_status_terse(struct thread_stat *ts, |
a666cab8 JA |
753 | struct group_run_stats *rs, int ddir, |
754 | struct buf_output *out) | |
c6ae0a5b JA |
755 | { |
756 | unsigned long min, max; | |
312b4af2 | 757 | unsigned long long bw, iops; |
1db92cb6 | 758 | unsigned int *ovals = NULL; |
c6ae0a5b | 759 | double mean, dev; |
1db92cb6 JA |
760 | unsigned int len, minv, maxv; |
761 | int i; | |
c6ae0a5b | 762 | |
ff58fced JA |
763 | assert(ddir_rw(ddir)); |
764 | ||
312b4af2 JA |
765 | iops = bw = 0; |
766 | if (ts->runtime[ddir]) { | |
767 | uint64_t runt = ts->runtime[ddir]; | |
768 | ||
033bbb51 | 769 | bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024; |
312b4af2 JA |
770 | iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt; |
771 | } | |
c6ae0a5b | 772 | |
a666cab8 | 773 | log_buf(out, ";%llu;%llu;%llu;%llu", |
4e0a8fa2 JA |
774 | (unsigned long long) ts->io_bytes[ddir] >> 10, bw, iops, |
775 | (unsigned long long) ts->runtime[ddir]); | |
c6ae0a5b | 776 | |
079ad09b | 777 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
a666cab8 | 778 | log_buf(out, ";%lu;%lu;%f;%f", min, max, mean, dev); |
c6ae0a5b | 779 | else |
a666cab8 | 780 | log_buf(out, ";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
c6ae0a5b | 781 | |
079ad09b | 782 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) |
a666cab8 | 783 | log_buf(out, ";%lu;%lu;%f;%f", min, max, mean, dev); |
c6ae0a5b | 784 | else |
a666cab8 | 785 | log_buf(out, ";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
c6ae0a5b | 786 | |
1db92cb6 JA |
787 | if (ts->clat_percentiles) { |
788 | len = calc_clat_percentiles(ts->io_u_plat[ddir], | |
789 | ts->clat_stat[ddir].samples, | |
790 | ts->percentile_list, &ovals, &maxv, | |
791 | &minv); | |
792 | } else | |
793 | len = 0; | |
794 | ||
795 | for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { | |
796 | if (i >= len) { | |
a666cab8 | 797 | log_buf(out, ";0%%=0"); |
1db92cb6 JA |
798 | continue; |
799 | } | |
a666cab8 | 800 | log_buf(out, ";%f%%=%u", ts->percentile_list[i].u.f, ovals[i]); |
1db92cb6 | 801 | } |
2341a37a K |
802 | |
803 | if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) | |
a666cab8 | 804 | log_buf(out, ";%lu;%lu;%f;%f", min, max, mean, dev); |
2341a37a | 805 | else |
a666cab8 | 806 | log_buf(out, ";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
2341a37a | 807 | |
1db92cb6 JA |
808 | if (ovals) |
809 | free(ovals); | |
810 | ||
079ad09b | 811 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
19d3e967 JA |
812 | double p_of_agg = 100.0; |
813 | ||
814 | if (rs->agg[ddir]) { | |
815 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; | |
816 | if (p_of_agg > 100.0) | |
817 | p_of_agg = 100.0; | |
818 | } | |
c6ae0a5b | 819 | |
a666cab8 | 820 | log_buf(out, ";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev); |
c6ae0a5b | 821 | } else |
a666cab8 | 822 | log_buf(out, ";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0); |
c6ae0a5b JA |
823 | } |
824 | ||
cc372b17 SL |
825 | static void add_ddir_status_json(struct thread_stat *ts, |
826 | struct group_run_stats *rs, int ddir, struct json_object *parent) | |
827 | { | |
828 | unsigned long min, max; | |
9f68fe3a | 829 | unsigned long long bw; |
cc372b17 | 830 | unsigned int *ovals = NULL; |
9f68fe3a | 831 | double mean, dev, iops; |
cc372b17 SL |
832 | unsigned int len, minv, maxv; |
833 | int i; | |
834 | const char *ddirname[] = {"read", "write", "trim"}; | |
513e37ee | 835 | struct json_object *dir_object, *tmp_object, *percentile_object, *clat_bins_object; |
cc372b17 SL |
836 | char buf[120]; |
837 | double p_of_agg = 100.0; | |
838 | ||
839 | assert(ddir_rw(ddir)); | |
840 | ||
771e58be JA |
841 | if (ts->unified_rw_rep && ddir != DDIR_READ) |
842 | return; | |
843 | ||
cc372b17 | 844 | dir_object = json_create_object(); |
771e58be JA |
845 | json_object_add_value_object(parent, |
846 | ts->unified_rw_rep ? "mixed" : ddirname[ddir], dir_object); | |
cc372b17 | 847 | |
9f68fe3a BE |
848 | bw = 0; |
849 | iops = 0.0; | |
cc372b17 SL |
850 | if (ts->runtime[ddir]) { |
851 | uint64_t runt = ts->runtime[ddir]; | |
852 | ||
853 | bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024; | |
9f68fe3a | 854 | iops = (1000.0 * (uint64_t) ts->total_io_u[ddir]) / runt; |
cc372b17 SL |
855 | } |
856 | ||
857 | json_object_add_value_int(dir_object, "io_bytes", ts->io_bytes[ddir] >> 10); | |
858 | json_object_add_value_int(dir_object, "bw", bw); | |
9f68fe3a | 859 | json_object_add_value_float(dir_object, "iops", iops); |
cc372b17 | 860 | json_object_add_value_int(dir_object, "runtime", ts->runtime[ddir]); |
9966af7b JA |
861 | json_object_add_value_int(dir_object, "total_ios", ts->total_io_u[ddir]); |
862 | json_object_add_value_int(dir_object, "short_ios", ts->short_io_u[ddir]); | |
863 | json_object_add_value_int(dir_object, "drop_ios", ts->drop_io_u[ddir]); | |
cc372b17 SL |
864 | |
865 | if (!calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) { | |
866 | min = max = 0; | |
867 | mean = dev = 0.0; | |
868 | } | |
869 | tmp_object = json_create_object(); | |
870 | json_object_add_value_object(dir_object, "slat", tmp_object); | |
871 | json_object_add_value_int(tmp_object, "min", min); | |
872 | json_object_add_value_int(tmp_object, "max", max); | |
873 | json_object_add_value_float(tmp_object, "mean", mean); | |
874 | json_object_add_value_float(tmp_object, "stddev", dev); | |
875 | ||
876 | if (!calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) { | |
877 | min = max = 0; | |
878 | mean = dev = 0.0; | |
879 | } | |
880 | tmp_object = json_create_object(); | |
881 | json_object_add_value_object(dir_object, "clat", tmp_object); | |
882 | json_object_add_value_int(tmp_object, "min", min); | |
883 | json_object_add_value_int(tmp_object, "max", max); | |
884 | json_object_add_value_float(tmp_object, "mean", mean); | |
885 | json_object_add_value_float(tmp_object, "stddev", dev); | |
886 | ||
887 | if (ts->clat_percentiles) { | |
888 | len = calc_clat_percentiles(ts->io_u_plat[ddir], | |
889 | ts->clat_stat[ddir].samples, | |
890 | ts->percentile_list, &ovals, &maxv, | |
891 | &minv); | |
892 | } else | |
893 | len = 0; | |
894 | ||
895 | percentile_object = json_create_object(); | |
896 | json_object_add_value_object(tmp_object, "percentile", percentile_object); | |
897 | for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { | |
898 | if (i >= len) { | |
899 | json_object_add_value_int(percentile_object, "0.00", 0); | |
900 | continue; | |
901 | } | |
435d195a | 902 | snprintf(buf, sizeof(buf), "%f", ts->percentile_list[i].u.f); |
cc372b17 SL |
903 | json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]); |
904 | } | |
905 | ||
513e37ee VF |
906 | if (output_format & FIO_OUTPUT_JSON_PLUS) { |
907 | clat_bins_object = json_create_object(); | |
908 | json_object_add_value_object(tmp_object, "bins", clat_bins_object); | |
909 | for(i = 0; i < FIO_IO_U_PLAT_NR; i++) { | |
910 | snprintf(buf, sizeof(buf), "%d", i); | |
911 | json_object_add_value_int(clat_bins_object, (const char *)buf, ts->io_u_plat[ddir][i]); | |
912 | } | |
913 | json_object_add_value_int(clat_bins_object, "FIO_IO_U_PLAT_BITS", FIO_IO_U_PLAT_BITS); | |
914 | json_object_add_value_int(clat_bins_object, "FIO_IO_U_PLAT_VAL", FIO_IO_U_PLAT_VAL); | |
915 | json_object_add_value_int(clat_bins_object, "FIO_IO_U_PLAT_NR", FIO_IO_U_PLAT_NR); | |
916 | } | |
917 | ||
cc372b17 SL |
918 | if (!calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) { |
919 | min = max = 0; | |
920 | mean = dev = 0.0; | |
921 | } | |
922 | tmp_object = json_create_object(); | |
923 | json_object_add_value_object(dir_object, "lat", tmp_object); | |
924 | json_object_add_value_int(tmp_object, "min", min); | |
925 | json_object_add_value_int(tmp_object, "max", max); | |
926 | json_object_add_value_float(tmp_object, "mean", mean); | |
927 | json_object_add_value_float(tmp_object, "stddev", dev); | |
928 | if (ovals) | |
929 | free(ovals); | |
930 | ||
b9e1b491 | 931 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
cc372b17 SL |
932 | if (rs->agg[ddir]) { |
933 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; | |
934 | if (p_of_agg > 100.0) | |
935 | p_of_agg = 100.0; | |
936 | } | |
937 | } else { | |
938 | min = max = 0; | |
939 | p_of_agg = mean = dev = 0.0; | |
940 | } | |
941 | json_object_add_value_int(dir_object, "bw_min", min); | |
942 | json_object_add_value_int(dir_object, "bw_max", max); | |
a806bf2e | 943 | json_object_add_value_float(dir_object, "bw_agg", p_of_agg); |
cc372b17 SL |
944 | json_object_add_value_float(dir_object, "bw_mean", mean); |
945 | json_object_add_value_float(dir_object, "bw_dev", dev); | |
946 | } | |
947 | ||
4d658652 | 948 | static void show_thread_status_terse_v2(struct thread_stat *ts, |
a666cab8 JA |
949 | struct group_run_stats *rs, |
950 | struct buf_output *out) | |
4d658652 JA |
951 | { |
952 | double io_u_dist[FIO_IO_U_MAP_NR]; | |
953 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; | |
954 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
955 | double usr_cpu, sys_cpu; | |
956 | int i; | |
957 | ||
958 | /* General Info */ | |
a666cab8 | 959 | log_buf(out, "2;%s;%d;%d", ts->name, ts->groupid, ts->error); |
4d658652 | 960 | /* Log Read Status */ |
a666cab8 | 961 | show_ddir_status_terse(ts, rs, DDIR_READ, out); |
4d658652 | 962 | /* Log Write Status */ |
a666cab8 | 963 | show_ddir_status_terse(ts, rs, DDIR_WRITE, out); |
6eaf09d6 | 964 | /* Log Trim Status */ |
a666cab8 | 965 | show_ddir_status_terse(ts, rs, DDIR_TRIM, out); |
4d658652 JA |
966 | |
967 | /* CPU Usage */ | |
968 | if (ts->total_run_time) { | |
969 | double runt = (double) ts->total_run_time; | |
970 | ||
971 | usr_cpu = (double) ts->usr_time * 100 / runt; | |
972 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
973 | } else { | |
974 | usr_cpu = 0; | |
975 | sys_cpu = 0; | |
976 | } | |
977 | ||
a666cab8 | 978 | log_buf(out, ";%f%%;%f%%;%llu;%llu;%llu", usr_cpu, sys_cpu, |
4e0a8fa2 JA |
979 | (unsigned long long) ts->ctx, |
980 | (unsigned long long) ts->majf, | |
981 | (unsigned long long) ts->minf); | |
4d658652 JA |
982 | |
983 | /* Calc % distribution of IO depths, usecond, msecond latency */ | |
d79db122 | 984 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); |
4d658652 JA |
985 | stat_calc_lat_u(ts, io_u_lat_u); |
986 | stat_calc_lat_m(ts, io_u_lat_m); | |
987 | ||
988 | /* Only show fixed 7 I/O depth levels*/ | |
a666cab8 | 989 | log_buf(out, ";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", |
4d658652 JA |
990 | io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], |
991 | io_u_dist[4], io_u_dist[5], io_u_dist[6]); | |
992 | ||
993 | /* Microsecond latency */ | |
994 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) | |
a666cab8 | 995 | log_buf(out, ";%3.2f%%", io_u_lat_u[i]); |
4d658652 JA |
996 | /* Millisecond latency */ |
997 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) | |
a666cab8 | 998 | log_buf(out, ";%3.2f%%", io_u_lat_m[i]); |
4d658652 JA |
999 | /* Additional output if continue_on_error set - default off*/ |
1000 | if (ts->continue_on_error) | |
a666cab8 JA |
1001 | log_buf(out, ";%llu;%d", (unsigned long long) ts->total_err_count, ts->first_error); |
1002 | log_buf(out, "\n"); | |
4d658652 JA |
1003 | |
1004 | /* Additional output if description is set */ | |
0a3c52f0 | 1005 | if (strlen(ts->description)) |
a666cab8 | 1006 | log_buf(out, ";%s", ts->description); |
4d658652 | 1007 | |
a666cab8 | 1008 | log_buf(out, "\n"); |
4d658652 JA |
1009 | } |
1010 | ||
3449ab8c | 1011 | static void show_thread_status_terse_v3_v4(struct thread_stat *ts, |
a666cab8 JA |
1012 | struct group_run_stats *rs, int ver, |
1013 | struct buf_output *out) | |
c6ae0a5b | 1014 | { |
2270890c | 1015 | double io_u_dist[FIO_IO_U_MAP_NR]; |
04a0feae JA |
1016 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
1017 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
c6ae0a5b | 1018 | double usr_cpu, sys_cpu; |
04a0feae | 1019 | int i; |
c6ae0a5b | 1020 | |
562c2d2f | 1021 | /* General Info */ |
a666cab8 | 1022 | log_buf(out, "%d;%s;%s;%d;%d", ver, fio_version_string, |
5e726d0a | 1023 | ts->name, ts->groupid, ts->error); |
562c2d2f | 1024 | /* Log Read Status */ |
a666cab8 | 1025 | show_ddir_status_terse(ts, rs, DDIR_READ, out); |
562c2d2f | 1026 | /* Log Write Status */ |
a666cab8 | 1027 | show_ddir_status_terse(ts, rs, DDIR_WRITE, out); |
6eaf09d6 | 1028 | /* Log Trim Status */ |
3449ab8c | 1029 | if (ver == 4) |
a666cab8 | 1030 | show_ddir_status_terse(ts, rs, DDIR_TRIM, out); |
c6ae0a5b | 1031 | |
562c2d2f | 1032 | /* CPU Usage */ |
756867bd JA |
1033 | if (ts->total_run_time) { |
1034 | double runt = (double) ts->total_run_time; | |
c6ae0a5b | 1035 | |
756867bd JA |
1036 | usr_cpu = (double) ts->usr_time * 100 / runt; |
1037 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
c6ae0a5b JA |
1038 | } else { |
1039 | usr_cpu = 0; | |
1040 | sys_cpu = 0; | |
1041 | } | |
1042 | ||
a666cab8 | 1043 | log_buf(out, ";%f%%;%f%%;%llu;%llu;%llu", usr_cpu, sys_cpu, |
4e0a8fa2 JA |
1044 | (unsigned long long) ts->ctx, |
1045 | (unsigned long long) ts->majf, | |
1046 | (unsigned long long) ts->minf); | |
2270890c | 1047 | |
562c2d2f | 1048 | /* Calc % distribution of IO depths, usecond, msecond latency */ |
d79db122 | 1049 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); |
04a0feae JA |
1050 | stat_calc_lat_u(ts, io_u_lat_u); |
1051 | stat_calc_lat_m(ts, io_u_lat_m); | |
2270890c | 1052 | |
562c2d2f | 1053 | /* Only show fixed 7 I/O depth levels*/ |
a666cab8 | 1054 | log_buf(out, ";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", |
5ec10eaa JA |
1055 | io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], |
1056 | io_u_dist[4], io_u_dist[5], io_u_dist[6]); | |
2270890c | 1057 | |
562c2d2f | 1058 | /* Microsecond latency */ |
04a0feae | 1059 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) |
a666cab8 | 1060 | log_buf(out, ";%3.2f%%", io_u_lat_u[i]); |
562c2d2f | 1061 | /* Millisecond latency */ |
04a0feae | 1062 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) |
a666cab8 | 1063 | log_buf(out, ";%3.2f%%", io_u_lat_m[i]); |
f2f788dd JA |
1064 | |
1065 | /* disk util stats, if any */ | |
a666cab8 | 1066 | show_disk_util(1, NULL, out); |
f2f788dd | 1067 | |
562c2d2f | 1068 | /* Additional output if continue_on_error set - default off*/ |
f2bba182 | 1069 | if (ts->continue_on_error) |
a666cab8 | 1070 | log_buf(out, ";%llu;%d", (unsigned long long) ts->total_err_count, ts->first_error); |
2270890c | 1071 | |
562c2d2f | 1072 | /* Additional output if description is set */ |
4b0f2258 | 1073 | if (strlen(ts->description)) |
a666cab8 | 1074 | log_buf(out, ";%s", ts->description); |
946e4276 | 1075 | |
a666cab8 | 1076 | log_buf(out, "\n"); |
756867bd JA |
1077 | } |
1078 | ||
cc372b17 SL |
1079 | static struct json_object *show_thread_status_json(struct thread_stat *ts, |
1080 | struct group_run_stats *rs) | |
1081 | { | |
1082 | struct json_object *root, *tmp; | |
b01af66b | 1083 | struct jobs_eta *je; |
cc372b17 SL |
1084 | double io_u_dist[FIO_IO_U_MAP_NR]; |
1085 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; | |
1086 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
1087 | double usr_cpu, sys_cpu; | |
1088 | int i; | |
b01af66b CJ |
1089 | size_t size; |
1090 | ||
cc372b17 SL |
1091 | root = json_create_object(); |
1092 | json_object_add_value_string(root, "jobname", ts->name); | |
1093 | json_object_add_value_int(root, "groupid", ts->groupid); | |
1094 | json_object_add_value_int(root, "error", ts->error); | |
1095 | ||
b01af66b CJ |
1096 | /* ETA Info */ |
1097 | je = get_jobs_eta(1, &size); | |
2de615ad JA |
1098 | if (je) { |
1099 | json_object_add_value_int(root, "eta", je->eta_sec); | |
1100 | json_object_add_value_int(root, "elapsed", je->elapsed_sec); | |
1101 | } | |
b01af66b | 1102 | |
cc372b17 SL |
1103 | add_ddir_status_json(ts, rs, DDIR_READ, root); |
1104 | add_ddir_status_json(ts, rs, DDIR_WRITE, root); | |
f3afa57e | 1105 | add_ddir_status_json(ts, rs, DDIR_TRIM, root); |
cc372b17 SL |
1106 | |
1107 | /* CPU Usage */ | |
1108 | if (ts->total_run_time) { | |
1109 | double runt = (double) ts->total_run_time; | |
1110 | ||
1111 | usr_cpu = (double) ts->usr_time * 100 / runt; | |
1112 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
1113 | } else { | |
1114 | usr_cpu = 0; | |
1115 | sys_cpu = 0; | |
1116 | } | |
1117 | json_object_add_value_float(root, "usr_cpu", usr_cpu); | |
1118 | json_object_add_value_float(root, "sys_cpu", sys_cpu); | |
1119 | json_object_add_value_int(root, "ctx", ts->ctx); | |
1120 | json_object_add_value_int(root, "majf", ts->majf); | |
1121 | json_object_add_value_int(root, "minf", ts->minf); | |
1122 | ||
1123 | ||
1124 | /* Calc % distribution of IO depths, usecond, msecond latency */ | |
d79db122 | 1125 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); |
cc372b17 SL |
1126 | stat_calc_lat_u(ts, io_u_lat_u); |
1127 | stat_calc_lat_m(ts, io_u_lat_m); | |
1128 | ||
1129 | tmp = json_create_object(); | |
1130 | json_object_add_value_object(root, "iodepth_level", tmp); | |
1131 | /* Only show fixed 7 I/O depth levels*/ | |
1132 | for (i = 0; i < 7; i++) { | |
1133 | char name[20]; | |
1134 | if (i < 6) | |
98ffb8f3 | 1135 | snprintf(name, 20, "%d", 1 << i); |
cc372b17 | 1136 | else |
98ffb8f3 | 1137 | snprintf(name, 20, ">=%d", 1 << i); |
cc372b17 SL |
1138 | json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]); |
1139 | } | |
1140 | ||
1141 | tmp = json_create_object(); | |
1142 | json_object_add_value_object(root, "latency_us", tmp); | |
1143 | /* Microsecond latency */ | |
1144 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) { | |
1145 | const char *ranges[] = { "2", "4", "10", "20", "50", "100", | |
1146 | "250", "500", "750", "1000", }; | |
1147 | json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]); | |
1148 | } | |
1149 | /* Millisecond latency */ | |
1150 | tmp = json_create_object(); | |
1151 | json_object_add_value_object(root, "latency_ms", tmp); | |
1152 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) { | |
1153 | const char *ranges[] = { "2", "4", "10", "20", "50", "100", | |
1154 | "250", "500", "750", "1000", "2000", | |
1155 | ">=2000", }; | |
1156 | json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]); | |
1157 | } | |
1158 | ||
1159 | /* Additional output if continue_on_error set - default off*/ | |
1160 | if (ts->continue_on_error) { | |
1161 | json_object_add_value_int(root, "total_err", ts->total_err_count); | |
952b05e0 | 1162 | json_object_add_value_int(root, "first_error", ts->first_error); |
cc372b17 SL |
1163 | } |
1164 | ||
3e260a46 JA |
1165 | if (ts->latency_depth) { |
1166 | json_object_add_value_int(root, "latency_depth", ts->latency_depth); | |
1167 | json_object_add_value_int(root, "latency_target", ts->latency_target); | |
1168 | json_object_add_value_float(root, "latency_percentile", ts->latency_percentile.u.f); | |
1169 | json_object_add_value_int(root, "latency_window", ts->latency_window); | |
1170 | } | |
1171 | ||
cc372b17 SL |
1172 | /* Additional output if description is set */ |
1173 | if (strlen(ts->description)) | |
1174 | json_object_add_value_string(root, "desc", ts->description); | |
1175 | ||
66347cfa DE |
1176 | if (ts->nr_block_infos) { |
1177 | /* Block error histogram and types */ | |
1178 | int len; | |
1179 | unsigned int *percentiles = NULL; | |
1180 | unsigned int block_state_counts[BLOCK_STATE_COUNT]; | |
1181 | ||
1182 | len = calc_block_percentiles(ts->nr_block_infos, ts->block_infos, | |
1183 | ts->percentile_list, | |
1184 | &percentiles, block_state_counts); | |
1185 | ||
1186 | if (len) { | |
1187 | struct json_object *block, *percentile_object, *states; | |
8a68c41c | 1188 | int state; |
66347cfa DE |
1189 | block = json_create_object(); |
1190 | json_object_add_value_object(root, "block", block); | |
1191 | ||
1192 | percentile_object = json_create_object(); | |
1193 | json_object_add_value_object(block, "percentiles", | |
1194 | percentile_object); | |
1195 | for (i = 0; i < len; i++) { | |
1196 | char buf[20]; | |
1197 | snprintf(buf, sizeof(buf), "%f", | |
1198 | ts->percentile_list[i].u.f); | |
1199 | json_object_add_value_int(percentile_object, | |
1200 | (const char *)buf, | |
1201 | percentiles[i]); | |
1202 | } | |
1203 | ||
1204 | states = json_create_object(); | |
1205 | json_object_add_value_object(block, "states", states); | |
1206 | for (state = 0; state < BLOCK_STATE_COUNT; state++) { | |
1207 | json_object_add_value_int(states, | |
1208 | block_state_names[state], | |
1209 | block_state_counts[state]); | |
1210 | } | |
1211 | free(percentiles); | |
1212 | } | |
1213 | } | |
1214 | ||
cc372b17 SL |
1215 | return root; |
1216 | } | |
1217 | ||
4d658652 | 1218 | static void show_thread_status_terse(struct thread_stat *ts, |
a666cab8 JA |
1219 | struct group_run_stats *rs, |
1220 | struct buf_output *out) | |
4d658652 JA |
1221 | { |
1222 | if (terse_version == 2) | |
a666cab8 | 1223 | show_thread_status_terse_v2(ts, rs, out); |
3449ab8c | 1224 | else if (terse_version == 3 || terse_version == 4) |
a666cab8 | 1225 | show_thread_status_terse_v3_v4(ts, rs, terse_version, out); |
4d658652 JA |
1226 | else |
1227 | log_err("fio: bad terse version!? %d\n", terse_version); | |
1228 | } | |
1229 | ||
952b05e0 | 1230 | struct json_object *show_thread_status(struct thread_stat *ts, |
a666cab8 JA |
1231 | struct group_run_stats *rs, |
1232 | struct buf_output *out) | |
952b05e0 | 1233 | { |
129fb2d4 JA |
1234 | struct json_object *ret = NULL; |
1235 | ||
1236 | if (output_format & FIO_OUTPUT_TERSE) | |
a666cab8 | 1237 | show_thread_status_terse(ts, rs, out); |
129fb2d4 JA |
1238 | if (output_format & FIO_OUTPUT_JSON) |
1239 | ret = show_thread_status_json(ts, rs); | |
1240 | if (output_format & FIO_OUTPUT_NORMAL) | |
a666cab8 | 1241 | show_thread_status_normal(ts, rs, out); |
129fb2d4 JA |
1242 | |
1243 | return ret; | |
952b05e0 CF |
1244 | } |
1245 | ||
197574e4 | 1246 | static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr) |
756867bd JA |
1247 | { |
1248 | double mean, S; | |
1249 | ||
e09231c2 ZL |
1250 | if (src->samples == 0) |
1251 | return; | |
1252 | ||
756867bd JA |
1253 | dst->min_val = min(dst->min_val, src->min_val); |
1254 | dst->max_val = max(dst->max_val, src->max_val); | |
756867bd JA |
1255 | |
1256 | /* | |
cdcac5cf YH |
1257 | * Compute new mean and S after the merge |
1258 | * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance | |
1259 | * #Parallel_algorithm> | |
756867bd JA |
1260 | */ |
1261 | if (nr == 1) { | |
802ad4a8 JA |
1262 | mean = src->mean.u.f; |
1263 | S = src->S.u.f; | |
756867bd | 1264 | } else { |
802ad4a8 | 1265 | double delta = src->mean.u.f - dst->mean.u.f; |
cdcac5cf | 1266 | |
802ad4a8 JA |
1267 | mean = ((src->mean.u.f * src->samples) + |
1268 | (dst->mean.u.f * dst->samples)) / | |
cdcac5cf YH |
1269 | (dst->samples + src->samples); |
1270 | ||
802ad4a8 | 1271 | S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) * |
cdcac5cf YH |
1272 | (dst->samples * src->samples) / |
1273 | (dst->samples + src->samples); | |
756867bd JA |
1274 | } |
1275 | ||
cdcac5cf | 1276 | dst->samples += src->samples; |
802ad4a8 JA |
1277 | dst->mean.u.f = mean; |
1278 | dst->S.u.f = S; | |
756867bd JA |
1279 | } |
1280 | ||
37f0c1ae JA |
1281 | void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src) |
1282 | { | |
1283 | int i; | |
1284 | ||
6eaf09d6 | 1285 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
37f0c1ae JA |
1286 | if (dst->max_run[i] < src->max_run[i]) |
1287 | dst->max_run[i] = src->max_run[i]; | |
1288 | if (dst->min_run[i] && dst->min_run[i] > src->min_run[i]) | |
1289 | dst->min_run[i] = src->min_run[i]; | |
1290 | if (dst->max_bw[i] < src->max_bw[i]) | |
1291 | dst->max_bw[i] = src->max_bw[i]; | |
1292 | if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i]) | |
1293 | dst->min_bw[i] = src->min_bw[i]; | |
1294 | ||
1295 | dst->io_kb[i] += src->io_kb[i]; | |
1296 | dst->agg[i] += src->agg[i]; | |
1297 | } | |
1298 | ||
dbae1bd6 JA |
1299 | if (!dst->kb_base) |
1300 | dst->kb_base = src->kb_base; | |
1301 | if (!dst->unit_base) | |
1302 | dst->unit_base = src->unit_base; | |
37f0c1ae JA |
1303 | } |
1304 | ||
5b9babb7 JA |
1305 | void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr) |
1306 | { | |
1307 | int l, k; | |
1308 | ||
6eaf09d6 | 1309 | for (l = 0; l < DDIR_RWDIR_CNT; l++) { |
771e58be JA |
1310 | if (!dst->unified_rw_rep) { |
1311 | sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr); | |
1312 | sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr); | |
1313 | sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr); | |
1314 | sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr); | |
1315 | ||
1316 | dst->io_bytes[l] += src->io_bytes[l]; | |
1317 | ||
1318 | if (dst->runtime[l] < src->runtime[l]) | |
1319 | dst->runtime[l] = src->runtime[l]; | |
1320 | } else { | |
1321 | sum_stat(&dst->clat_stat[0], &src->clat_stat[l], nr); | |
1322 | sum_stat(&dst->slat_stat[0], &src->slat_stat[l], nr); | |
1323 | sum_stat(&dst->lat_stat[0], &src->lat_stat[l], nr); | |
1324 | sum_stat(&dst->bw_stat[0], &src->bw_stat[l], nr); | |
1325 | ||
1326 | dst->io_bytes[0] += src->io_bytes[l]; | |
1327 | ||
1328 | if (dst->runtime[0] < src->runtime[l]) | |
1329 | dst->runtime[0] = src->runtime[l]; | |
1330 | } | |
5b9babb7 JA |
1331 | } |
1332 | ||
1333 | dst->usr_time += src->usr_time; | |
1334 | dst->sys_time += src->sys_time; | |
1335 | dst->ctx += src->ctx; | |
1336 | dst->majf += src->majf; | |
1337 | dst->minf += src->minf; | |
1338 | ||
1339 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) | |
1340 | dst->io_u_map[k] += src->io_u_map[k]; | |
1341 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) | |
1342 | dst->io_u_submit[k] += src->io_u_submit[k]; | |
1343 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) | |
1344 | dst->io_u_complete[k] += src->io_u_complete[k]; | |
1345 | for (k = 0; k < FIO_IO_U_LAT_U_NR; k++) | |
1346 | dst->io_u_lat_u[k] += src->io_u_lat_u[k]; | |
1347 | for (k = 0; k < FIO_IO_U_LAT_M_NR; k++) | |
1348 | dst->io_u_lat_m[k] += src->io_u_lat_m[k]; | |
1349 | ||
6eaf09d6 | 1350 | for (k = 0; k < DDIR_RWDIR_CNT; k++) { |
771e58be JA |
1351 | if (!dst->unified_rw_rep) { |
1352 | dst->total_io_u[k] += src->total_io_u[k]; | |
1353 | dst->short_io_u[k] += src->short_io_u[k]; | |
3bcb9d94 | 1354 | dst->drop_io_u[k] += src->drop_io_u[k]; |
771e58be JA |
1355 | } else { |
1356 | dst->total_io_u[0] += src->total_io_u[k]; | |
1357 | dst->short_io_u[0] += src->short_io_u[k]; | |
3bcb9d94 | 1358 | dst->drop_io_u[0] += src->drop_io_u[k]; |
771e58be | 1359 | } |
5b9babb7 JA |
1360 | } |
1361 | ||
6eaf09d6 | 1362 | for (k = 0; k < DDIR_RWDIR_CNT; k++) { |
5b9babb7 | 1363 | int m; |
771e58be JA |
1364 | |
1365 | for (m = 0; m < FIO_IO_U_PLAT_NR; m++) { | |
1366 | if (!dst->unified_rw_rep) | |
1367 | dst->io_u_plat[k][m] += src->io_u_plat[k][m]; | |
1368 | else | |
1369 | dst->io_u_plat[0][m] += src->io_u_plat[k][m]; | |
1370 | } | |
5b9babb7 JA |
1371 | } |
1372 | ||
1373 | dst->total_run_time += src->total_run_time; | |
1374 | dst->total_submit += src->total_submit; | |
1375 | dst->total_complete += src->total_complete; | |
1376 | } | |
1377 | ||
37f0c1ae JA |
1378 | void init_group_run_stat(struct group_run_stats *gs) |
1379 | { | |
6eaf09d6 | 1380 | int i; |
37f0c1ae | 1381 | memset(gs, 0, sizeof(*gs)); |
6eaf09d6 SL |
1382 | |
1383 | for (i = 0; i < DDIR_RWDIR_CNT; i++) | |
1384 | gs->min_bw[i] = gs->min_run[i] = ~0UL; | |
37f0c1ae JA |
1385 | } |
1386 | ||
1387 | void init_thread_stat(struct thread_stat *ts) | |
1388 | { | |
1389 | int j; | |
1390 | ||
1391 | memset(ts, 0, sizeof(*ts)); | |
1392 | ||
6eaf09d6 | 1393 | for (j = 0; j < DDIR_RWDIR_CNT; j++) { |
37f0c1ae JA |
1394 | ts->lat_stat[j].min_val = -1UL; |
1395 | ts->clat_stat[j].min_val = -1UL; | |
1396 | ts->slat_stat[j].min_val = -1UL; | |
1397 | ts->bw_stat[j].min_val = -1UL; | |
1398 | } | |
1399 | ts->groupid = -1; | |
1400 | } | |
1401 | ||
83f7b64e | 1402 | void __show_run_stats(void) |
3c39a379 JA |
1403 | { |
1404 | struct group_run_stats *runstats, *rs; | |
1405 | struct thread_data *td; | |
756867bd | 1406 | struct thread_stat *threadstats, *ts; |
4da24b69 | 1407 | int i, j, k, nr_ts, last_ts, idx; |
90fef2d1 | 1408 | int kb_base_warned = 0; |
ad705bcb | 1409 | int unit_base_warned = 0; |
cc372b17 SL |
1410 | struct json_object *root = NULL; |
1411 | struct json_array *array = NULL; | |
a666cab8 JA |
1412 | struct buf_output output[FIO_OUTPUT_NR]; |
1413 | ||
3c39a379 JA |
1414 | runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); |
1415 | ||
37f0c1ae JA |
1416 | for (i = 0; i < groupid + 1; i++) |
1417 | init_group_run_stat(&runstats[i]); | |
3c39a379 | 1418 | |
756867bd JA |
1419 | /* |
1420 | * find out how many threads stats we need. if group reporting isn't | |
1421 | * enabled, it's one-per-td. | |
1422 | */ | |
1423 | nr_ts = 0; | |
1424 | last_ts = -1; | |
1425 | for_each_td(td, i) { | |
2dc1bbeb | 1426 | if (!td->o.group_reporting) { |
756867bd JA |
1427 | nr_ts++; |
1428 | continue; | |
1429 | } | |
1430 | if (last_ts == td->groupid) | |
1431 | continue; | |
1432 | ||
1433 | last_ts = td->groupid; | |
1434 | nr_ts++; | |
1435 | } | |
1436 | ||
1437 | threadstats = malloc(nr_ts * sizeof(struct thread_stat)); | |
1438 | ||
37f0c1ae JA |
1439 | for (i = 0; i < nr_ts; i++) |
1440 | init_thread_stat(&threadstats[i]); | |
756867bd JA |
1441 | |
1442 | j = 0; | |
1443 | last_ts = -1; | |
197574e4 | 1444 | idx = 0; |
34572e28 | 1445 | for_each_td(td, i) { |
2dc1bbeb JA |
1446 | if (idx && (!td->o.group_reporting || |
1447 | (td->o.group_reporting && last_ts != td->groupid))) { | |
7abd0e3a JA |
1448 | idx = 0; |
1449 | j++; | |
1450 | } | |
1451 | ||
1452 | last_ts = td->groupid; | |
1453 | ||
756867bd JA |
1454 | ts = &threadstats[j]; |
1455 | ||
83349190 | 1456 | ts->clat_percentiles = td->o.clat_percentiles; |
435d195a | 1457 | ts->percentile_precision = td->o.percentile_precision; |
fd112d34 | 1458 | memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list)); |
83349190 | 1459 | |
197574e4 | 1460 | idx++; |
6586ee89 | 1461 | ts->members++; |
756867bd | 1462 | |
7abd0e3a | 1463 | if (ts->groupid == -1) { |
2dc84ba7 JA |
1464 | /* |
1465 | * These are per-group shared already | |
1466 | */ | |
4e59d0f3 | 1467 | strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE - 1); |
a64e88da JA |
1468 | if (td->o.description) |
1469 | strncpy(ts->description, td->o.description, | |
4e59d0f3 | 1470 | FIO_JOBDESC_SIZE - 1); |
a64e88da | 1471 | else |
4e59d0f3 | 1472 | memset(ts->description, 0, FIO_JOBDESC_SIZE); |
a64e88da | 1473 | |
2f122b13 JA |
1474 | /* |
1475 | * If multiple entries in this group, this is | |
1476 | * the first member. | |
1477 | */ | |
1478 | ts->thread_number = td->thread_number; | |
756867bd | 1479 | ts->groupid = td->groupid; |
2dc84ba7 JA |
1480 | |
1481 | /* | |
1482 | * first pid in group, not very useful... | |
1483 | */ | |
756867bd | 1484 | ts->pid = td->pid; |
90fef2d1 JA |
1485 | |
1486 | ts->kb_base = td->o.kb_base; | |
ad705bcb | 1487 | ts->unit_base = td->o.unit_base; |
771e58be | 1488 | ts->unified_rw_rep = td->o.unified_rw_rep; |
90fef2d1 JA |
1489 | } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) { |
1490 | log_info("fio: kb_base differs for jobs in group, using" | |
1491 | " %u as the base\n", ts->kb_base); | |
1492 | kb_base_warned = 1; | |
ad705bcb SN |
1493 | } else if (ts->unit_base != td->o.unit_base && !unit_base_warned) { |
1494 | log_info("fio: unit_base differs for jobs in group, using" | |
1495 | " %u as the base\n", ts->unit_base); | |
1496 | unit_base_warned = 1; | |
2dc84ba7 JA |
1497 | } |
1498 | ||
f2bba182 RR |
1499 | ts->continue_on_error = td->o.continue_on_error; |
1500 | ts->total_err_count += td->total_err_count; | |
1501 | ts->first_error = td->first_error; | |
1502 | if (!ts->error) { | |
1503 | if (!td->error && td->o.continue_on_error && | |
1504 | td->first_error) { | |
1505 | ts->error = td->first_error; | |
3660ceae JA |
1506 | ts->verror[sizeof(ts->verror) - 1] = '\0'; |
1507 | strncpy(ts->verror, td->verror, sizeof(ts->verror) - 1); | |
f2bba182 RR |
1508 | } else if (td->error) { |
1509 | ts->error = td->error; | |
3660ceae JA |
1510 | ts->verror[sizeof(ts->verror) - 1] = '\0'; |
1511 | strncpy(ts->verror, td->verror, sizeof(ts->verror) - 1); | |
f2bba182 | 1512 | } |
756867bd JA |
1513 | } |
1514 | ||
3e260a46 JA |
1515 | ts->latency_depth = td->latency_qd; |
1516 | ts->latency_target = td->o.latency_target; | |
1517 | ts->latency_percentile = td->o.latency_percentile; | |
1518 | ts->latency_window = td->o.latency_window; | |
1519 | ||
0e4dd95c | 1520 | ts->nr_block_infos = td->ts.nr_block_infos; |
4da24b69 JA |
1521 | for (k = 0; k < ts->nr_block_infos; k++) |
1522 | ts->block_infos[k] = td->ts.block_infos[k]; | |
0e4dd95c | 1523 | |
5b9babb7 | 1524 | sum_thread_stats(ts, &td->ts, idx); |
756867bd JA |
1525 | } |
1526 | ||
1527 | for (i = 0; i < nr_ts; i++) { | |
94370ac4 | 1528 | unsigned long long bw; |
3c39a379 | 1529 | |
756867bd JA |
1530 | ts = &threadstats[i]; |
1531 | rs = &runstats[ts->groupid]; | |
90fef2d1 | 1532 | rs->kb_base = ts->kb_base; |
ad705bcb | 1533 | rs->unit_base = ts->unit_base; |
771e58be | 1534 | rs->unified_rw_rep += ts->unified_rw_rep; |
3c39a379 | 1535 | |
6eaf09d6 | 1536 | for (j = 0; j < DDIR_RWDIR_CNT; j++) { |
94370ac4 JA |
1537 | if (!ts->runtime[j]) |
1538 | continue; | |
1539 | if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j]) | |
1540 | rs->min_run[j] = ts->runtime[j]; | |
1541 | if (ts->runtime[j] > rs->max_run[j]) | |
1542 | rs->max_run[j] = ts->runtime[j]; | |
1543 | ||
1544 | bw = 0; | |
8879fd15 | 1545 | if (ts->runtime[j]) { |
c857cfeb JA |
1546 | unsigned long runt = ts->runtime[j]; |
1547 | unsigned long long kb; | |
8879fd15 | 1548 | |
c857cfeb JA |
1549 | kb = ts->io_bytes[j] / rs->kb_base; |
1550 | bw = kb * 1000 / runt; | |
8879fd15 | 1551 | } |
94370ac4 JA |
1552 | if (bw < rs->min_bw[j]) |
1553 | rs->min_bw[j] = bw; | |
1554 | if (bw > rs->max_bw[j]) | |
1555 | rs->max_bw[j] = bw; | |
1556 | ||
90fef2d1 | 1557 | rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base; |
94370ac4 | 1558 | } |
3c39a379 JA |
1559 | } |
1560 | ||
1561 | for (i = 0; i < groupid + 1; i++) { | |
6eaf09d6 SL |
1562 | int ddir; |
1563 | ||
3c39a379 JA |
1564 | rs = &runstats[i]; |
1565 | ||
6eaf09d6 SL |
1566 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
1567 | if (rs->max_run[ddir]) | |
1568 | rs->agg[ddir] = (rs->io_kb[ddir] * 1000) / | |
1569 | rs->max_run[ddir]; | |
1570 | } | |
3c39a379 JA |
1571 | } |
1572 | ||
a666cab8 | 1573 | for (i = 0; i < FIO_OUTPUT_NR; i++) |
e250c0a9 | 1574 | buf_output_init(&output[i]); |
a666cab8 | 1575 | |
3c39a379 JA |
1576 | /* |
1577 | * don't overwrite last signal output | |
1578 | */ | |
129fb2d4 | 1579 | if (output_format & FIO_OUTPUT_NORMAL) |
a666cab8 | 1580 | log_buf(&output[__FIO_OUTPUT_NORMAL], "\n"); |
129fb2d4 | 1581 | if (output_format & FIO_OUTPUT_JSON) { |
35326842 | 1582 | char time_buf[32]; |
91e53870 SO |
1583 | time_t time_p; |
1584 | ||
1585 | time(&time_p); | |
1586 | os_ctime_r((const time_t *) &time_p, time_buf, | |
1587 | sizeof(time_buf)); | |
1588 | time_buf[strlen(time_buf) - 1] = '\0'; | |
1589 | ||
cc372b17 SL |
1590 | root = json_create_object(); |
1591 | json_object_add_value_string(root, "fio version", fio_version_string); | |
91e53870 SO |
1592 | json_object_add_value_int(root, "timestamp", time_p); |
1593 | json_object_add_value_string(root, "time", time_buf); | |
cc372b17 SL |
1594 | array = json_create_array(); |
1595 | json_object_add_value_array(root, "jobs", array); | |
1596 | } | |
3c39a379 | 1597 | |
756867bd JA |
1598 | for (i = 0; i < nr_ts; i++) { |
1599 | ts = &threadstats[i]; | |
1600 | rs = &runstats[ts->groupid]; | |
3c39a379 | 1601 | |
a64e88da JA |
1602 | if (is_backend) |
1603 | fio_server_send_ts(ts, rs); | |
129fb2d4 JA |
1604 | else { |
1605 | if (output_format & FIO_OUTPUT_TERSE) | |
a666cab8 | 1606 | show_thread_status_terse(ts, rs, &output[__FIO_OUTPUT_TERSE]); |
129fb2d4 JA |
1607 | if (output_format & FIO_OUTPUT_JSON) { |
1608 | struct json_object *tmp = show_thread_status_json(ts, rs); | |
1609 | json_array_add_value_object(array, tmp); | |
1610 | } | |
1611 | if (output_format & FIO_OUTPUT_NORMAL) | |
a666cab8 | 1612 | show_thread_status_normal(ts, rs, &output[__FIO_OUTPUT_NORMAL]); |
129fb2d4 | 1613 | } |
3c39a379 | 1614 | } |
129fb2d4 | 1615 | if (output_format & FIO_OUTPUT_JSON) { |
cc372b17 | 1616 | /* disk util stats, if any */ |
a666cab8 | 1617 | show_disk_util(1, root, &output[__FIO_OUTPUT_JSON]); |
cc372b17 | 1618 | |
a666cab8 | 1619 | show_idle_prof_stats(FIO_OUTPUT_JSON, root, &output[__FIO_OUTPUT_JSON]); |
f2a2ce0e | 1620 | |
a666cab8 JA |
1621 | json_print_object(root, &output[__FIO_OUTPUT_JSON]); |
1622 | log_buf(&output[__FIO_OUTPUT_JSON], "\n"); | |
cc372b17 SL |
1623 | json_free_object(root); |
1624 | } | |
3c39a379 | 1625 | |
72c27ff8 JA |
1626 | for (i = 0; i < groupid + 1; i++) { |
1627 | rs = &runstats[i]; | |
3c39a379 | 1628 | |
72c27ff8 | 1629 | rs->groupid = i; |
d09a64a0 | 1630 | if (is_backend) |
72c27ff8 | 1631 | fio_server_send_gs(rs); |
129fb2d4 | 1632 | else if (output_format & FIO_OUTPUT_NORMAL) |
a666cab8 | 1633 | show_group_stats(rs, &output[__FIO_OUTPUT_NORMAL]); |
c6ae0a5b | 1634 | } |
eecf272f | 1635 | |
72c27ff8 JA |
1636 | if (is_backend) |
1637 | fio_server_send_du(); | |
129fb2d4 | 1638 | else if (output_format & FIO_OUTPUT_NORMAL) { |
a666cab8 JA |
1639 | show_disk_util(0, NULL, &output[__FIO_OUTPUT_NORMAL]); |
1640 | show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL, &output[__FIO_OUTPUT_NORMAL]); | |
60904003 | 1641 | } |
f2a2ce0e | 1642 | |
3d57c0e9 | 1643 | for (i = 0; i < FIO_OUTPUT_NR; i++) { |
a666cab8 | 1644 | buf_output_flush(&output[i]); |
3d57c0e9 JA |
1645 | buf_output_free(&output[i]); |
1646 | } | |
2b8c71b0 | 1647 | |
fdd5f15f | 1648 | log_info_flush(); |
eecf272f | 1649 | free(runstats); |
756867bd | 1650 | free(threadstats); |
3c39a379 JA |
1651 | } |
1652 | ||
cef9175e JA |
1653 | void show_run_stats(void) |
1654 | { | |
1655 | fio_mutex_down(stat_mutex); | |
1656 | __show_run_stats(); | |
1657 | fio_mutex_up(stat_mutex); | |
1658 | } | |
1659 | ||
5ddc6707 | 1660 | void __show_running_run_stats(void) |
b852e7cf JA |
1661 | { |
1662 | struct thread_data *td; | |
1663 | unsigned long long *rt; | |
1664 | struct timeval tv; | |
1665 | int i; | |
1666 | ||
90811930 JA |
1667 | fio_mutex_down(stat_mutex); |
1668 | ||
b852e7cf JA |
1669 | rt = malloc(thread_number * sizeof(unsigned long long)); |
1670 | fio_gettime(&tv, NULL); | |
1671 | ||
1672 | for_each_td(td, i) { | |
1673 | rt[i] = mtime_since(&td->start, &tv); | |
1674 | if (td_read(td) && td->io_bytes[DDIR_READ]) | |
1675 | td->ts.runtime[DDIR_READ] += rt[i]; | |
1676 | if (td_write(td) && td->io_bytes[DDIR_WRITE]) | |
1677 | td->ts.runtime[DDIR_WRITE] += rt[i]; | |
6eaf09d6 SL |
1678 | if (td_trim(td) && td->io_bytes[DDIR_TRIM]) |
1679 | td->ts.runtime[DDIR_TRIM] += rt[i]; | |
b852e7cf | 1680 | |
c97f1ad6 | 1681 | td->update_rusage = 1; |
6eaf09d6 SL |
1682 | td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ]; |
1683 | td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE]; | |
1684 | td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM]; | |
b852e7cf JA |
1685 | td->ts.total_run_time = mtime_since(&td->epoch, &tv); |
1686 | } | |
1687 | ||
c97f1ad6 | 1688 | for_each_td(td, i) { |
fda2cfac JA |
1689 | if (td->runstate >= TD_EXITED) |
1690 | continue; | |
c97f1ad6 JA |
1691 | if (td->rusage_sem) { |
1692 | td->update_rusage = 1; | |
1693 | fio_mutex_down(td->rusage_sem); | |
1694 | } | |
1695 | td->update_rusage = 0; | |
1696 | } | |
1697 | ||
cef9175e | 1698 | __show_run_stats(); |
b852e7cf JA |
1699 | |
1700 | for_each_td(td, i) { | |
1701 | if (td_read(td) && td->io_bytes[DDIR_READ]) | |
1702 | td->ts.runtime[DDIR_READ] -= rt[i]; | |
1703 | if (td_write(td) && td->io_bytes[DDIR_WRITE]) | |
1704 | td->ts.runtime[DDIR_WRITE] -= rt[i]; | |
6eaf09d6 SL |
1705 | if (td_trim(td) && td->io_bytes[DDIR_TRIM]) |
1706 | td->ts.runtime[DDIR_TRIM] -= rt[i]; | |
b852e7cf JA |
1707 | } |
1708 | ||
1709 | free(rt); | |
cef9175e | 1710 | fio_mutex_up(stat_mutex); |
b852e7cf JA |
1711 | } |
1712 | ||
06464907 JA |
1713 | static int status_interval_init; |
1714 | static struct timeval status_time; | |
77d99675 | 1715 | static int status_file_disabled; |
06464907 | 1716 | |
dac45f23 | 1717 | #define FIO_STATUS_FILE "fio-dump-status" |
06464907 JA |
1718 | |
1719 | static int check_status_file(void) | |
1720 | { | |
1721 | struct stat sb; | |
a0bafb7d BC |
1722 | const char *temp_dir; |
1723 | char fio_status_file_path[PATH_MAX]; | |
06464907 | 1724 | |
77d99675 JA |
1725 | if (status_file_disabled) |
1726 | return 0; | |
1727 | ||
a0bafb7d | 1728 | temp_dir = getenv("TMPDIR"); |
48b16e27 | 1729 | if (temp_dir == NULL) { |
a0bafb7d | 1730 | temp_dir = getenv("TEMP"); |
48b16e27 JA |
1731 | if (temp_dir && strlen(temp_dir) >= PATH_MAX) |
1732 | temp_dir = NULL; | |
1733 | } | |
a0bafb7d BC |
1734 | if (temp_dir == NULL) |
1735 | temp_dir = "/tmp"; | |
1736 | ||
1737 | snprintf(fio_status_file_path, sizeof(fio_status_file_path), "%s/%s", temp_dir, FIO_STATUS_FILE); | |
1738 | ||
1739 | if (stat(fio_status_file_path, &sb)) | |
06464907 JA |
1740 | return 0; |
1741 | ||
77d99675 JA |
1742 | if (unlink(fio_status_file_path) < 0) { |
1743 | log_err("fio: failed to unlink %s: %s\n", fio_status_file_path, | |
1744 | strerror(errno)); | |
1745 | log_err("fio: disabling status file updates\n"); | |
1746 | status_file_disabled = 1; | |
1747 | } | |
1748 | ||
06464907 JA |
1749 | return 1; |
1750 | } | |
1751 | ||
1752 | void check_for_running_stats(void) | |
1753 | { | |
1754 | if (status_interval) { | |
1755 | if (!status_interval_init) { | |
1756 | fio_gettime(&status_time, NULL); | |
1757 | status_interval_init = 1; | |
1758 | } else if (mtime_since_now(&status_time) >= status_interval) { | |
1759 | show_running_run_stats(); | |
1760 | fio_gettime(&status_time, NULL); | |
1761 | return; | |
1762 | } | |
1763 | } | |
1764 | if (check_status_file()) { | |
1765 | show_running_run_stats(); | |
1766 | return; | |
1767 | } | |
1768 | } | |
1769 | ||
68704084 | 1770 | static inline void add_stat_sample(struct io_stat *is, unsigned long data) |
3c39a379 | 1771 | { |
68704084 | 1772 | double val = data; |
6660cc67 | 1773 | double delta; |
68704084 JA |
1774 | |
1775 | if (data > is->max_val) | |
1776 | is->max_val = data; | |
1777 | if (data < is->min_val) | |
1778 | is->min_val = data; | |
1779 | ||
802ad4a8 | 1780 | delta = val - is->mean.u.f; |
ef11d737 | 1781 | if (delta) { |
802ad4a8 JA |
1782 | is->mean.u.f += delta / (is->samples + 1.0); |
1783 | is->S.u.f += delta * (val - is->mean.u.f); | |
ef11d737 | 1784 | } |
3c39a379 | 1785 | |
3c39a379 JA |
1786 | is->samples++; |
1787 | } | |
1788 | ||
bb3884d8 | 1789 | static void __add_log_sample(struct io_log *iolog, unsigned long val, |
306ddc97 | 1790 | enum fio_ddir ddir, unsigned int bs, |
ae588852 | 1791 | unsigned long t, uint64_t offset) |
3c39a379 | 1792 | { |
aee2ab67 | 1793 | uint64_t nr_samples = iolog->nr_samples; |
ae588852 | 1794 | struct io_sample *s; |
306ddc97 | 1795 | |
3c568239 JA |
1796 | if (iolog->disabled) |
1797 | return; | |
1798 | ||
b8bc8cba JA |
1799 | if (!iolog->nr_samples) |
1800 | iolog->avg_last = t; | |
1801 | ||
3c39a379 | 1802 | if (iolog->nr_samples == iolog->max_samples) { |
ae588852 | 1803 | size_t new_size; |
3c568239 | 1804 | void *new_log; |
3c39a379 | 1805 | |
ae588852 | 1806 | new_size = 2 * iolog->max_samples * log_entry_sz(iolog); |
aee2ab67 JA |
1807 | |
1808 | if (iolog->log_gz && (new_size > iolog->log_gz)) { | |
1809 | if (iolog_flush(iolog, 0)) { | |
1810 | log_err("fio: failed flushing iolog! Will stop logging.\n"); | |
1811 | iolog->disabled = 1; | |
1812 | return; | |
1813 | } | |
1814 | nr_samples = iolog->nr_samples; | |
1815 | } else { | |
1816 | new_log = realloc(iolog->log, new_size); | |
1817 | if (!new_log) { | |
1818 | log_err("fio: failed extending iolog! Will stop logging.\n"); | |
1819 | iolog->disabled = 1; | |
1820 | return; | |
1821 | } | |
1822 | iolog->log = new_log; | |
1823 | iolog->max_samples <<= 1; | |
3c568239 | 1824 | } |
3c39a379 JA |
1825 | } |
1826 | ||
ae588852 JA |
1827 | s = get_sample(iolog, nr_samples); |
1828 | ||
1829 | s->val = val; | |
1830 | s->time = t; | |
b26317c9 | 1831 | io_sample_set_ddir(iolog, s, ddir); |
ae588852 JA |
1832 | s->bs = bs; |
1833 | ||
1834 | if (iolog->log_offset) { | |
1835 | struct io_sample_offset *so = (void *) s; | |
1836 | ||
1837 | so->offset = offset; | |
1838 | } | |
1839 | ||
3c39a379 JA |
1840 | iolog->nr_samples++; |
1841 | } | |
1842 | ||
7fb28d36 JA |
1843 | static inline void reset_io_stat(struct io_stat *ios) |
1844 | { | |
1845 | ios->max_val = ios->min_val = ios->samples = 0; | |
1846 | ios->mean.u.f = ios->S.u.f = 0; | |
1847 | } | |
1848 | ||
6bb58215 JA |
1849 | void reset_io_stats(struct thread_data *td) |
1850 | { | |
1851 | struct thread_stat *ts = &td->ts; | |
1852 | int i, j; | |
1853 | ||
1854 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { | |
1855 | reset_io_stat(&ts->clat_stat[i]); | |
1856 | reset_io_stat(&ts->slat_stat[i]); | |
1857 | reset_io_stat(&ts->lat_stat[i]); | |
1858 | reset_io_stat(&ts->bw_stat[i]); | |
1859 | reset_io_stat(&ts->iops_stat[i]); | |
1860 | ||
1861 | ts->io_bytes[i] = 0; | |
1862 | ts->runtime[i] = 0; | |
1863 | ||
1864 | for (j = 0; j < FIO_IO_U_PLAT_NR; j++) | |
1865 | ts->io_u_plat[i][j] = 0; | |
1866 | } | |
1867 | ||
1868 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { | |
1869 | ts->io_u_map[i] = 0; | |
1870 | ts->io_u_submit[i] = 0; | |
1871 | ts->io_u_complete[i] = 0; | |
1872 | ts->io_u_lat_u[i] = 0; | |
1873 | ts->io_u_lat_m[i] = 0; | |
1874 | ts->total_submit = 0; | |
1875 | ts->total_complete = 0; | |
1876 | } | |
1877 | ||
1878 | for (i = 0; i < 3; i++) { | |
1879 | ts->total_io_u[i] = 0; | |
1880 | ts->short_io_u[i] = 0; | |
3bcb9d94 | 1881 | ts->drop_io_u[i] = 0; |
6bb58215 JA |
1882 | } |
1883 | } | |
1884 | ||
99007068 PO |
1885 | static void _add_stat_to_log(struct io_log *iolog, unsigned long elapsed) |
1886 | { | |
1887 | /* | |
1888 | * Note an entry in the log. Use the mean from the logged samples, | |
1889 | * making sure to properly round up. Only write a log entry if we | |
1890 | * had actual samples done. | |
1891 | */ | |
1892 | if (iolog->avg_window[DDIR_READ].samples) { | |
1893 | unsigned long mr; | |
1894 | ||
1895 | mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50; | |
ae588852 | 1896 | __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed, 0); |
99007068 PO |
1897 | } |
1898 | if (iolog->avg_window[DDIR_WRITE].samples) { | |
1899 | unsigned long mw; | |
1900 | ||
1901 | mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50; | |
ae588852 | 1902 | __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed, 0); |
99007068 PO |
1903 | } |
1904 | if (iolog->avg_window[DDIR_TRIM].samples) { | |
1905 | unsigned long mw; | |
1906 | ||
1907 | mw = iolog->avg_window[DDIR_TRIM].mean.u.f + 0.50; | |
ae588852 | 1908 | __add_log_sample(iolog, mw, DDIR_TRIM, 0, elapsed, 0); |
99007068 PO |
1909 | } |
1910 | ||
1911 | reset_io_stat(&iolog->avg_window[DDIR_READ]); | |
1912 | reset_io_stat(&iolog->avg_window[DDIR_WRITE]); | |
1913 | reset_io_stat(&iolog->avg_window[DDIR_TRIM]); | |
1914 | } | |
1915 | ||
bb3884d8 | 1916 | static void add_log_sample(struct thread_data *td, struct io_log *iolog, |
306ddc97 | 1917 | unsigned long val, enum fio_ddir ddir, |
ae588852 | 1918 | unsigned int bs, uint64_t offset) |
bb3884d8 | 1919 | { |
7fb28d36 | 1920 | unsigned long elapsed, this_window; |
b8bc8cba | 1921 | |
ff58fced JA |
1922 | if (!ddir_rw(ddir)) |
1923 | return; | |
1924 | ||
b8bc8cba JA |
1925 | elapsed = mtime_since_now(&td->epoch); |
1926 | ||
1927 | /* | |
1928 | * If no time averaging, just add the log sample. | |
1929 | */ | |
1930 | if (!iolog->avg_msec) { | |
ae588852 | 1931 | __add_log_sample(iolog, val, ddir, bs, elapsed, offset); |
b8bc8cba JA |
1932 | return; |
1933 | } | |
1934 | ||
1935 | /* | |
1936 | * Add the sample. If the time period has passed, then | |
1937 | * add that entry to the log and clear. | |
1938 | */ | |
1939 | add_stat_sample(&iolog->avg_window[ddir], val); | |
1940 | ||
7fb28d36 JA |
1941 | /* |
1942 | * If period hasn't passed, adding the above sample is all we | |
1943 | * need to do. | |
1944 | */ | |
b8bc8cba JA |
1945 | this_window = elapsed - iolog->avg_last; |
1946 | if (this_window < iolog->avg_msec) | |
1947 | return; | |
1948 | ||
99007068 | 1949 | _add_stat_to_log(iolog, elapsed); |
b8bc8cba | 1950 | |
99007068 PO |
1951 | iolog->avg_last = elapsed; |
1952 | } | |
6eaf09d6 | 1953 | |
99007068 PO |
1954 | void finalize_logs(struct thread_data *td) |
1955 | { | |
1956 | unsigned long elapsed; | |
6eaf09d6 | 1957 | |
99007068 | 1958 | elapsed = mtime_since_now(&td->epoch); |
b8bc8cba | 1959 | |
99007068 PO |
1960 | if (td->clat_log) |
1961 | _add_stat_to_log(td->clat_log, elapsed); | |
1962 | if (td->slat_log) | |
1963 | _add_stat_to_log(td->slat_log, elapsed); | |
1964 | if (td->lat_log) | |
1965 | _add_stat_to_log(td->lat_log, elapsed); | |
1966 | if (td->bw_log) | |
1967 | _add_stat_to_log(td->bw_log, elapsed); | |
1968 | if (td->iops_log) | |
1969 | _add_stat_to_log(td->iops_log, elapsed); | |
bb3884d8 JA |
1970 | } |
1971 | ||
306ddc97 | 1972 | void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs) |
bb3884d8 | 1973 | { |
ff58fced | 1974 | struct io_log *iolog; |
bb3884d8 | 1975 | |
ff58fced JA |
1976 | if (!ddir_rw(ddir)) |
1977 | return; | |
1978 | ||
1979 | iolog = agg_io_log[ddir]; | |
ae588852 | 1980 | __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis(), 0); |
bb3884d8 JA |
1981 | } |
1982 | ||
83349190 YH |
1983 | static void add_clat_percentile_sample(struct thread_stat *ts, |
1984 | unsigned long usec, enum fio_ddir ddir) | |
1985 | { | |
1986 | unsigned int idx = plat_val_to_idx(usec); | |
1987 | assert(idx < FIO_IO_U_PLAT_NR); | |
1988 | ||
1989 | ts->io_u_plat[ddir][idx]++; | |
1990 | } | |
1991 | ||
1e97cce9 | 1992 | void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, |
ae588852 | 1993 | unsigned long usec, unsigned int bs, uint64_t offset) |
3c39a379 | 1994 | { |
756867bd | 1995 | struct thread_stat *ts = &td->ts; |
079ad09b | 1996 | |
ff58fced JA |
1997 | if (!ddir_rw(ddir)) |
1998 | return; | |
1999 | ||
75dc383e JA |
2000 | td_io_u_lock(td); |
2001 | ||
d85f5118 | 2002 | add_stat_sample(&ts->clat_stat[ddir], usec); |
3c39a379 | 2003 | |
7b9f733a | 2004 | if (td->clat_log) |
ae588852 | 2005 | add_log_sample(td, td->clat_log, usec, ddir, bs, offset); |
83349190 YH |
2006 | |
2007 | if (ts->clat_percentiles) | |
2008 | add_clat_percentile_sample(ts, usec, ddir); | |
75dc383e JA |
2009 | |
2010 | td_io_u_unlock(td); | |
3c39a379 JA |
2011 | } |
2012 | ||
1e97cce9 | 2013 | void add_slat_sample(struct thread_data *td, enum fio_ddir ddir, |
ae588852 | 2014 | unsigned long usec, unsigned int bs, uint64_t offset) |
3c39a379 | 2015 | { |
756867bd | 2016 | struct thread_stat *ts = &td->ts; |
079ad09b | 2017 | |
ff58fced JA |
2018 | if (!ddir_rw(ddir)) |
2019 | return; | |
2020 | ||
75dc383e JA |
2021 | td_io_u_lock(td); |
2022 | ||
d85f5118 | 2023 | add_stat_sample(&ts->slat_stat[ddir], usec); |
3c39a379 | 2024 | |
7b9f733a | 2025 | if (td->slat_log) |
ae588852 | 2026 | add_log_sample(td, td->slat_log, usec, ddir, bs, offset); |
75dc383e JA |
2027 | |
2028 | td_io_u_unlock(td); | |
3c39a379 JA |
2029 | } |
2030 | ||
02af0988 | 2031 | void add_lat_sample(struct thread_data *td, enum fio_ddir ddir, |
ae588852 | 2032 | unsigned long usec, unsigned int bs, uint64_t offset) |
02af0988 JA |
2033 | { |
2034 | struct thread_stat *ts = &td->ts; | |
2035 | ||
ff58fced JA |
2036 | if (!ddir_rw(ddir)) |
2037 | return; | |
2038 | ||
75dc383e JA |
2039 | td_io_u_lock(td); |
2040 | ||
02af0988 JA |
2041 | add_stat_sample(&ts->lat_stat[ddir], usec); |
2042 | ||
7b9f733a | 2043 | if (td->lat_log) |
ae588852 | 2044 | add_log_sample(td, td->lat_log, usec, ddir, bs, offset); |
75dc383e JA |
2045 | |
2046 | td_io_u_unlock(td); | |
02af0988 JA |
2047 | } |
2048 | ||
306ddc97 | 2049 | void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs, |
1e97cce9 | 2050 | struct timeval *t) |
3c39a379 | 2051 | { |
756867bd | 2052 | struct thread_stat *ts = &td->ts; |
ff58fced JA |
2053 | unsigned long spent, rate; |
2054 | ||
2055 | if (!ddir_rw(ddir)) | |
2056 | return; | |
3c39a379 | 2057 | |
c8eeb9df | 2058 | spent = mtime_since(&td->bw_sample_time, t); |
2dc1bbeb | 2059 | if (spent < td->o.bw_avg_time) |
3c39a379 | 2060 | return; |
9602d8df | 2061 | |
a9da8ab2 JA |
2062 | td_io_u_lock(td); |
2063 | ||
9602d8df | 2064 | /* |
5daa4ebe JC |
2065 | * Compute both read and write rates for the interval. |
2066 | */ | |
6eaf09d6 | 2067 | for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) { |
5daa4ebe JC |
2068 | uint64_t delta; |
2069 | ||
2070 | delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir]; | |
2071 | if (!delta) | |
2072 | continue; /* No entries for interval */ | |
3c39a379 | 2073 | |
0956264f JA |
2074 | if (spent) |
2075 | rate = delta * 1000 / spent / 1024; | |
2076 | else | |
2077 | rate = 0; | |
2078 | ||
5daa4ebe | 2079 | add_stat_sample(&ts->bw_stat[ddir], rate); |
3c39a379 | 2080 | |
5daa4ebe | 2081 | if (td->bw_log) |
ae588852 | 2082 | add_log_sample(td, td->bw_log, rate, ddir, bs, 0); |
5daa4ebe JC |
2083 | |
2084 | td->stat_io_bytes[ddir] = td->this_io_bytes[ddir]; | |
2085 | } | |
3c39a379 | 2086 | |
c8eeb9df | 2087 | fio_gettime(&td->bw_sample_time, NULL); |
a9da8ab2 | 2088 | td_io_u_unlock(td); |
3c39a379 | 2089 | } |
c8eeb9df | 2090 | |
9b7e600d | 2091 | void add_iops_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs, |
c8eeb9df JA |
2092 | struct timeval *t) |
2093 | { | |
2094 | struct thread_stat *ts = &td->ts; | |
2095 | unsigned long spent, iops; | |
2096 | ||
2097 | if (!ddir_rw(ddir)) | |
2098 | return; | |
2099 | ||
2100 | spent = mtime_since(&td->iops_sample_time, t); | |
2101 | if (spent < td->o.iops_avg_time) | |
2102 | return; | |
2103 | ||
a9da8ab2 JA |
2104 | td_io_u_lock(td); |
2105 | ||
9602d8df JA |
2106 | /* |
2107 | * Compute both read and write rates for the interval. | |
2108 | */ | |
6eaf09d6 | 2109 | for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) { |
9602d8df | 2110 | uint64_t delta; |
c8eeb9df | 2111 | |
9602d8df JA |
2112 | delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir]; |
2113 | if (!delta) | |
2114 | continue; /* No entries for interval */ | |
2115 | ||
0956264f JA |
2116 | if (spent) |
2117 | iops = (delta * 1000) / spent; | |
2118 | else | |
2119 | iops = 0; | |
2120 | ||
9602d8df | 2121 | add_stat_sample(&ts->iops_stat[ddir], iops); |
c8eeb9df | 2122 | |
9602d8df | 2123 | if (td->iops_log) |
ae588852 | 2124 | add_log_sample(td, td->iops_log, iops, ddir, bs, 0); |
9602d8df | 2125 | |
421f4a82 | 2126 | td->stat_io_blocks[ddir] = td->this_io_blocks[ddir]; |
9602d8df | 2127 | } |
c8eeb9df JA |
2128 | |
2129 | fio_gettime(&td->iops_sample_time, NULL); | |
a9da8ab2 | 2130 | td_io_u_unlock(td); |
c8eeb9df | 2131 | } |
cef9175e JA |
2132 | |
2133 | void stat_init(void) | |
2134 | { | |
2135 | stat_mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED); | |
2136 | } | |
2137 | ||
2138 | void stat_exit(void) | |
2139 | { | |
2140 | /* | |
2141 | * When we have the mutex, we know out-of-band access to it | |
2142 | * have ended. | |
2143 | */ | |
2144 | fio_mutex_down(stat_mutex); | |
2145 | fio_mutex_remove(stat_mutex); | |
2146 | } | |
b2ee7647 | 2147 | |
b2ee7647 JA |
2148 | /* |
2149 | * Called from signal handler. Wake up status thread. | |
2150 | */ | |
2151 | void show_running_run_stats(void) | |
2152 | { | |
5ddc6707 JA |
2153 | helper_do_stat = 1; |
2154 | pthread_cond_signal(&helper_cond); | |
b2ee7647 | 2155 | } |
66347cfa DE |
2156 | |
2157 | uint32_t *io_u_block_info(struct thread_data *td, struct io_u *io_u) | |
2158 | { | |
2159 | /* Ignore io_u's which span multiple blocks--they will just get | |
2160 | * inaccurate counts. */ | |
2161 | int idx = (io_u->offset - io_u->file->file_offset) | |
2162 | / td->o.bs[DDIR_TRIM]; | |
2163 | uint32_t *info = &td->ts.block_infos[idx]; | |
2164 | assert(idx < td->ts.nr_block_infos); | |
2165 | return info; | |
2166 | } |