Commit | Line | Data |
---|---|---|
3c39a379 JA |
1 | #include <stdio.h> |
2 | #include <string.h> | |
0fc3cb4c | 3 | #include <stdlib.h> |
3c39a379 | 4 | #include <sys/time.h> |
5c4e1dbc | 5 | #include <sys/stat.h> |
3c39a379 JA |
6 | #include <math.h> |
7 | ||
8 | #include "fio.h" | |
7c9b1bce | 9 | #include "diskutil.h" |
c7c6cb4c | 10 | #include "lib/ieee754.h" |
cc372b17 | 11 | #include "json.h" |
44404c5a | 12 | #include "lib/getrusage.h" |
f2a2ce0e | 13 | #include "idletime.h" |
0f38bbef | 14 | #include "lib/pow2.h" |
a666cab8 | 15 | #include "lib/output_buffer.h" |
a39fb9ea | 16 | #include "helper_thread.h" |
90d2d53f | 17 | #include "smalloc.h" |
fd5d733f | 18 | #include "zbd.h" |
f5bff36e | 19 | #include "oslib/asprintf.h" |
3c39a379 | 20 | |
3d0d549a BP |
21 | #ifdef WIN32 |
22 | #define LOG_MSEC_SLACK 2 | |
23 | #else | |
674456bf | 24 | #define LOG_MSEC_SLACK 1 |
3d0d549a | 25 | #endif |
d454a205 | 26 | |
2e7da20d SK |
27 | struct log_sample { |
28 | union io_sample_data data; | |
29 | uint32_t ddir; | |
30 | uint64_t bs; | |
31 | uint64_t offset; | |
32 | uint16_t priority; | |
14d3134a | 33 | uint64_t issue_time; |
2e7da20d SK |
34 | }; |
35 | ||
971caeb1 | 36 | struct fio_sem *stat_sem; |
cef9175e | 37 | |
210dd0fc JA |
38 | void clear_rusage_stat(struct thread_data *td) |
39 | { | |
40 | struct thread_stat *ts = &td->ts; | |
41 | ||
42 | fio_getrusage(&td->ru_start); | |
43 | ts->usr_time = ts->sys_time = 0; | |
44 | ts->ctx = 0; | |
45 | ts->minf = ts->majf = 0; | |
46 | } | |
47 | ||
3c39a379 JA |
48 | void update_rusage_stat(struct thread_data *td) |
49 | { | |
756867bd | 50 | struct thread_stat *ts = &td->ts; |
3c39a379 | 51 | |
44404c5a | 52 | fio_getrusage(&td->ru_end); |
8b6a404c | 53 | ts->usr_time += mtime_since_tv(&td->ru_start.ru_utime, |
c8aaba19 | 54 | &td->ru_end.ru_utime); |
8b6a404c | 55 | ts->sys_time += mtime_since_tv(&td->ru_start.ru_stime, |
c8aaba19 JA |
56 | &td->ru_end.ru_stime); |
57 | ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw | |
58 | - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw); | |
59 | ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt; | |
60 | ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt; | |
5ec10eaa | 61 | |
c8aaba19 | 62 | memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end)); |
3c39a379 JA |
63 | } |
64 | ||
83349190 YH |
65 | /* |
66 | * Given a latency, return the index of the corresponding bucket in | |
67 | * the structure tracking percentiles. | |
68 | * | |
69 | * (1) find the group (and error bits) that the value (latency) | |
70 | * belongs to by looking at its MSB. (2) find the bucket number in the | |
71 | * group by looking at the index bits. | |
72 | * | |
73 | */ | |
d6bb626e | 74 | static unsigned int plat_val_to_idx(unsigned long long val) |
83349190 YH |
75 | { |
76 | unsigned int msb, error_bits, base, offset, idx; | |
77 | ||
78 | /* Find MSB starting from bit 0 */ | |
79 | if (val == 0) | |
80 | msb = 0; | |
81 | else | |
d6bb626e | 82 | msb = (sizeof(val)*8) - __builtin_clzll(val) - 1; |
83349190 | 83 | |
716050f2 JA |
84 | /* |
85 | * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use | |
86 | * all bits of the sample as index | |
87 | */ | |
83349190 YH |
88 | if (msb <= FIO_IO_U_PLAT_BITS) |
89 | return val; | |
90 | ||
91 | /* Compute the number of error bits to discard*/ | |
92 | error_bits = msb - FIO_IO_U_PLAT_BITS; | |
93 | ||
94 | /* Compute the number of buckets before the group */ | |
95 | base = (error_bits + 1) << FIO_IO_U_PLAT_BITS; | |
96 | ||
716050f2 JA |
97 | /* |
98 | * Discard the error bits and apply the mask to find the | |
3c3ed070 | 99 | * index for the buckets in the group |
716050f2 | 100 | */ |
83349190 YH |
101 | offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits); |
102 | ||
103 | /* Make sure the index does not exceed (array size - 1) */ | |
3c3ed070 | 104 | idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1) ? |
83349190 YH |
105 | (base + offset) : (FIO_IO_U_PLAT_NR - 1); |
106 | ||
107 | return idx; | |
108 | } | |
109 | ||
110 | /* | |
111 | * Convert the given index of the bucket array to the value | |
112 | * represented by the bucket | |
113 | */ | |
129e4193 | 114 | static unsigned long long plat_idx_to_val(unsigned int idx) |
83349190 | 115 | { |
c8b44cfa RL |
116 | unsigned int error_bits; |
117 | unsigned long long k, base; | |
83349190 YH |
118 | |
119 | assert(idx < FIO_IO_U_PLAT_NR); | |
120 | ||
121 | /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use | |
122 | * all bits of the sample as index */ | |
3c3ed070 | 123 | if (idx < (FIO_IO_U_PLAT_VAL << 1)) |
83349190 YH |
124 | return idx; |
125 | ||
126 | /* Find the group and compute the minimum value of that group */ | |
3c3ed070 | 127 | error_bits = (idx >> FIO_IO_U_PLAT_BITS) - 1; |
c8b44cfa | 128 | base = ((unsigned long long) 1) << (error_bits + FIO_IO_U_PLAT_BITS); |
83349190 YH |
129 | |
130 | /* Find its bucket number of the group */ | |
131 | k = idx % FIO_IO_U_PLAT_VAL; | |
132 | ||
133 | /* Return the mean of the range of the bucket */ | |
134 | return base + ((k + 0.5) * (1 << error_bits)); | |
135 | } | |
136 | ||
137 | static int double_cmp(const void *a, const void *b) | |
138 | { | |
802ad4a8 JA |
139 | const fio_fp64_t fa = *(const fio_fp64_t *) a; |
140 | const fio_fp64_t fb = *(const fio_fp64_t *) b; | |
83349190 YH |
141 | int cmp = 0; |
142 | ||
802ad4a8 | 143 | if (fa.u.f > fb.u.f) |
83349190 | 144 | cmp = 1; |
802ad4a8 | 145 | else if (fa.u.f < fb.u.f) |
83349190 YH |
146 | cmp = -1; |
147 | ||
148 | return cmp; | |
149 | } | |
150 | ||
6cc0e5aa | 151 | unsigned int calc_clat_percentiles(uint64_t *io_u_plat, unsigned long long nr, |
d6bb626e VF |
152 | fio_fp64_t *plist, unsigned long long **output, |
153 | unsigned long long *maxv, unsigned long long *minv) | |
83349190 | 154 | { |
447b94e1 | 155 | unsigned long long sum = 0; |
1db92cb6 | 156 | unsigned int len, i, j = 0; |
d6bb626e | 157 | unsigned long long *ovals = NULL; |
8985b491 | 158 | bool is_last; |
1db92cb6 | 159 | |
d6bb626e | 160 | *minv = -1ULL; |
1db92cb6 | 161 | *maxv = 0; |
83349190 | 162 | |
802ad4a8 JA |
163 | len = 0; |
164 | while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0) | |
165 | len++; | |
716050f2 | 166 | |
351de8de | 167 | if (!len) |
1db92cb6 | 168 | return 0; |
351de8de | 169 | |
716050f2 | 170 | /* |
802ad4a8 JA |
171 | * Sort the percentile list. Note that it may already be sorted if |
172 | * we are using the default values, but since it's a short list this | |
173 | * isn't a worry. Also note that this does not work for NaN values. | |
716050f2 | 174 | */ |
802ad4a8 | 175 | if (len > 1) |
68e0dc1a | 176 | qsort(plist, len, sizeof(plist[0]), double_cmp); |
83349190 | 177 | |
5d89c625 VF |
178 | ovals = malloc(len * sizeof(*ovals)); |
179 | if (!ovals) | |
180 | return 0; | |
181 | ||
4f6f8298 JA |
182 | /* |
183 | * Calculate bucket values, note down max and min values | |
184 | */ | |
8985b491 | 185 | is_last = false; |
07511a63 | 186 | for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) { |
83349190 | 187 | sum += io_u_plat[i]; |
298d751e | 188 | while (sum >= ((long double) plist[j].u.f / 100.0 * nr)) { |
802ad4a8 | 189 | assert(plist[j].u.f <= 100.0); |
83349190 | 190 | |
4f6f8298 | 191 | ovals[j] = plat_idx_to_val(i); |
1db92cb6 JA |
192 | if (ovals[j] < *minv) |
193 | *minv = ovals[j]; | |
194 | if (ovals[j] > *maxv) | |
195 | *maxv = ovals[j]; | |
07511a63 | 196 | |
8985b491 | 197 | is_last = (j == len - 1) != 0; |
07511a63 JA |
198 | if (is_last) |
199 | break; | |
200 | ||
4f6f8298 JA |
201 | j++; |
202 | } | |
203 | } | |
83349190 | 204 | |
298d751e VF |
205 | if (!is_last) |
206 | log_err("fio: error calculating latency percentiles\n"); | |
207 | ||
1db92cb6 JA |
208 | *output = ovals; |
209 | return len; | |
210 | } | |
211 | ||
212 | /* | |
213 | * Find and display the p-th percentile of clat | |
214 | */ | |
6cc0e5aa | 215 | static void show_clat_percentiles(uint64_t *io_u_plat, unsigned long long nr, |
a666cab8 | 216 | fio_fp64_t *plist, unsigned int precision, |
b2b3eefe | 217 | const char *pre, struct buf_output *out) |
1db92cb6 | 218 | { |
d6bb626e VF |
219 | unsigned int divisor, len, i, j = 0; |
220 | unsigned long long minv, maxv; | |
221 | unsigned long long *ovals; | |
8985b491 | 222 | int per_line, scale_down, time_width; |
8985b491 | 223 | bool is_last; |
eef02441 | 224 | char fmt[32]; |
1db92cb6 JA |
225 | |
226 | len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv); | |
b2b3eefe | 227 | if (!len || !ovals) |
824d8186 | 228 | return; |
1db92cb6 | 229 | |
4f6f8298 | 230 | /* |
d6bb626e VF |
231 | * We default to nsecs, but if the value range is such that we |
232 | * should scale down to usecs or msecs, do that. | |
4f6f8298 | 233 | */ |
d6bb626e VF |
234 | if (minv > 2000000 && maxv > 99999999ULL) { |
235 | scale_down = 2; | |
236 | divisor = 1000000; | |
b599759b | 237 | log_buf(out, " %s percentiles (msec):\n |", pre); |
d6bb626e VF |
238 | } else if (minv > 2000 && maxv > 99999) { |
239 | scale_down = 1; | |
240 | divisor = 1000; | |
b599759b | 241 | log_buf(out, " %s percentiles (usec):\n |", pre); |
4f6f8298 JA |
242 | } else { |
243 | scale_down = 0; | |
d6bb626e | 244 | divisor = 1; |
b599759b | 245 | log_buf(out, " %s percentiles (nsec):\n |", pre); |
4f6f8298 | 246 | } |
83349190 | 247 | |
619adf9c | 248 | |
d6bb626e | 249 | time_width = max(5, (int) (log10(maxv / divisor) + 1)); |
74558486 JA |
250 | snprintf(fmt, sizeof(fmt), " %%%u.%ufth=[%%%dllu]%%c", precision + 3, |
251 | precision, time_width); | |
252 | /* fmt will be something like " %5.2fth=[%4llu]%c" */ | |
d6bb626e | 253 | per_line = (80 - 7) / (precision + 10 + time_width); |
81ab0b3a | 254 | |
d6bb626e | 255 | for (j = 0; j < len; j++) { |
4f6f8298 | 256 | /* for formatting */ |
eef02441 | 257 | if (j != 0 && (j % per_line) == 0) |
a666cab8 | 258 | log_buf(out, " |"); |
83349190 | 259 | |
4f6f8298 | 260 | /* end of the list */ |
8985b491 | 261 | is_last = (j == len - 1) != 0; |
83349190 | 262 | |
d6bb626e | 263 | for (i = 0; i < scale_down; i++) |
4f6f8298 JA |
264 | ovals[j] = (ovals[j] + 999) / 1000; |
265 | ||
d6bb626e | 266 | log_buf(out, fmt, plist[j].u.f, ovals[j], is_last ? '\n' : ','); |
4f6f8298 JA |
267 | |
268 | if (is_last) | |
269 | break; | |
270 | ||
eef02441 | 271 | if ((j % per_line) == per_line - 1) /* for formatting */ |
a666cab8 | 272 | log_buf(out, "\n"); |
83349190 | 273 | } |
4f6f8298 | 274 | |
283feb79 | 275 | free(ovals); |
83349190 YH |
276 | } |
277 | ||
692dec0c NC |
278 | static int get_nr_prios_with_samples(struct thread_stat *ts, enum fio_ddir ddir) |
279 | { | |
280 | int i, nr_prios_with_samples = 0; | |
281 | ||
282 | for (i = 0; i < ts->nr_clat_prio[ddir]; i++) { | |
283 | if (ts->clat_prio[ddir][i].clat_stat.samples) | |
284 | nr_prios_with_samples++; | |
285 | } | |
286 | ||
287 | return nr_prios_with_samples; | |
288 | } | |
289 | ||
74558486 JA |
290 | bool calc_lat(struct io_stat *is, unsigned long long *min, |
291 | unsigned long long *max, double *mean, double *dev) | |
3c39a379 | 292 | { |
ee0ccb79 | 293 | double n = (double) is->samples; |
3c39a379 | 294 | |
ee0ccb79 | 295 | if (n == 0) |
8aa89d70 | 296 | return false; |
3c39a379 JA |
297 | |
298 | *min = is->min_val; | |
299 | *max = is->max_val; | |
802ad4a8 | 300 | *mean = is->mean.u.f; |
e6d276f2 | 301 | |
68704084 | 302 | if (n > 1.0) |
802ad4a8 | 303 | *dev = sqrt(is->S.u.f / (n - 1.0)); |
ef9c5c40 | 304 | else |
4b43f54e | 305 | *dev = 0; |
ef9c5c40 | 306 | |
8aa89d70 | 307 | return true; |
3c39a379 JA |
308 | } |
309 | ||
5cb8a8cd BP |
310 | void show_mixed_group_stats(struct group_run_stats *rs, struct buf_output *out) |
311 | { | |
312 | char *io, *agg, *min, *max; | |
313 | char *ioalt, *aggalt, *minalt, *maxalt; | |
6dc75062 JA |
314 | uint64_t io_mix = 0, agg_mix = 0, min_mix = -1, max_mix = 0; |
315 | uint64_t min_run = -1, max_run = 0; | |
5cb8a8cd | 316 | const int i2p = is_power_of_2(rs->kb_base); |
6dc75062 | 317 | int i; |
5cb8a8cd BP |
318 | |
319 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { | |
320 | if (!rs->max_run[i]) | |
321 | continue; | |
322 | io_mix += rs->iobytes[i]; | |
323 | agg_mix += rs->agg[i]; | |
324 | min_mix = min_mix < rs->min_bw[i] ? min_mix : rs->min_bw[i]; | |
325 | max_mix = max_mix > rs->max_bw[i] ? max_mix : rs->max_bw[i]; | |
326 | min_run = min_run < rs->min_run[i] ? min_run : rs->min_run[i]; | |
327 | max_run = max_run > rs->max_run[i] ? max_run : rs->max_run[i]; | |
328 | } | |
329 | io = num2str(io_mix, rs->sig_figs, 1, i2p, N2S_BYTE); | |
330 | ioalt = num2str(io_mix, rs->sig_figs, 1, !i2p, N2S_BYTE); | |
331 | agg = num2str(agg_mix, rs->sig_figs, 1, i2p, rs->unit_base); | |
332 | aggalt = num2str(agg_mix, rs->sig_figs, 1, !i2p, rs->unit_base); | |
333 | min = num2str(min_mix, rs->sig_figs, 1, i2p, rs->unit_base); | |
334 | minalt = num2str(min_mix, rs->sig_figs, 1, !i2p, rs->unit_base); | |
335 | max = num2str(max_mix, rs->sig_figs, 1, i2p, rs->unit_base); | |
336 | maxalt = num2str(max_mix, rs->sig_figs, 1, !i2p, rs->unit_base); | |
337 | log_buf(out, " MIXED: bw=%s (%s), %s-%s (%s-%s), io=%s (%s), run=%llu-%llumsec\n", | |
338 | agg, aggalt, min, max, minalt, maxalt, io, ioalt, | |
339 | (unsigned long long) min_run, | |
340 | (unsigned long long) max_run); | |
341 | free(io); | |
342 | free(agg); | |
343 | free(min); | |
344 | free(max); | |
345 | free(ioalt); | |
346 | free(aggalt); | |
347 | free(minalt); | |
348 | free(maxalt); | |
349 | } | |
350 | ||
a666cab8 | 351 | void show_group_stats(struct group_run_stats *rs, struct buf_output *out) |
3c39a379 | 352 | { |
d694a6a7 RE |
353 | char *io, *agg, *min, *max; |
354 | char *ioalt, *aggalt, *minalt, *maxalt; | |
42da5c8b | 355 | const char *str[] = { " READ", " WRITE" , " TRIM"}; |
dbe1125e JA |
356 | int i; |
357 | ||
a666cab8 | 358 | log_buf(out, "\nRun status group %d (all jobs):\n", rs->groupid); |
3c39a379 | 359 | |
6eaf09d6 | 360 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
90fef2d1 JA |
361 | const int i2p = is_power_of_2(rs->kb_base); |
362 | ||
dbe1125e JA |
363 | if (!rs->max_run[i]) |
364 | continue; | |
365 | ||
e883cb35 JF |
366 | io = num2str(rs->iobytes[i], rs->sig_figs, 1, i2p, N2S_BYTE); |
367 | ioalt = num2str(rs->iobytes[i], rs->sig_figs, 1, !i2p, N2S_BYTE); | |
368 | agg = num2str(rs->agg[i], rs->sig_figs, 1, i2p, rs->unit_base); | |
369 | aggalt = num2str(rs->agg[i], rs->sig_figs, 1, !i2p, rs->unit_base); | |
370 | min = num2str(rs->min_bw[i], rs->sig_figs, 1, i2p, rs->unit_base); | |
371 | minalt = num2str(rs->min_bw[i], rs->sig_figs, 1, !i2p, rs->unit_base); | |
372 | max = num2str(rs->max_bw[i], rs->sig_figs, 1, i2p, rs->unit_base); | |
373 | maxalt = num2str(rs->max_bw[i], rs->sig_figs, 1, !i2p, rs->unit_base); | |
d694a6a7 | 374 | log_buf(out, "%s: bw=%s (%s), %s-%s (%s-%s), io=%s (%s), run=%llu-%llumsec\n", |
5cb8a8cd | 375 | (rs->unified_rw_rep == UNIFIED_MIXED) ? " MIXED" : str[i], |
d694a6a7 | 376 | agg, aggalt, min, max, minalt, maxalt, io, ioalt, |
4e0a8fa2 JA |
377 | (unsigned long long) rs->min_run[i], |
378 | (unsigned long long) rs->max_run[i]); | |
dbe1125e | 379 | |
d694a6a7 RE |
380 | free(io); |
381 | free(agg); | |
382 | free(min); | |
383 | free(max); | |
384 | free(ioalt); | |
385 | free(aggalt); | |
386 | free(minalt); | |
387 | free(maxalt); | |
dbe1125e | 388 | } |
6dc75062 | 389 | |
fc002f14 | 390 | /* Need to aggregate statistics to show mixed values */ |
6dc75062 | 391 | if (rs->unified_rw_rep == UNIFIED_BOTH) |
5cb8a8cd | 392 | show_mixed_group_stats(rs, out); |
3c39a379 JA |
393 | } |
394 | ||
6cc0e5aa | 395 | void stat_calc_dist(uint64_t *map, unsigned long total, double *io_u_dist) |
2270890c JA |
396 | { |
397 | int i; | |
398 | ||
399 | /* | |
400 | * Do depth distribution calculations | |
401 | */ | |
402 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { | |
838bc709 JA |
403 | if (total) { |
404 | io_u_dist[i] = (double) map[i] / (double) total; | |
405 | io_u_dist[i] *= 100.0; | |
406 | if (io_u_dist[i] < 0.1 && map[i]) | |
407 | io_u_dist[i] = 0.1; | |
408 | } else | |
409 | io_u_dist[i] = 0.0; | |
2270890c JA |
410 | } |
411 | } | |
412 | ||
04a0feae | 413 | static void stat_calc_lat(struct thread_stat *ts, double *dst, |
6cc0e5aa | 414 | uint64_t *src, int nr) |
2270890c | 415 | { |
d79db122 | 416 | unsigned long total = ddir_rw_sum(ts->total_io_u); |
2270890c JA |
417 | int i; |
418 | ||
419 | /* | |
420 | * Do latency distribution calculations | |
421 | */ | |
04a0feae | 422 | for (i = 0; i < nr; i++) { |
838bc709 JA |
423 | if (total) { |
424 | dst[i] = (double) src[i] / (double) total; | |
425 | dst[i] *= 100.0; | |
426 | if (dst[i] < 0.01 && src[i]) | |
427 | dst[i] = 0.01; | |
428 | } else | |
429 | dst[i] = 0.0; | |
2270890c JA |
430 | } |
431 | } | |
432 | ||
247823cc VF |
433 | /* |
434 | * To keep the terse format unaltered, add all of the ns latency | |
435 | * buckets to the first us latency bucket | |
436 | */ | |
52e4c651 | 437 | static void stat_calc_lat_nu(struct thread_stat *ts, double *io_u_lat_u) |
247823cc VF |
438 | { |
439 | unsigned long ntotal = 0, total = ddir_rw_sum(ts->total_io_u); | |
440 | int i; | |
441 | ||
442 | stat_calc_lat(ts, io_u_lat_u, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR); | |
443 | ||
444 | for (i = 0; i < FIO_IO_U_LAT_N_NR; i++) | |
445 | ntotal += ts->io_u_lat_n[i]; | |
446 | ||
447 | io_u_lat_u[0] += 100.0 * (double) ntotal / (double) total; | |
448 | } | |
449 | ||
d6bb626e VF |
450 | void stat_calc_lat_n(struct thread_stat *ts, double *io_u_lat) |
451 | { | |
452 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_n, FIO_IO_U_LAT_N_NR); | |
453 | } | |
454 | ||
e5bd1347 | 455 | void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat) |
04a0feae JA |
456 | { |
457 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR); | |
458 | } | |
459 | ||
e5bd1347 | 460 | void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat) |
04a0feae JA |
461 | { |
462 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR); | |
463 | } | |
464 | ||
74558486 JA |
465 | static void display_lat(const char *name, unsigned long long min, |
466 | unsigned long long max, double mean, double dev, | |
467 | struct buf_output *out) | |
ea2accc5 | 468 | { |
d6bb626e | 469 | const char *base = "(nsec)"; |
b29ad562 | 470 | char *minp, *maxp; |
ea2accc5 | 471 | |
d6bb626e | 472 | if (nsec_to_msec(&min, &max, &mean, &dev)) |
b29ad562 | 473 | base = "(msec)"; |
d6bb626e VF |
474 | else if (nsec_to_usec(&min, &max, &mean, &dev)) |
475 | base = "(usec)"; | |
b29ad562 | 476 | |
d694a6a7 RE |
477 | minp = num2str(min, 6, 1, 0, N2S_NONE); |
478 | maxp = num2str(max, 6, 1, 0, N2S_NONE); | |
b29ad562 | 479 | |
a666cab8 | 480 | log_buf(out, " %s %s: min=%s, max=%s, avg=%5.02f," |
b29ad562 JA |
481 | " stdev=%5.02f\n", name, base, minp, maxp, mean, dev); |
482 | ||
483 | free(minp); | |
484 | free(maxp); | |
ea2accc5 JA |
485 | } |
486 | ||
b182f077 NC |
487 | static struct thread_stat *gen_mixed_ddir_stats_from_ts(struct thread_stat *ts) |
488 | { | |
489 | struct thread_stat *ts_lcl; | |
490 | ||
491 | /* | |
492 | * Handle aggregation of Reads (ddir = 0), Writes (ddir = 1), and | |
493 | * Trims (ddir = 2) | |
494 | */ | |
495 | ts_lcl = malloc(sizeof(struct thread_stat)); | |
496 | if (!ts_lcl) { | |
497 | log_err("fio: failed to allocate local thread stat\n"); | |
498 | return NULL; | |
499 | } | |
500 | ||
501 | init_thread_stat(ts_lcl); | |
502 | ||
503 | /* calculate mixed stats */ | |
504 | ts_lcl->unified_rw_rep = UNIFIED_MIXED; | |
505 | ts_lcl->lat_percentiles = ts->lat_percentiles; | |
506 | ts_lcl->clat_percentiles = ts->clat_percentiles; | |
507 | ts_lcl->slat_percentiles = ts->slat_percentiles; | |
508 | ts_lcl->percentile_precision = ts->percentile_precision; | |
509 | memcpy(ts_lcl->percentile_list, ts->percentile_list, sizeof(ts->percentile_list)); | |
510 | ||
511 | sum_thread_stats(ts_lcl, ts); | |
512 | ||
513 | return ts_lcl; | |
514 | } | |
515 | ||
2e545522 NC |
516 | static double convert_agg_kbytes_percent(struct group_run_stats *rs, |
517 | enum fio_ddir ddir, int mean) | |
5c0abd5e | 518 | { |
519 | double p_of_agg = 100.0; | |
520 | if (rs && rs->agg[ddir] > 1024) { | |
106e14ce | 521 | p_of_agg = mean * 100.0 / (double) (rs->agg[ddir] / 1024.0); |
5c0abd5e | 522 | |
523 | if (p_of_agg > 100.0) | |
524 | p_of_agg = 100.0; | |
525 | } | |
526 | return p_of_agg; | |
527 | } | |
528 | ||
756867bd | 529 | static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, |
2e545522 | 530 | enum fio_ddir ddir, struct buf_output *out) |
3c39a379 | 531 | { |
d6bb626e VF |
532 | unsigned long runt; |
533 | unsigned long long min, max, bw, iops; | |
3c39a379 | 534 | double mean, dev; |
96563db9 | 535 | char *io_p, *bw_p, *bw_p_alt, *iops_p, *post_st = NULL; |
692dec0c NC |
536 | int i2p, i; |
537 | const char *clat_type = ts->lat_percentiles ? "lat" : "clat"; | |
3c39a379 | 538 | |
b2b3eefe JA |
539 | if (ddir_sync(ddir)) { |
540 | if (calc_lat(&ts->sync_stat, &min, &max, &mean, &dev)) { | |
541 | log_buf(out, " %s:\n", "fsync/fdatasync/sync_file_range"); | |
425d3e0e | 542 | display_lat(io_ddir_name(ddir), min, max, mean, dev, out); |
b2b3eefe JA |
543 | show_clat_percentiles(ts->io_u_sync_plat, |
544 | ts->sync_stat.samples, | |
545 | ts->percentile_list, | |
546 | ts->percentile_precision, | |
425d3e0e | 547 | io_ddir_name(ddir), out); |
b2b3eefe JA |
548 | } |
549 | return; | |
550 | } | |
551 | ||
ff58fced JA |
552 | assert(ddir_rw(ddir)); |
553 | ||
756867bd | 554 | if (!ts->runtime[ddir]) |
3c39a379 JA |
555 | return; |
556 | ||
90fef2d1 | 557 | i2p = is_power_of_2(rs->kb_base); |
8879fd15 JA |
558 | runt = ts->runtime[ddir]; |
559 | ||
560 | bw = (1000 * ts->io_bytes[ddir]) / runt; | |
e883cb35 JF |
561 | io_p = num2str(ts->io_bytes[ddir], ts->sig_figs, 1, i2p, N2S_BYTE); |
562 | bw_p = num2str(bw, ts->sig_figs, 1, i2p, ts->unit_base); | |
563 | bw_p_alt = num2str(bw, ts->sig_figs, 1, !i2p, ts->unit_base); | |
8879fd15 | 564 | |
0aacc50c | 565 | iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt; |
e883cb35 | 566 | iops_p = num2str(iops, ts->sig_figs, 1, 0, N2S_NONE); |
16be6037 | 567 | if (ddir == DDIR_WRITE || ddir == DDIR_TRIM) |
96563db9 JA |
568 | post_st = zbd_write_status(ts); |
569 | else if (ddir == DDIR_READ && ts->cachehit && ts->cachemiss) { | |
570 | uint64_t total; | |
571 | double hit; | |
572 | ||
573 | total = ts->cachehit + ts->cachemiss; | |
574 | hit = (double) ts->cachehit / (double) total; | |
575 | hit *= 100.0; | |
576 | if (asprintf(&post_st, "; Cachehit=%0.2f%%", hit) < 0) | |
577 | post_st = NULL; | |
578 | } | |
dbe1125e | 579 | |
fd5d733f | 580 | log_buf(out, " %s: IOPS=%s, BW=%s (%s)(%s/%llumsec)%s\n", |
5cb8a8cd | 581 | (ts->unified_rw_rep == UNIFIED_MIXED) ? "mixed" : io_ddir_name(ddir), |
d694a6a7 | 582 | iops_p, bw_p, bw_p_alt, io_p, |
fd5d733f | 583 | (unsigned long long) ts->runtime[ddir], |
96563db9 | 584 | post_st ? : ""); |
dbe1125e | 585 | |
96563db9 | 586 | free(post_st); |
dbe1125e JA |
587 | free(io_p); |
588 | free(bw_p); | |
d694a6a7 | 589 | free(bw_p_alt); |
b3605062 | 590 | free(iops_p); |
3c39a379 | 591 | |
b29ad562 | 592 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
a666cab8 | 593 | display_lat("slat", min, max, mean, dev, out); |
b29ad562 | 594 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) |
a666cab8 | 595 | display_lat("clat", min, max, mean, dev, out); |
b29ad562 | 596 | if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) |
a666cab8 | 597 | display_lat(" lat", min, max, mean, dev, out); |
692dec0c NC |
598 | |
599 | /* Only print per prio stats if there are >= 2 prios with samples */ | |
600 | if (get_nr_prios_with_samples(ts, ddir) >= 2) { | |
601 | for (i = 0; i < ts->nr_clat_prio[ddir]; i++) { | |
a967e54d DLM |
602 | char buf[64]; |
603 | ||
604 | if (!calc_lat(&ts->clat_prio[ddir][i].clat_stat, &min, | |
605 | &max, &mean, &dev)) | |
606 | continue; | |
607 | ||
608 | snprintf(buf, sizeof(buf), | |
219a8682 | 609 | "%s prio %u/%u/%u", |
a967e54d DLM |
610 | clat_type, |
611 | ioprio_class(ts->clat_prio[ddir][i].ioprio), | |
219a8682 DLM |
612 | ioprio(ts->clat_prio[ddir][i].ioprio), |
613 | ioprio_hint(ts->clat_prio[ddir][i].ioprio)); | |
a967e54d | 614 | display_lat(buf, min, max, mean, dev, out); |
692dec0c | 615 | } |
2e86a90c | 616 | } |
02af0988 | 617 | |
56440e63 VF |
618 | if (ts->slat_percentiles && ts->slat_stat[ddir].samples > 0) |
619 | show_clat_percentiles(ts->io_u_plat[FIO_SLAT][ddir], | |
620 | ts->slat_stat[ddir].samples, | |
621 | ts->percentile_list, | |
622 | ts->percentile_precision, "slat", out); | |
623 | if (ts->clat_percentiles && ts->clat_stat[ddir].samples > 0) | |
624 | show_clat_percentiles(ts->io_u_plat[FIO_CLAT][ddir], | |
625 | ts->clat_stat[ddir].samples, | |
626 | ts->percentile_list, | |
627 | ts->percentile_precision, "clat", out); | |
628 | if (ts->lat_percentiles && ts->lat_stat[ddir].samples > 0) | |
629 | show_clat_percentiles(ts->io_u_plat[FIO_LAT][ddir], | |
630 | ts->lat_stat[ddir].samples, | |
631 | ts->percentile_list, | |
632 | ts->percentile_precision, "lat", out); | |
633 | ||
b599759b | 634 | if (ts->clat_percentiles || ts->lat_percentiles) { |
692dec0c | 635 | char prio_name[64]; |
af1600c1 SW |
636 | uint64_t samples; |
637 | ||
56440e63 | 638 | if (ts->lat_percentiles) |
af1600c1 | 639 | samples = ts->lat_stat[ddir].samples; |
56440e63 VF |
640 | else |
641 | samples = ts->clat_stat[ddir].samples; | |
b2a432bf | 642 | |
692dec0c NC |
643 | /* Only print per prio stats if there are >= 2 prios with samples */ |
644 | if (get_nr_prios_with_samples(ts, ddir) >= 2) { | |
645 | for (i = 0; i < ts->nr_clat_prio[ddir]; i++) { | |
a967e54d DLM |
646 | uint64_t prio_samples = |
647 | ts->clat_prio[ddir][i].clat_stat.samples; | |
648 | ||
649 | if (!prio_samples) | |
650 | continue; | |
651 | ||
652 | snprintf(prio_name, sizeof(prio_name), | |
219a8682 | 653 | "%s prio %u/%u/%u (%.2f%% of IOs)", |
a967e54d DLM |
654 | clat_type, |
655 | ioprio_class(ts->clat_prio[ddir][i].ioprio), | |
656 | ioprio(ts->clat_prio[ddir][i].ioprio), | |
219a8682 | 657 | ioprio_hint(ts->clat_prio[ddir][i].ioprio), |
a967e54d DLM |
658 | 100. * (double) prio_samples / (double) samples); |
659 | show_clat_percentiles(ts->clat_prio[ddir][i].io_u_plat, | |
660 | prio_samples, ts->percentile_list, | |
661 | ts->percentile_precision, | |
662 | prio_name, out); | |
692dec0c | 663 | } |
b2a432bf | 664 | } |
83349190 | 665 | } |
56440e63 | 666 | |
079ad09b | 667 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
142c7f2d | 668 | double p_of_agg = 100.0, fkb_base = (double)rs->kb_base; |
d694a6a7 RE |
669 | const char *bw_str; |
670 | ||
671 | if ((rs->unit_base == 1) && i2p) | |
672 | bw_str = "Kibit"; | |
673 | else if (rs->unit_base == 1) | |
674 | bw_str = "kbit"; | |
675 | else if (i2p) | |
676 | bw_str = "KiB"; | |
677 | else | |
678 | bw_str = "kB"; | |
d686990a | 679 | |
5c0abd5e | 680 | p_of_agg = convert_agg_kbytes_percent(rs, ddir, mean); |
d1707474 | 681 | |
d686990a SN |
682 | if (rs->unit_base == 1) { |
683 | min *= 8.0; | |
684 | max *= 8.0; | |
685 | mean *= 8.0; | |
686 | dev *= 8.0; | |
687 | } | |
3c39a379 | 688 | |
142c7f2d SN |
689 | if (mean > fkb_base * fkb_base) { |
690 | min /= fkb_base; | |
691 | max /= fkb_base; | |
692 | mean /= fkb_base; | |
693 | dev /= fkb_base; | |
d694a6a7 | 694 | bw_str = (rs->unit_base == 1 ? "Mibit" : "MiB"); |
b7017e32 JA |
695 | } |
696 | ||
54c05828 | 697 | log_buf(out, " bw (%5s/s): min=%5llu, max=%5llu, per=%3.2f%%, " |
29eb371b | 698 | "avg=%5.02f, stdev=%5.02f, samples=%" PRIu64 "\n", |
54c05828 AH |
699 | bw_str, min, max, p_of_agg, mean, dev, |
700 | (&ts->bw_stat[ddir])->samples); | |
3c39a379 | 701 | } |
188b6016 | 702 | if (calc_lat(&ts->iops_stat[ddir], &min, &max, &mean, &dev)) { |
21ba6606 | 703 | log_buf(out, " iops : min=%5llu, max=%5llu, " |
29eb371b | 704 | "avg=%5.02f, stdev=%5.02f, samples=%" PRIu64 "\n", |
54c05828 | 705 | min, max, mean, dev, (&ts->iops_stat[ddir])->samples); |
188b6016 | 706 | } |
3c39a379 JA |
707 | } |
708 | ||
53d966f8 NC |
709 | static void show_mixed_ddir_status(struct group_run_stats *rs, |
710 | struct thread_stat *ts, | |
711 | struct buf_output *out) | |
712 | { | |
b182f077 | 713 | struct thread_stat *ts_lcl = gen_mixed_ddir_stats_from_ts(ts); |
53d966f8 | 714 | |
b182f077 NC |
715 | if (ts_lcl) |
716 | show_ddir_status(rs, ts_lcl, DDIR_READ, out); | |
53d966f8 | 717 | |
692dec0c | 718 | free_clat_prio_stats(ts_lcl); |
53d966f8 NC |
719 | free(ts_lcl); |
720 | } | |
721 | ||
8985b491 JA |
722 | static bool show_lat(double *io_u_lat, int nr, const char **ranges, |
723 | const char *msg, struct buf_output *out) | |
04a0feae | 724 | { |
8985b491 JA |
725 | bool new_line = true, shown = false; |
726 | int i, line = 0; | |
04a0feae JA |
727 | |
728 | for (i = 0; i < nr; i++) { | |
729 | if (io_u_lat[i] <= 0.0) | |
730 | continue; | |
8985b491 | 731 | shown = true; |
04a0feae | 732 | if (new_line) { |
4539ed73 | 733 | if (line) |
a666cab8 | 734 | log_buf(out, "\n"); |
4a19fcaa | 735 | log_buf(out, " lat (%s) : ", msg); |
8985b491 | 736 | new_line = false; |
04a0feae JA |
737 | line = 0; |
738 | } | |
739 | if (line) | |
a666cab8 JA |
740 | log_buf(out, ", "); |
741 | log_buf(out, "%s%3.2f%%", ranges[i], io_u_lat[i]); | |
04a0feae JA |
742 | line++; |
743 | if (line == 5) | |
8985b491 | 744 | new_line = true; |
04a0feae | 745 | } |
7e1773ba JA |
746 | |
747 | if (shown) | |
a666cab8 | 748 | log_buf(out, "\n"); |
7e1773ba | 749 | |
8985b491 | 750 | return true; |
04a0feae JA |
751 | } |
752 | ||
d6bb626e VF |
753 | static void show_lat_n(double *io_u_lat_n, struct buf_output *out) |
754 | { | |
755 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", | |
756 | "250=", "500=", "750=", "1000=", }; | |
757 | ||
758 | show_lat(io_u_lat_n, FIO_IO_U_LAT_N_NR, ranges, "nsec", out); | |
759 | } | |
760 | ||
a666cab8 | 761 | static void show_lat_u(double *io_u_lat_u, struct buf_output *out) |
04a0feae JA |
762 | { |
763 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", | |
764 | "250=", "500=", "750=", "1000=", }; | |
765 | ||
a666cab8 | 766 | show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec", out); |
04a0feae JA |
767 | } |
768 | ||
a666cab8 | 769 | static void show_lat_m(double *io_u_lat_m, struct buf_output *out) |
04a0feae JA |
770 | { |
771 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", | |
772 | "250=", "500=", "750=", "1000=", "2000=", | |
773 | ">=2000=", }; | |
774 | ||
a666cab8 | 775 | show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec", out); |
04a0feae JA |
776 | } |
777 | ||
a666cab8 | 778 | static void show_latencies(struct thread_stat *ts, struct buf_output *out) |
04a0feae | 779 | { |
d6bb626e | 780 | double io_u_lat_n[FIO_IO_U_LAT_N_NR]; |
c551f65a JA |
781 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
782 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
783 | ||
d6bb626e | 784 | stat_calc_lat_n(ts, io_u_lat_n); |
5a18988e JA |
785 | stat_calc_lat_u(ts, io_u_lat_u); |
786 | stat_calc_lat_m(ts, io_u_lat_m); | |
787 | ||
d6bb626e | 788 | show_lat_n(io_u_lat_n, out); |
a666cab8 JA |
789 | show_lat_u(io_u_lat_u, out); |
790 | show_lat_m(io_u_lat_m, out); | |
04a0feae JA |
791 | } |
792 | ||
66347cfa DE |
793 | static int block_state_category(int block_state) |
794 | { | |
795 | switch (block_state) { | |
796 | case BLOCK_STATE_UNINIT: | |
797 | return 0; | |
798 | case BLOCK_STATE_TRIMMED: | |
799 | case BLOCK_STATE_WRITTEN: | |
800 | return 1; | |
801 | case BLOCK_STATE_WRITE_FAILURE: | |
802 | case BLOCK_STATE_TRIM_FAILURE: | |
803 | return 2; | |
804 | default: | |
081c2dc3 | 805 | /* Silence compile warning on some BSDs and have a return */ |
66347cfa | 806 | assert(0); |
07ff5841 | 807 | return -1; |
66347cfa DE |
808 | } |
809 | } | |
810 | ||
811 | static int compare_block_infos(const void *bs1, const void *bs2) | |
812 | { | |
5fff9543 JF |
813 | uint64_t block1 = *(uint64_t *)bs1; |
814 | uint64_t block2 = *(uint64_t *)bs2; | |
66347cfa DE |
815 | int state1 = BLOCK_INFO_STATE(block1); |
816 | int state2 = BLOCK_INFO_STATE(block2); | |
817 | int bscat1 = block_state_category(state1); | |
818 | int bscat2 = block_state_category(state2); | |
819 | int cycles1 = BLOCK_INFO_TRIMS(block1); | |
820 | int cycles2 = BLOCK_INFO_TRIMS(block2); | |
821 | ||
822 | if (bscat1 < bscat2) | |
823 | return -1; | |
824 | if (bscat1 > bscat2) | |
825 | return 1; | |
826 | ||
827 | if (cycles1 < cycles2) | |
828 | return -1; | |
829 | if (cycles1 > cycles2) | |
830 | return 1; | |
831 | ||
832 | if (state1 < state2) | |
833 | return -1; | |
834 | if (state1 > state2) | |
835 | return 1; | |
836 | ||
837 | assert(block1 == block2); | |
838 | return 0; | |
839 | } | |
840 | ||
841 | static int calc_block_percentiles(int nr_block_infos, uint32_t *block_infos, | |
842 | fio_fp64_t *plist, unsigned int **percentiles, | |
843 | unsigned int *types) | |
844 | { | |
845 | int len = 0; | |
846 | int i, nr_uninit; | |
847 | ||
848 | qsort(block_infos, nr_block_infos, sizeof(uint32_t), compare_block_infos); | |
849 | ||
850 | while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0) | |
851 | len++; | |
852 | ||
853 | if (!len) | |
854 | return 0; | |
855 | ||
856 | /* | |
857 | * Sort the percentile list. Note that it may already be sorted if | |
858 | * we are using the default values, but since it's a short list this | |
859 | * isn't a worry. Also note that this does not work for NaN values. | |
860 | */ | |
861 | if (len > 1) | |
68e0dc1a | 862 | qsort(plist, len, sizeof(plist[0]), double_cmp); |
66347cfa | 863 | |
66347cfa DE |
864 | /* Start only after the uninit entries end */ |
865 | for (nr_uninit = 0; | |
866 | nr_uninit < nr_block_infos | |
867 | && BLOCK_INFO_STATE(block_infos[nr_uninit]) == BLOCK_STATE_UNINIT; | |
868 | nr_uninit ++) | |
869 | ; | |
870 | ||
871 | if (nr_uninit == nr_block_infos) | |
872 | return 0; | |
873 | ||
874 | *percentiles = calloc(len, sizeof(**percentiles)); | |
875 | ||
876 | for (i = 0; i < len; i++) { | |
877 | int idx = (plist[i].u.f * (nr_block_infos - nr_uninit) / 100) | |
878 | + nr_uninit; | |
879 | (*percentiles)[i] = BLOCK_INFO_TRIMS(block_infos[idx]); | |
880 | } | |
881 | ||
882 | memset(types, 0, sizeof(*types) * BLOCK_STATE_COUNT); | |
883 | for (i = 0; i < nr_block_infos; i++) | |
884 | types[BLOCK_INFO_STATE(block_infos[i])]++; | |
885 | ||
886 | return len; | |
887 | } | |
888 | ||
889 | static const char *block_state_names[] = { | |
890 | [BLOCK_STATE_UNINIT] = "unwritten", | |
891 | [BLOCK_STATE_TRIMMED] = "trimmed", | |
892 | [BLOCK_STATE_WRITTEN] = "written", | |
893 | [BLOCK_STATE_TRIM_FAILURE] = "trim failure", | |
894 | [BLOCK_STATE_WRITE_FAILURE] = "write failure", | |
895 | }; | |
896 | ||
897 | static void show_block_infos(int nr_block_infos, uint32_t *block_infos, | |
a666cab8 | 898 | fio_fp64_t *plist, struct buf_output *out) |
66347cfa DE |
899 | { |
900 | int len, pos, i; | |
901 | unsigned int *percentiles = NULL; | |
902 | unsigned int block_state_counts[BLOCK_STATE_COUNT]; | |
903 | ||
904 | len = calc_block_percentiles(nr_block_infos, block_infos, plist, | |
905 | &percentiles, block_state_counts); | |
906 | ||
a666cab8 | 907 | log_buf(out, " block lifetime percentiles :\n |"); |
66347cfa DE |
908 | pos = 0; |
909 | for (i = 0; i < len; i++) { | |
910 | uint32_t block_info = percentiles[i]; | |
911 | #define LINE_LENGTH 75 | |
912 | char str[LINE_LENGTH]; | |
913 | int strln = snprintf(str, LINE_LENGTH, " %3.2fth=%u%c", | |
914 | plist[i].u.f, block_info, | |
915 | i == len - 1 ? '\n' : ','); | |
916 | assert(strln < LINE_LENGTH); | |
917 | if (pos + strln > LINE_LENGTH) { | |
918 | pos = 0; | |
a666cab8 | 919 | log_buf(out, "\n |"); |
66347cfa | 920 | } |
a666cab8 | 921 | log_buf(out, "%s", str); |
66347cfa DE |
922 | pos += strln; |
923 | #undef LINE_LENGTH | |
924 | } | |
925 | if (percentiles) | |
926 | free(percentiles); | |
927 | ||
a666cab8 | 928 | log_buf(out, " states :"); |
66347cfa | 929 | for (i = 0; i < BLOCK_STATE_COUNT; i++) |
a666cab8 | 930 | log_buf(out, " %s=%u%c", |
66347cfa DE |
931 | block_state_names[i], block_state_counts[i], |
932 | i == BLOCK_STATE_COUNT - 1 ? '\n' : ','); | |
933 | } | |
934 | ||
d685adfb VF |
935 | static void show_ss_normal(struct thread_stat *ts, struct buf_output *out) |
936 | { | |
d694a6a7 | 937 | char *p1, *p1alt, *p2; |
d685adfb VF |
938 | unsigned long long bw_mean, iops_mean; |
939 | const int i2p = is_power_of_2(ts->kb_base); | |
940 | ||
0c13c969 | 941 | if (!ts->ss_dur) |
d685adfb VF |
942 | return; |
943 | ||
bb49c8bd VF |
944 | bw_mean = steadystate_bw_mean(ts); |
945 | iops_mean = steadystate_iops_mean(ts); | |
d685adfb | 946 | |
e883cb35 JF |
947 | p1 = num2str(bw_mean / ts->kb_base, ts->sig_figs, ts->kb_base, i2p, ts->unit_base); |
948 | p1alt = num2str(bw_mean / ts->kb_base, ts->sig_figs, ts->kb_base, !i2p, ts->unit_base); | |
949 | p2 = num2str(iops_mean, ts->sig_figs, 1, 0, N2S_NONE); | |
d685adfb | 950 | |
d694a6a7 | 951 | log_buf(out, " steadystate : attained=%s, bw=%s (%s), iops=%s, %s%s=%.3f%s\n", |
c8caba48 | 952 | ts->ss_state & FIO_SS_ATTAINED ? "yes" : "no", |
d694a6a7 | 953 | p1, p1alt, p2, |
c8caba48 JA |
954 | ts->ss_state & FIO_SS_IOPS ? "iops" : "bw", |
955 | ts->ss_state & FIO_SS_SLOPE ? " slope": " mean dev", | |
bb49c8bd | 956 | ts->ss_criterion.u.f, |
c8caba48 | 957 | ts->ss_state & FIO_SS_PCT ? "%" : ""); |
d685adfb VF |
958 | |
959 | free(p1); | |
d694a6a7 | 960 | free(p1alt); |
d685adfb VF |
961 | free(p2); |
962 | } | |
963 | ||
2a2fdab1 L |
964 | static void show_agg_stats(struct disk_util_agg *agg, int terse, |
965 | struct buf_output *out) | |
966 | { | |
967 | if (!agg->slavecount) | |
968 | return; | |
969 | ||
970 | if (!terse) { | |
bb08a260 VF |
971 | log_buf(out, ", aggrios=%llu/%llu, aggsectors=%llu/%llu, " |
972 | "aggrmerge=%llu/%llu, aggrticks=%llu/%llu, " | |
973 | "aggrin_queue=%llu, aggrutil=%3.2f%%", | |
2a2fdab1 L |
974 | (unsigned long long) agg->ios[0] / agg->slavecount, |
975 | (unsigned long long) agg->ios[1] / agg->slavecount, | |
bb08a260 VF |
976 | (unsigned long long) agg->sectors[0] / agg->slavecount, |
977 | (unsigned long long) agg->sectors[1] / agg->slavecount, | |
2a2fdab1 L |
978 | (unsigned long long) agg->merges[0] / agg->slavecount, |
979 | (unsigned long long) agg->merges[1] / agg->slavecount, | |
980 | (unsigned long long) agg->ticks[0] / agg->slavecount, | |
981 | (unsigned long long) agg->ticks[1] / agg->slavecount, | |
982 | (unsigned long long) agg->time_in_queue / agg->slavecount, | |
983 | agg->max_util.u.f); | |
984 | } else { | |
985 | log_buf(out, ";slaves;%llu;%llu;%llu;%llu;%llu;%llu;%llu;%3.2f%%", | |
986 | (unsigned long long) agg->ios[0] / agg->slavecount, | |
987 | (unsigned long long) agg->ios[1] / agg->slavecount, | |
988 | (unsigned long long) agg->merges[0] / agg->slavecount, | |
989 | (unsigned long long) agg->merges[1] / agg->slavecount, | |
990 | (unsigned long long) agg->ticks[0] / agg->slavecount, | |
991 | (unsigned long long) agg->ticks[1] / agg->slavecount, | |
992 | (unsigned long long) agg->time_in_queue / agg->slavecount, | |
993 | agg->max_util.u.f); | |
994 | } | |
995 | } | |
996 | ||
997 | static void aggregate_slaves_stats(struct disk_util *masterdu) | |
998 | { | |
999 | struct disk_util_agg *agg = &masterdu->agg; | |
1000 | struct disk_util_stat *dus; | |
1001 | struct flist_head *entry; | |
1002 | struct disk_util *slavedu; | |
1003 | double util; | |
1004 | ||
1005 | flist_for_each(entry, &masterdu->slaves) { | |
1006 | slavedu = flist_entry(entry, struct disk_util, slavelist); | |
1007 | dus = &slavedu->dus; | |
1008 | agg->ios[0] += dus->s.ios[0]; | |
1009 | agg->ios[1] += dus->s.ios[1]; | |
1010 | agg->merges[0] += dus->s.merges[0]; | |
1011 | agg->merges[1] += dus->s.merges[1]; | |
1012 | agg->sectors[0] += dus->s.sectors[0]; | |
1013 | agg->sectors[1] += dus->s.sectors[1]; | |
1014 | agg->ticks[0] += dus->s.ticks[0]; | |
1015 | agg->ticks[1] += dus->s.ticks[1]; | |
1016 | agg->time_in_queue += dus->s.time_in_queue; | |
1017 | agg->slavecount++; | |
1018 | ||
1019 | util = (double) (100 * dus->s.io_ticks / (double) slavedu->dus.s.msec); | |
1020 | /* System utilization is the utilization of the | |
1021 | * component with the highest utilization. | |
1022 | */ | |
1023 | if (util > agg->max_util.u.f) | |
1024 | agg->max_util.u.f = util; | |
1025 | ||
1026 | } | |
1027 | ||
1028 | if (agg->max_util.u.f > 100.0) | |
1029 | agg->max_util.u.f = 100.0; | |
1030 | } | |
1031 | ||
1032 | void print_disk_util(struct disk_util_stat *dus, struct disk_util_agg *agg, | |
1033 | int terse, struct buf_output *out) | |
1034 | { | |
1035 | double util = 0; | |
1036 | ||
1037 | if (dus->s.msec) | |
1038 | util = (double) 100 * dus->s.io_ticks / (double) dus->s.msec; | |
1039 | if (util > 100.0) | |
1040 | util = 100.0; | |
1041 | ||
1042 | if (!terse) { | |
1043 | if (agg->slavecount) | |
1044 | log_buf(out, " "); | |
1045 | ||
75cbc26d BVA |
1046 | log_buf(out, " %s: ios=%llu/%llu, sectors=%llu/%llu, " |
1047 | "merge=%llu/%llu, ticks=%llu/%llu, in_queue=%llu, " | |
1048 | "util=%3.2f%%", | |
2a2fdab1 L |
1049 | dus->name, |
1050 | (unsigned long long) dus->s.ios[0], | |
1051 | (unsigned long long) dus->s.ios[1], | |
75cbc26d BVA |
1052 | (unsigned long long) dus->s.sectors[0], |
1053 | (unsigned long long) dus->s.sectors[1], | |
2a2fdab1 L |
1054 | (unsigned long long) dus->s.merges[0], |
1055 | (unsigned long long) dus->s.merges[1], | |
1056 | (unsigned long long) dus->s.ticks[0], | |
1057 | (unsigned long long) dus->s.ticks[1], | |
1058 | (unsigned long long) dus->s.time_in_queue, | |
1059 | util); | |
1060 | } else { | |
1061 | log_buf(out, ";%s;%llu;%llu;%llu;%llu;%llu;%llu;%llu;%3.2f%%", | |
1062 | dus->name, | |
1063 | (unsigned long long) dus->s.ios[0], | |
1064 | (unsigned long long) dus->s.ios[1], | |
1065 | (unsigned long long) dus->s.merges[0], | |
1066 | (unsigned long long) dus->s.merges[1], | |
1067 | (unsigned long long) dus->s.ticks[0], | |
1068 | (unsigned long long) dus->s.ticks[1], | |
1069 | (unsigned long long) dus->s.time_in_queue, | |
1070 | util); | |
1071 | } | |
1072 | ||
1073 | /* | |
1074 | * If the device has slaves, aggregate the stats for | |
1075 | * those slave devices also. | |
1076 | */ | |
1077 | show_agg_stats(agg, terse, out); | |
1078 | ||
1079 | if (!terse) | |
1080 | log_buf(out, "\n"); | |
1081 | } | |
1082 | ||
1083 | void json_array_add_disk_util(struct disk_util_stat *dus, | |
1084 | struct disk_util_agg *agg, struct json_array *array) | |
1085 | { | |
1086 | struct json_object *obj; | |
1087 | double util = 0; | |
1088 | ||
1089 | if (dus->s.msec) | |
1090 | util = (double) 100 * dus->s.io_ticks / (double) dus->s.msec; | |
1091 | if (util > 100.0) | |
1092 | util = 100.0; | |
1093 | ||
1094 | obj = json_create_object(); | |
1095 | json_array_add_value_object(array, obj); | |
1096 | ||
eb2f29b7 | 1097 | json_object_add_value_string(obj, "name", (const char *)dus->name); |
2a2fdab1 L |
1098 | json_object_add_value_int(obj, "read_ios", dus->s.ios[0]); |
1099 | json_object_add_value_int(obj, "write_ios", dus->s.ios[1]); | |
fc250131 VF |
1100 | json_object_add_value_int(obj, "read_sectors", dus->s.sectors[0]); |
1101 | json_object_add_value_int(obj, "write_sectors", dus->s.sectors[1]); | |
2a2fdab1 L |
1102 | json_object_add_value_int(obj, "read_merges", dus->s.merges[0]); |
1103 | json_object_add_value_int(obj, "write_merges", dus->s.merges[1]); | |
1104 | json_object_add_value_int(obj, "read_ticks", dus->s.ticks[0]); | |
1105 | json_object_add_value_int(obj, "write_ticks", dus->s.ticks[1]); | |
1106 | json_object_add_value_int(obj, "in_queue", dus->s.time_in_queue); | |
1107 | json_object_add_value_float(obj, "util", util); | |
1108 | ||
1109 | /* | |
1110 | * If the device has slaves, aggregate the stats for | |
1111 | * those slave devices also. | |
1112 | */ | |
1113 | if (!agg->slavecount) | |
1114 | return; | |
1115 | json_object_add_value_int(obj, "aggr_read_ios", | |
1116 | agg->ios[0] / agg->slavecount); | |
1117 | json_object_add_value_int(obj, "aggr_write_ios", | |
1118 | agg->ios[1] / agg->slavecount); | |
fc250131 VF |
1119 | json_object_add_value_int(obj, "aggr_read_sectors", |
1120 | agg->sectors[0] / agg->slavecount); | |
1121 | json_object_add_value_int(obj, "aggr_write_sectors", | |
1122 | agg->sectors[1] / agg->slavecount); | |
2a2fdab1 L |
1123 | json_object_add_value_int(obj, "aggr_read_merges", |
1124 | agg->merges[0] / agg->slavecount); | |
1125 | json_object_add_value_int(obj, "aggr_write_merge", | |
1126 | agg->merges[1] / agg->slavecount); | |
1127 | json_object_add_value_int(obj, "aggr_read_ticks", | |
1128 | agg->ticks[0] / agg->slavecount); | |
1129 | json_object_add_value_int(obj, "aggr_write_ticks", | |
1130 | agg->ticks[1] / agg->slavecount); | |
1131 | json_object_add_value_int(obj, "aggr_in_queue", | |
1132 | agg->time_in_queue / agg->slavecount); | |
1133 | json_object_add_value_float(obj, "aggr_util", agg->max_util.u.f); | |
1134 | } | |
1135 | ||
1136 | static void json_object_add_disk_utils(struct json_object *obj, | |
1137 | struct flist_head *head) | |
1138 | { | |
1139 | struct json_array *array = json_create_array(); | |
1140 | struct flist_head *entry; | |
1141 | struct disk_util *du; | |
1142 | ||
1143 | json_object_add_value_array(obj, "disk_util", array); | |
1144 | ||
1145 | flist_for_each(entry, head) { | |
1146 | du = flist_entry(entry, struct disk_util, list); | |
1147 | ||
1148 | aggregate_slaves_stats(du); | |
1149 | json_array_add_disk_util(&du->dus, &du->agg, array); | |
1150 | } | |
1151 | } | |
1152 | ||
1153 | void show_disk_util(int terse, struct json_object *parent, | |
1154 | struct buf_output *out) | |
1155 | { | |
1156 | struct flist_head *entry; | |
1157 | struct disk_util *du; | |
1158 | bool do_json; | |
1159 | ||
1160 | if (!is_running_backend()) | |
1161 | return; | |
1162 | ||
6dc75062 | 1163 | if (flist_empty(&disk_list)) |
2a2fdab1 | 1164 | return; |
2a2fdab1 L |
1165 | |
1166 | if ((output_format & FIO_OUTPUT_JSON) && parent) | |
1167 | do_json = true; | |
1168 | else | |
1169 | do_json = false; | |
1170 | ||
1171 | if (!terse && !do_json) | |
1172 | log_buf(out, "\nDisk stats (read/write):\n"); | |
1173 | ||
6dc75062 | 1174 | if (do_json) { |
2a2fdab1 | 1175 | json_object_add_disk_utils(parent, &disk_list); |
6dc75062 | 1176 | } else if (output_format & ~(FIO_OUTPUT_JSON | FIO_OUTPUT_JSON_PLUS)) { |
2a2fdab1 L |
1177 | flist_for_each(entry, &disk_list) { |
1178 | du = flist_entry(entry, struct disk_util, list); | |
1179 | ||
1180 | aggregate_slaves_stats(du); | |
1181 | print_disk_util(&du->dus, &du->agg, terse, out); | |
1182 | } | |
1183 | } | |
1184 | } | |
1185 | ||
10aa136b | 1186 | static void show_thread_status_normal(struct thread_stat *ts, |
a666cab8 JA |
1187 | struct group_run_stats *rs, |
1188 | struct buf_output *out) | |
3c39a379 JA |
1189 | { |
1190 | double usr_cpu, sys_cpu; | |
69008999 | 1191 | unsigned long runtime; |
71619dc2 | 1192 | double io_u_dist[FIO_IO_U_MAP_NR]; |
57a64324 | 1193 | time_t time_p; |
35326842 | 1194 | char time_buf[32]; |
3c39a379 | 1195 | |
9966af7b | 1196 | if (!ddir_rw_sum(ts->io_bytes) && !ddir_rw_sum(ts->total_io_u)) |
3c39a379 | 1197 | return; |
7a4e480d | 1198 | |
33477b4b | 1199 | memset(time_buf, 0, sizeof(time_buf)); |
3c39a379 | 1200 | |
57a64324 | 1201 | time(&time_p); |
45054cbe | 1202 | os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf)); |
57a64324 | 1203 | |
5ec10eaa | 1204 | if (!ts->error) { |
a666cab8 | 1205 | log_buf(out, "%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s", |
5ec10eaa | 1206 | ts->name, ts->groupid, ts->members, |
57a64324 | 1207 | ts->error, (int) ts->pid, time_buf); |
5ec10eaa | 1208 | } else { |
a666cab8 | 1209 | log_buf(out, "%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s", |
5ec10eaa | 1210 | ts->name, ts->groupid, ts->members, |
57a64324 JA |
1211 | ts->error, ts->verror, (int) ts->pid, |
1212 | time_buf); | |
5ec10eaa | 1213 | } |
3c39a379 | 1214 | |
259e47de | 1215 | if (strlen(ts->description)) |
a666cab8 | 1216 | log_buf(out, " Description : [%s]\n", ts->description); |
7bdce1bd | 1217 | |
dde39f8c AD |
1218 | for_each_rw_ddir(ddir) { |
1219 | if (ts->io_bytes[ddir]) | |
1220 | show_ddir_status(rs, ts, ddir, out); | |
1221 | } | |
3c39a379 | 1222 | |
5cb8a8cd BP |
1223 | if (ts->unified_rw_rep == UNIFIED_BOTH) |
1224 | show_mixed_ddir_status(rs, ts, out); | |
1225 | ||
a666cab8 | 1226 | show_latencies(ts, out); |
7e1773ba | 1227 | |
b2b3eefe JA |
1228 | if (ts->sync_stat.samples) |
1229 | show_ddir_status(rs, ts, DDIR_SYNC, out); | |
1230 | ||
756867bd | 1231 | runtime = ts->total_run_time; |
69008999 | 1232 | if (runtime) { |
1e97cce9 | 1233 | double runt = (double) runtime; |
3c39a379 | 1234 | |
756867bd JA |
1235 | usr_cpu = (double) ts->usr_time * 100 / runt; |
1236 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
3c39a379 JA |
1237 | } else { |
1238 | usr_cpu = 0; | |
1239 | sys_cpu = 0; | |
1240 | } | |
1241 | ||
a666cab8 | 1242 | log_buf(out, " cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%llu," |
4e0a8fa2 JA |
1243 | " majf=%llu, minf=%llu\n", usr_cpu, sys_cpu, |
1244 | (unsigned long long) ts->ctx, | |
1245 | (unsigned long long) ts->majf, | |
1246 | (unsigned long long) ts->minf); | |
71619dc2 | 1247 | |
d79db122 | 1248 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); |
a666cab8 | 1249 | log_buf(out, " IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%," |
5ec10eaa JA |
1250 | " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], |
1251 | io_u_dist[1], io_u_dist[2], | |
1252 | io_u_dist[3], io_u_dist[4], | |
1253 | io_u_dist[5], io_u_dist[6]); | |
838bc709 JA |
1254 | |
1255 | stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist); | |
a666cab8 | 1256 | log_buf(out, " submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," |
838bc709 JA |
1257 | " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], |
1258 | io_u_dist[1], io_u_dist[2], | |
1259 | io_u_dist[3], io_u_dist[4], | |
1260 | io_u_dist[5], io_u_dist[6]); | |
1261 | stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist); | |
a666cab8 | 1262 | log_buf(out, " complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," |
838bc709 JA |
1263 | " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], |
1264 | io_u_dist[1], io_u_dist[2], | |
1265 | io_u_dist[3], io_u_dist[4], | |
1266 | io_u_dist[5], io_u_dist[6]); | |
7f3ecee2 JA |
1267 | log_buf(out, " issued rwts: total=%llu,%llu,%llu,%llu" |
1268 | " short=%llu,%llu,%llu,0" | |
1269 | " dropped=%llu,%llu,%llu,0\n", | |
4e0a8fa2 JA |
1270 | (unsigned long long) ts->total_io_u[0], |
1271 | (unsigned long long) ts->total_io_u[1], | |
1272 | (unsigned long long) ts->total_io_u[2], | |
7f3ecee2 | 1273 | (unsigned long long) ts->total_io_u[3], |
4e0a8fa2 JA |
1274 | (unsigned long long) ts->short_io_u[0], |
1275 | (unsigned long long) ts->short_io_u[1], | |
3bcb9d94 JA |
1276 | (unsigned long long) ts->short_io_u[2], |
1277 | (unsigned long long) ts->drop_io_u[0], | |
1278 | (unsigned long long) ts->drop_io_u[1], | |
1279 | (unsigned long long) ts->drop_io_u[2]); | |
f2bba182 | 1280 | if (ts->continue_on_error) { |
a666cab8 | 1281 | log_buf(out, " errors : total=%llu, first_error=%d/<%s>\n", |
4e0a8fa2 | 1282 | (unsigned long long)ts->total_err_count, |
1ec99eea JA |
1283 | ts->first_error, |
1284 | strerror(ts->first_error)); | |
f2bba182 | 1285 | } |
3e260a46 | 1286 | if (ts->latency_depth) { |
a666cab8 | 1287 | log_buf(out, " latency : target=%llu, window=%llu, percentile=%.2f%%, depth=%u\n", |
3e260a46 JA |
1288 | (unsigned long long)ts->latency_target, |
1289 | (unsigned long long)ts->latency_window, | |
1290 | ts->latency_percentile.u.f, | |
1291 | ts->latency_depth); | |
1292 | } | |
66347cfa DE |
1293 | |
1294 | if (ts->nr_block_infos) | |
1295 | show_block_infos(ts->nr_block_infos, ts->block_infos, | |
a666cab8 | 1296 | ts->percentile_list, out); |
d685adfb | 1297 | |
bb49c8bd | 1298 | if (ts->ss_dur) |
d685adfb | 1299 | show_ss_normal(ts, out); |
3c39a379 JA |
1300 | } |
1301 | ||
756867bd | 1302 | static void show_ddir_status_terse(struct thread_stat *ts, |
2e545522 NC |
1303 | struct group_run_stats *rs, |
1304 | enum fio_ddir ddir, int ver, | |
1305 | struct buf_output *out) | |
c6ae0a5b | 1306 | { |
d6bb626e VF |
1307 | unsigned long long min, max, minv, maxv, bw, iops; |
1308 | unsigned long long *ovals = NULL; | |
c6ae0a5b | 1309 | double mean, dev; |
d6bb626e | 1310 | unsigned int len; |
a2c95580 | 1311 | int i, bw_stat; |
c6ae0a5b | 1312 | |
ff58fced JA |
1313 | assert(ddir_rw(ddir)); |
1314 | ||
312b4af2 JA |
1315 | iops = bw = 0; |
1316 | if (ts->runtime[ddir]) { | |
1317 | uint64_t runt = ts->runtime[ddir]; | |
1318 | ||
420b104a | 1319 | bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024; /* KiB/s */ |
312b4af2 JA |
1320 | iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt; |
1321 | } | |
c6ae0a5b | 1322 | |
a666cab8 | 1323 | log_buf(out, ";%llu;%llu;%llu;%llu", |
4e0a8fa2 JA |
1324 | (unsigned long long) ts->io_bytes[ddir] >> 10, bw, iops, |
1325 | (unsigned long long) ts->runtime[ddir]); | |
c6ae0a5b | 1326 | |
079ad09b | 1327 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
247823cc | 1328 | log_buf(out, ";%llu;%llu;%f;%f", min/1000, max/1000, mean/1000, dev/1000); |
c6ae0a5b | 1329 | else |
d6bb626e | 1330 | log_buf(out, ";%llu;%llu;%f;%f", 0ULL, 0ULL, 0.0, 0.0); |
c6ae0a5b | 1331 | |
079ad09b | 1332 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) |
247823cc | 1333 | log_buf(out, ";%llu;%llu;%f;%f", min/1000, max/1000, mean/1000, dev/1000); |
c6ae0a5b | 1334 | else |
d6bb626e | 1335 | log_buf(out, ";%llu;%llu;%f;%f", 0ULL, 0ULL, 0.0, 0.0); |
c6ae0a5b | 1336 | |
6dc75062 | 1337 | if (ts->lat_percentiles) { |
56440e63 VF |
1338 | len = calc_clat_percentiles(ts->io_u_plat[FIO_LAT][ddir], |
1339 | ts->lat_stat[ddir].samples, | |
1340 | ts->percentile_list, &ovals, &maxv, | |
1341 | &minv); | |
6dc75062 | 1342 | } else if (ts->clat_percentiles) { |
df8781b6 | 1343 | len = calc_clat_percentiles(ts->io_u_plat[FIO_CLAT][ddir], |
1db92cb6 JA |
1344 | ts->clat_stat[ddir].samples, |
1345 | ts->percentile_list, &ovals, &maxv, | |
1346 | &minv); | |
6dc75062 | 1347 | } else { |
1db92cb6 | 1348 | len = 0; |
6dc75062 JA |
1349 | } |
1350 | ||
1db92cb6 JA |
1351 | for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { |
1352 | if (i >= len) { | |
a666cab8 | 1353 | log_buf(out, ";0%%=0"); |
1db92cb6 JA |
1354 | continue; |
1355 | } | |
247823cc | 1356 | log_buf(out, ";%f%%=%llu", ts->percentile_list[i].u.f, ovals[i]/1000); |
1db92cb6 | 1357 | } |
2341a37a K |
1358 | |
1359 | if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) | |
247823cc | 1360 | log_buf(out, ";%llu;%llu;%f;%f", min/1000, max/1000, mean/1000, dev/1000); |
2341a37a | 1361 | else |
d6bb626e | 1362 | log_buf(out, ";%llu;%llu;%f;%f", 0ULL, 0ULL, 0.0, 0.0); |
2341a37a | 1363 | |
283feb79 | 1364 | free(ovals); |
1db92cb6 | 1365 | |
a2c95580 AH |
1366 | bw_stat = calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev); |
1367 | if (bw_stat) { | |
19d3e967 JA |
1368 | double p_of_agg = 100.0; |
1369 | ||
1370 | if (rs->agg[ddir]) { | |
d1707474 | 1371 | p_of_agg = mean * 100 / (double) (rs->agg[ddir] / 1024); |
19d3e967 JA |
1372 | if (p_of_agg > 100.0) |
1373 | p_of_agg = 100.0; | |
1374 | } | |
c6ae0a5b | 1375 | |
d6bb626e | 1376 | log_buf(out, ";%llu;%llu;%f%%;%f;%f", min, max, p_of_agg, mean, dev); |
6dc75062 | 1377 | } else { |
d6bb626e | 1378 | log_buf(out, ";%llu;%llu;%f%%;%f;%f", 0ULL, 0ULL, 0.0, 0.0, 0.0); |
6dc75062 | 1379 | } |
a2c95580 AH |
1380 | |
1381 | if (ver == 5) { | |
1382 | if (bw_stat) | |
29eb371b | 1383 | log_buf(out, ";%" PRIu64, (&ts->bw_stat[ddir])->samples); |
a2c95580 AH |
1384 | else |
1385 | log_buf(out, ";%lu", 0UL); | |
1386 | ||
1387 | if (calc_lat(&ts->iops_stat[ddir], &min, &max, &mean, &dev)) | |
29eb371b | 1388 | log_buf(out, ";%llu;%llu;%f;%f;%" PRIu64, min, max, |
a2c95580 AH |
1389 | mean, dev, (&ts->iops_stat[ddir])->samples); |
1390 | else | |
1391 | log_buf(out, ";%llu;%llu;%f;%f;%lu", 0ULL, 0ULL, 0.0, 0.0, 0UL); | |
1392 | } | |
c6ae0a5b JA |
1393 | } |
1394 | ||
5cb8a8cd BP |
1395 | static void show_mixed_ddir_status_terse(struct thread_stat *ts, |
1396 | struct group_run_stats *rs, | |
1397 | int ver, struct buf_output *out) | |
1398 | { | |
b182f077 | 1399 | struct thread_stat *ts_lcl = gen_mixed_ddir_stats_from_ts(ts); |
5cb8a8cd | 1400 | |
b182f077 NC |
1401 | if (ts_lcl) |
1402 | show_ddir_status_terse(ts_lcl, rs, DDIR_READ, ver, out); | |
5cb8a8cd | 1403 | |
692dec0c | 1404 | free_clat_prio_stats(ts_lcl); |
5cb8a8cd BP |
1405 | free(ts_lcl); |
1406 | } | |
1407 | ||
6dc75062 JA |
1408 | static struct json_object *add_ddir_lat_json(struct thread_stat *ts, |
1409 | uint32_t percentiles, | |
1410 | struct io_stat *lat_stat, | |
1411 | uint64_t *io_u_plat) | |
56440e63 VF |
1412 | { |
1413 | char buf[120]; | |
1414 | double mean, dev; | |
1415 | unsigned int i, len; | |
1416 | struct json_object *lat_object, *percentile_object, *clat_bins_object; | |
1417 | unsigned long long min, max, maxv, minv, *ovals = NULL; | |
1418 | ||
1419 | if (!calc_lat(lat_stat, &min, &max, &mean, &dev)) { | |
1420 | min = max = 0; | |
1421 | mean = dev = 0.0; | |
1422 | } | |
1423 | lat_object = json_create_object(); | |
1424 | json_object_add_value_int(lat_object, "min", min); | |
1425 | json_object_add_value_int(lat_object, "max", max); | |
1426 | json_object_add_value_float(lat_object, "mean", mean); | |
1427 | json_object_add_value_float(lat_object, "stddev", dev); | |
1428 | json_object_add_value_int(lat_object, "N", lat_stat->samples); | |
1429 | ||
1430 | if (percentiles && lat_stat->samples) { | |
1431 | len = calc_clat_percentiles(io_u_plat, lat_stat->samples, | |
1432 | ts->percentile_list, &ovals, &maxv, &minv); | |
1433 | ||
1434 | if (len > FIO_IO_U_LIST_MAX_LEN) | |
1435 | len = FIO_IO_U_LIST_MAX_LEN; | |
1436 | ||
1437 | percentile_object = json_create_object(); | |
1438 | json_object_add_value_object(lat_object, "percentile", percentile_object); | |
1439 | for (i = 0; i < len; i++) { | |
1440 | snprintf(buf, sizeof(buf), "%f", ts->percentile_list[i].u.f); | |
1441 | json_object_add_value_int(percentile_object, buf, ovals[i]); | |
1442 | } | |
1443 | free(ovals); | |
1444 | ||
1445 | if (output_format & FIO_OUTPUT_JSON_PLUS) { | |
1446 | clat_bins_object = json_create_object(); | |
1447 | json_object_add_value_object(lat_object, "bins", clat_bins_object); | |
1448 | ||
1449 | for(i = 0; i < FIO_IO_U_PLAT_NR; i++) | |
1450 | if (io_u_plat[i]) { | |
1451 | snprintf(buf, sizeof(buf), "%llu", plat_idx_to_val(i)); | |
1452 | json_object_add_value_int(clat_bins_object, buf, io_u_plat[i]); | |
1453 | } | |
1454 | } | |
1455 | } | |
1456 | ||
1457 | return lat_object; | |
1458 | } | |
1459 | ||
cc372b17 | 1460 | static void add_ddir_status_json(struct thread_stat *ts, |
2e545522 NC |
1461 | struct group_run_stats *rs, enum fio_ddir ddir, |
1462 | struct json_object *parent) | |
cc372b17 | 1463 | { |
56440e63 | 1464 | unsigned long long min, max; |
aedd021d | 1465 | unsigned long long bw_bytes, bw; |
9f68fe3a | 1466 | double mean, dev, iops; |
56440e63 | 1467 | struct json_object *dir_object, *tmp_object; |
cc372b17 SL |
1468 | double p_of_agg = 100.0; |
1469 | ||
b2b3eefe | 1470 | assert(ddir_rw(ddir) || ddir_sync(ddir)); |
cc372b17 | 1471 | |
5cb8a8cd | 1472 | if ((ts->unified_rw_rep == UNIFIED_MIXED) && ddir != DDIR_READ) |
771e58be JA |
1473 | return; |
1474 | ||
cc372b17 | 1475 | dir_object = json_create_object(); |
771e58be | 1476 | json_object_add_value_object(parent, |
5cb8a8cd | 1477 | (ts->unified_rw_rep == UNIFIED_MIXED) ? "mixed" : io_ddir_name(ddir), dir_object); |
cc372b17 | 1478 | |
b2b3eefe JA |
1479 | if (ddir_rw(ddir)) { |
1480 | bw_bytes = 0; | |
1481 | bw = 0; | |
1482 | iops = 0.0; | |
1483 | if (ts->runtime[ddir]) { | |
1484 | uint64_t runt = ts->runtime[ddir]; | |
cc372b17 | 1485 | |
b2b3eefe JA |
1486 | bw_bytes = ((1000 * ts->io_bytes[ddir]) / runt); /* Bytes/s */ |
1487 | bw = bw_bytes / 1024; /* KiB/s */ | |
1488 | iops = (1000.0 * (uint64_t) ts->total_io_u[ddir]) / runt; | |
1489 | } | |
cc372b17 | 1490 | |
b2b3eefe JA |
1491 | json_object_add_value_int(dir_object, "io_bytes", ts->io_bytes[ddir]); |
1492 | json_object_add_value_int(dir_object, "io_kbytes", ts->io_bytes[ddir] >> 10); | |
1493 | json_object_add_value_int(dir_object, "bw_bytes", bw_bytes); | |
1494 | json_object_add_value_int(dir_object, "bw", bw); | |
1495 | json_object_add_value_float(dir_object, "iops", iops); | |
1496 | json_object_add_value_int(dir_object, "runtime", ts->runtime[ddir]); | |
1497 | json_object_add_value_int(dir_object, "total_ios", ts->total_io_u[ddir]); | |
1498 | json_object_add_value_int(dir_object, "short_ios", ts->short_io_u[ddir]); | |
1499 | json_object_add_value_int(dir_object, "drop_ios", ts->drop_io_u[ddir]); | |
1500 | ||
56440e63 VF |
1501 | tmp_object = add_ddir_lat_json(ts, ts->slat_percentiles, |
1502 | &ts->slat_stat[ddir], ts->io_u_plat[FIO_SLAT][ddir]); | |
b2b3eefe | 1503 | json_object_add_value_object(dir_object, "slat_ns", tmp_object); |
56440e63 VF |
1504 | |
1505 | tmp_object = add_ddir_lat_json(ts, ts->clat_percentiles, | |
1506 | &ts->clat_stat[ddir], ts->io_u_plat[FIO_CLAT][ddir]); | |
b2b3eefe | 1507 | json_object_add_value_object(dir_object, "clat_ns", tmp_object); |
cc372b17 | 1508 | |
56440e63 VF |
1509 | tmp_object = add_ddir_lat_json(ts, ts->lat_percentiles, |
1510 | &ts->lat_stat[ddir], ts->io_u_plat[FIO_LAT][ddir]); | |
b2b3eefe | 1511 | json_object_add_value_object(dir_object, "lat_ns", tmp_object); |
56440e63 | 1512 | } else { |
f5ec8123 | 1513 | json_object_add_value_int(dir_object, "total_ios", ts->total_io_u[DDIR_SYNC]); |
56440e63 VF |
1514 | tmp_object = add_ddir_lat_json(ts, ts->lat_percentiles | ts->clat_percentiles, |
1515 | &ts->sync_stat, ts->io_u_sync_plat); | |
1516 | json_object_add_value_object(dir_object, "lat_ns", tmp_object); | |
513e37ee VF |
1517 | } |
1518 | ||
56440e63 VF |
1519 | if (!ddir_rw(ddir)) |
1520 | return; | |
b2a432bf | 1521 | |
1cbbba65 NC |
1522 | /* Only include per prio stats if there are >= 2 prios with samples */ |
1523 | if (get_nr_prios_with_samples(ts, ddir) >= 2) { | |
1524 | struct json_array *array = json_create_array(); | |
1525 | const char *obj_name; | |
1526 | int i; | |
1527 | ||
1528 | if (ts->lat_percentiles) | |
1529 | obj_name = "lat_ns"; | |
1530 | else | |
1531 | obj_name = "clat_ns"; | |
b2a432bf | 1532 | |
1cbbba65 | 1533 | json_object_add_value_array(dir_object, "prios", array); |
b2b3eefe | 1534 | |
1cbbba65 | 1535 | for (i = 0; i < ts->nr_clat_prio[ddir]; i++) { |
a967e54d DLM |
1536 | struct json_object *obj; |
1537 | ||
1538 | if (!ts->clat_prio[ddir][i].clat_stat.samples) | |
1539 | continue; | |
1540 | ||
1541 | obj = json_create_object(); | |
1542 | ||
1543 | json_object_add_value_int(obj, "prioclass", | |
1544 | ioprio_class(ts->clat_prio[ddir][i].ioprio)); | |
1545 | json_object_add_value_int(obj, "prio", | |
1546 | ioprio(ts->clat_prio[ddir][i].ioprio)); | |
219a8682 DLM |
1547 | json_object_add_value_int(obj, "priohint", |
1548 | ioprio_hint(ts->clat_prio[ddir][i].ioprio)); | |
a967e54d DLM |
1549 | |
1550 | tmp_object = add_ddir_lat_json(ts, | |
1551 | ts->clat_percentiles | ts->lat_percentiles, | |
1552 | &ts->clat_prio[ddir][i].clat_stat, | |
1553 | ts->clat_prio[ddir][i].io_u_plat); | |
1554 | json_object_add_value_object(obj, obj_name, tmp_object); | |
1555 | json_array_add_value_object(array, obj); | |
1cbbba65 | 1556 | } |
cc372b17 | 1557 | } |
24cab44e | 1558 | |
b9e1b491 | 1559 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
5c0abd5e | 1560 | p_of_agg = convert_agg_kbytes_percent(rs, ddir, mean); |
cc372b17 SL |
1561 | } else { |
1562 | min = max = 0; | |
1563 | p_of_agg = mean = dev = 0.0; | |
1564 | } | |
56440e63 | 1565 | |
cc372b17 SL |
1566 | json_object_add_value_int(dir_object, "bw_min", min); |
1567 | json_object_add_value_int(dir_object, "bw_max", max); | |
a806bf2e | 1568 | json_object_add_value_float(dir_object, "bw_agg", p_of_agg); |
cc372b17 SL |
1569 | json_object_add_value_float(dir_object, "bw_mean", mean); |
1570 | json_object_add_value_float(dir_object, "bw_dev", dev); | |
54c05828 AH |
1571 | json_object_add_value_int(dir_object, "bw_samples", |
1572 | (&ts->bw_stat[ddir])->samples); | |
188b6016 AH |
1573 | |
1574 | if (!calc_lat(&ts->iops_stat[ddir], &min, &max, &mean, &dev)) { | |
1575 | min = max = 0; | |
1576 | mean = dev = 0.0; | |
1577 | } | |
1578 | json_object_add_value_int(dir_object, "iops_min", min); | |
1579 | json_object_add_value_int(dir_object, "iops_max", max); | |
1580 | json_object_add_value_float(dir_object, "iops_mean", mean); | |
1581 | json_object_add_value_float(dir_object, "iops_stddev", dev); | |
54c05828 AH |
1582 | json_object_add_value_int(dir_object, "iops_samples", |
1583 | (&ts->iops_stat[ddir])->samples); | |
96563db9 JA |
1584 | |
1585 | if (ts->cachehit + ts->cachemiss) { | |
1586 | uint64_t total; | |
1587 | double hit; | |
1588 | ||
1589 | total = ts->cachehit + ts->cachemiss; | |
1590 | hit = (double) ts->cachehit / (double) total; | |
1591 | hit *= 100.0; | |
1592 | json_object_add_value_float(dir_object, "cachehit", hit); | |
1593 | } | |
cc372b17 SL |
1594 | } |
1595 | ||
5cb8a8cd BP |
1596 | static void add_mixed_ddir_status_json(struct thread_stat *ts, |
1597 | struct group_run_stats *rs, struct json_object *parent) | |
1598 | { | |
b182f077 | 1599 | struct thread_stat *ts_lcl = gen_mixed_ddir_stats_from_ts(ts); |
5cb8a8cd BP |
1600 | |
1601 | /* add the aggregated stats to json parent */ | |
b182f077 NC |
1602 | if (ts_lcl) |
1603 | add_ddir_status_json(ts_lcl, rs, DDIR_READ, parent); | |
1604 | ||
692dec0c | 1605 | free_clat_prio_stats(ts_lcl); |
5cb8a8cd BP |
1606 | free(ts_lcl); |
1607 | } | |
1608 | ||
bef2112b AH |
1609 | static void show_thread_status_terse_all(struct thread_stat *ts, |
1610 | struct group_run_stats *rs, int ver, | |
1611 | struct buf_output *out) | |
4d658652 JA |
1612 | { |
1613 | double io_u_dist[FIO_IO_U_MAP_NR]; | |
1614 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; | |
1615 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
1616 | double usr_cpu, sys_cpu; | |
1617 | int i; | |
1618 | ||
1619 | /* General Info */ | |
bef2112b AH |
1620 | if (ver == 2) |
1621 | log_buf(out, "2;%s;%d;%d", ts->name, ts->groupid, ts->error); | |
1622 | else | |
1623 | log_buf(out, "%d;%s;%s;%d;%d", ver, fio_version_string, | |
1624 | ts->name, ts->groupid, ts->error); | |
c6ae0a5b | 1625 | |
5cb8a8cd | 1626 | /* Log Read Status, or mixed if unified_rw_rep = 1 */ |
a2c95580 | 1627 | show_ddir_status_terse(ts, rs, DDIR_READ, ver, out); |
5cb8a8cd BP |
1628 | if (ts->unified_rw_rep != UNIFIED_MIXED) { |
1629 | /* Log Write Status */ | |
1630 | show_ddir_status_terse(ts, rs, DDIR_WRITE, ver, out); | |
1631 | /* Log Trim Status */ | |
1632 | if (ver == 2 || ver == 4 || ver == 5) | |
1633 | show_ddir_status_terse(ts, rs, DDIR_TRIM, ver, out); | |
1634 | } | |
1635 | if (ts->unified_rw_rep == UNIFIED_BOTH) | |
1636 | show_mixed_ddir_status_terse(ts, rs, ver, out); | |
562c2d2f | 1637 | /* CPU Usage */ |
756867bd JA |
1638 | if (ts->total_run_time) { |
1639 | double runt = (double) ts->total_run_time; | |
c6ae0a5b | 1640 | |
756867bd JA |
1641 | usr_cpu = (double) ts->usr_time * 100 / runt; |
1642 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
c6ae0a5b JA |
1643 | } else { |
1644 | usr_cpu = 0; | |
1645 | sys_cpu = 0; | |
1646 | } | |
1647 | ||
a666cab8 | 1648 | log_buf(out, ";%f%%;%f%%;%llu;%llu;%llu", usr_cpu, sys_cpu, |
4e0a8fa2 JA |
1649 | (unsigned long long) ts->ctx, |
1650 | (unsigned long long) ts->majf, | |
1651 | (unsigned long long) ts->minf); | |
2270890c | 1652 | |
562c2d2f | 1653 | /* Calc % distribution of IO depths, usecond, msecond latency */ |
d79db122 | 1654 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); |
247823cc | 1655 | stat_calc_lat_nu(ts, io_u_lat_u); |
04a0feae | 1656 | stat_calc_lat_m(ts, io_u_lat_m); |
2270890c | 1657 | |
562c2d2f | 1658 | /* Only show fixed 7 I/O depth levels*/ |
a666cab8 | 1659 | log_buf(out, ";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", |
5ec10eaa JA |
1660 | io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], |
1661 | io_u_dist[4], io_u_dist[5], io_u_dist[6]); | |
2270890c | 1662 | |
562c2d2f | 1663 | /* Microsecond latency */ |
04a0feae | 1664 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) |
a666cab8 | 1665 | log_buf(out, ";%3.2f%%", io_u_lat_u[i]); |
562c2d2f | 1666 | /* Millisecond latency */ |
04a0feae | 1667 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) |
a666cab8 | 1668 | log_buf(out, ";%3.2f%%", io_u_lat_m[i]); |
f2f788dd JA |
1669 | |
1670 | /* disk util stats, if any */ | |
24a97130 | 1671 | if (ver >= 3 && is_running_backend()) |
bef2112b | 1672 | show_disk_util(1, NULL, out); |
f2f788dd | 1673 | |
562c2d2f | 1674 | /* Additional output if continue_on_error set - default off*/ |
f2bba182 | 1675 | if (ts->continue_on_error) |
a666cab8 | 1676 | log_buf(out, ";%llu;%d", (unsigned long long) ts->total_err_count, ts->first_error); |
2270890c | 1677 | |
562c2d2f | 1678 | /* Additional output if description is set */ |
d5495f0b VF |
1679 | if (strlen(ts->description)) { |
1680 | if (ver == 2) | |
1681 | log_buf(out, "\n"); | |
a666cab8 | 1682 | log_buf(out, ";%s", ts->description); |
d5495f0b | 1683 | } |
946e4276 | 1684 | |
a666cab8 | 1685 | log_buf(out, "\n"); |
756867bd JA |
1686 | } |
1687 | ||
a89ba4b1 | 1688 | static void json_add_job_opts(struct json_object *root, const char *name, |
0cf542af | 1689 | struct flist_head *opt_list) |
66e19a38 JA |
1690 | { |
1691 | struct json_object *dir_object; | |
1692 | struct flist_head *entry; | |
1693 | struct print_option *p; | |
1694 | ||
1695 | if (flist_empty(opt_list)) | |
1696 | return; | |
1697 | ||
1698 | dir_object = json_create_object(); | |
1699 | json_object_add_value_object(root, name, dir_object); | |
1700 | ||
1701 | flist_for_each(entry, opt_list) { | |
66e19a38 | 1702 | p = flist_entry(entry, struct print_option, list); |
c42b48fe | 1703 | json_object_add_value_string(dir_object, p->name, p->value); |
66e19a38 JA |
1704 | } |
1705 | } | |
1706 | ||
cc372b17 | 1707 | static struct json_object *show_thread_status_json(struct thread_stat *ts, |
66e19a38 JA |
1708 | struct group_run_stats *rs, |
1709 | struct flist_head *opt_list) | |
cc372b17 SL |
1710 | { |
1711 | struct json_object *root, *tmp; | |
b01af66b | 1712 | struct jobs_eta *je; |
cc372b17 | 1713 | double io_u_dist[FIO_IO_U_MAP_NR]; |
d6bb626e | 1714 | double io_u_lat_n[FIO_IO_U_LAT_N_NR]; |
cc372b17 SL |
1715 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
1716 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
1717 | double usr_cpu, sys_cpu; | |
1718 | int i; | |
b01af66b CJ |
1719 | size_t size; |
1720 | ||
cc372b17 SL |
1721 | root = json_create_object(); |
1722 | json_object_add_value_string(root, "jobname", ts->name); | |
1723 | json_object_add_value_int(root, "groupid", ts->groupid); | |
12d325ca | 1724 | json_object_add_value_int(root, "job_start", ts->job_start); |
cc372b17 SL |
1725 | json_object_add_value_int(root, "error", ts->error); |
1726 | ||
b01af66b | 1727 | /* ETA Info */ |
c5103619 | 1728 | je = get_jobs_eta(true, &size); |
2de615ad JA |
1729 | if (je) { |
1730 | json_object_add_value_int(root, "eta", je->eta_sec); | |
1731 | json_object_add_value_int(root, "elapsed", je->elapsed_sec); | |
0fc3cb4c | 1732 | free(je); |
2de615ad | 1733 | } |
b01af66b | 1734 | |
66e19a38 | 1735 | if (opt_list) |
0cf542af | 1736 | json_add_job_opts(root, "job options", opt_list); |
66e19a38 | 1737 | |
cc372b17 SL |
1738 | add_ddir_status_json(ts, rs, DDIR_READ, root); |
1739 | add_ddir_status_json(ts, rs, DDIR_WRITE, root); | |
f3afa57e | 1740 | add_ddir_status_json(ts, rs, DDIR_TRIM, root); |
b2b3eefe | 1741 | add_ddir_status_json(ts, rs, DDIR_SYNC, root); |
cc372b17 | 1742 | |
5cb8a8cd BP |
1743 | if (ts->unified_rw_rep == UNIFIED_BOTH) |
1744 | add_mixed_ddir_status_json(ts, rs, root); | |
1745 | ||
cc372b17 SL |
1746 | /* CPU Usage */ |
1747 | if (ts->total_run_time) { | |
1748 | double runt = (double) ts->total_run_time; | |
1749 | ||
1750 | usr_cpu = (double) ts->usr_time * 100 / runt; | |
1751 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
1752 | } else { | |
1753 | usr_cpu = 0; | |
1754 | sys_cpu = 0; | |
1755 | } | |
bcbb4c6c | 1756 | json_object_add_value_int(root, "job_runtime", ts->total_run_time); |
cc372b17 SL |
1757 | json_object_add_value_float(root, "usr_cpu", usr_cpu); |
1758 | json_object_add_value_float(root, "sys_cpu", sys_cpu); | |
1759 | json_object_add_value_int(root, "ctx", ts->ctx); | |
1760 | json_object_add_value_int(root, "majf", ts->majf); | |
1761 | json_object_add_value_int(root, "minf", ts->minf); | |
1762 | ||
ec3e3648 | 1763 | /* Calc % distribution of IO depths */ |
d79db122 | 1764 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); |
cc372b17 SL |
1765 | tmp = json_create_object(); |
1766 | json_object_add_value_object(root, "iodepth_level", tmp); | |
1767 | /* Only show fixed 7 I/O depth levels*/ | |
1768 | for (i = 0; i < 7; i++) { | |
1769 | char name[20]; | |
1770 | if (i < 6) | |
98ffb8f3 | 1771 | snprintf(name, 20, "%d", 1 << i); |
cc372b17 | 1772 | else |
98ffb8f3 | 1773 | snprintf(name, 20, ">=%d", 1 << i); |
cc372b17 SL |
1774 | json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]); |
1775 | } | |
1776 | ||
ec3e3648 VF |
1777 | /* Calc % distribution of submit IO depths */ |
1778 | stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist); | |
1779 | tmp = json_create_object(); | |
1780 | json_object_add_value_object(root, "iodepth_submit", tmp); | |
1781 | /* Only show fixed 7 I/O depth levels*/ | |
1782 | for (i = 0; i < 7; i++) { | |
1783 | char name[20]; | |
1784 | if (i == 0) | |
1785 | snprintf(name, 20, "0"); | |
1786 | else if (i < 6) | |
1787 | snprintf(name, 20, "%d", 1 << (i+1)); | |
1788 | else | |
1789 | snprintf(name, 20, ">=%d", 1 << i); | |
1790 | json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]); | |
1791 | } | |
1792 | ||
1793 | /* Calc % distribution of completion IO depths */ | |
1794 | stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist); | |
1795 | tmp = json_create_object(); | |
1796 | json_object_add_value_object(root, "iodepth_complete", tmp); | |
1797 | /* Only show fixed 7 I/O depth levels*/ | |
1798 | for (i = 0; i < 7; i++) { | |
1799 | char name[20]; | |
1800 | if (i == 0) | |
1801 | snprintf(name, 20, "0"); | |
1802 | else if (i < 6) | |
1803 | snprintf(name, 20, "%d", 1 << (i+1)); | |
1804 | else | |
1805 | snprintf(name, 20, ">=%d", 1 << i); | |
1806 | json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]); | |
1807 | } | |
1808 | ||
1809 | /* Calc % distribution of nsecond, usecond, msecond latency */ | |
1810 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); | |
1811 | stat_calc_lat_n(ts, io_u_lat_n); | |
1812 | stat_calc_lat_u(ts, io_u_lat_u); | |
1813 | stat_calc_lat_m(ts, io_u_lat_m); | |
1814 | ||
d6bb626e | 1815 | /* Nanosecond latency */ |
cc372b17 | 1816 | tmp = json_create_object(); |
d6bb626e VF |
1817 | json_object_add_value_object(root, "latency_ns", tmp); |
1818 | for (i = 0; i < FIO_IO_U_LAT_N_NR; i++) { | |
1819 | const char *ranges[] = { "2", "4", "10", "20", "50", "100", | |
1820 | "250", "500", "750", "1000", }; | |
1821 | json_object_add_value_float(tmp, ranges[i], io_u_lat_n[i]); | |
1822 | } | |
cc372b17 | 1823 | /* Microsecond latency */ |
d6bb626e VF |
1824 | tmp = json_create_object(); |
1825 | json_object_add_value_object(root, "latency_us", tmp); | |
cc372b17 SL |
1826 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) { |
1827 | const char *ranges[] = { "2", "4", "10", "20", "50", "100", | |
1828 | "250", "500", "750", "1000", }; | |
1829 | json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]); | |
1830 | } | |
1831 | /* Millisecond latency */ | |
1832 | tmp = json_create_object(); | |
1833 | json_object_add_value_object(root, "latency_ms", tmp); | |
1834 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) { | |
1835 | const char *ranges[] = { "2", "4", "10", "20", "50", "100", | |
1836 | "250", "500", "750", "1000", "2000", | |
1837 | ">=2000", }; | |
1838 | json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]); | |
1839 | } | |
1840 | ||
1841 | /* Additional output if continue_on_error set - default off*/ | |
1842 | if (ts->continue_on_error) { | |
1843 | json_object_add_value_int(root, "total_err", ts->total_err_count); | |
952b05e0 | 1844 | json_object_add_value_int(root, "first_error", ts->first_error); |
cc372b17 SL |
1845 | } |
1846 | ||
3e260a46 JA |
1847 | if (ts->latency_depth) { |
1848 | json_object_add_value_int(root, "latency_depth", ts->latency_depth); | |
1849 | json_object_add_value_int(root, "latency_target", ts->latency_target); | |
1850 | json_object_add_value_float(root, "latency_percentile", ts->latency_percentile.u.f); | |
1851 | json_object_add_value_int(root, "latency_window", ts->latency_window); | |
1852 | } | |
1853 | ||
cc372b17 SL |
1854 | /* Additional output if description is set */ |
1855 | if (strlen(ts->description)) | |
1856 | json_object_add_value_string(root, "desc", ts->description); | |
1857 | ||
66347cfa DE |
1858 | if (ts->nr_block_infos) { |
1859 | /* Block error histogram and types */ | |
1860 | int len; | |
1861 | unsigned int *percentiles = NULL; | |
1862 | unsigned int block_state_counts[BLOCK_STATE_COUNT]; | |
1863 | ||
1864 | len = calc_block_percentiles(ts->nr_block_infos, ts->block_infos, | |
1865 | ts->percentile_list, | |
1866 | &percentiles, block_state_counts); | |
1867 | ||
1868 | if (len) { | |
1869 | struct json_object *block, *percentile_object, *states; | |
8a68c41c | 1870 | int state; |
66347cfa DE |
1871 | block = json_create_object(); |
1872 | json_object_add_value_object(root, "block", block); | |
1873 | ||
1874 | percentile_object = json_create_object(); | |
1875 | json_object_add_value_object(block, "percentiles", | |
1876 | percentile_object); | |
1877 | for (i = 0; i < len; i++) { | |
1878 | char buf[20]; | |
1879 | snprintf(buf, sizeof(buf), "%f", | |
1880 | ts->percentile_list[i].u.f); | |
1881 | json_object_add_value_int(percentile_object, | |
c0a6be6c | 1882 | buf, |
66347cfa DE |
1883 | percentiles[i]); |
1884 | } | |
1885 | ||
1886 | states = json_create_object(); | |
1887 | json_object_add_value_object(block, "states", states); | |
1888 | for (state = 0; state < BLOCK_STATE_COUNT; state++) { | |
1889 | json_object_add_value_int(states, | |
1890 | block_state_names[state], | |
1891 | block_state_counts[state]); | |
1892 | } | |
1893 | free(percentiles); | |
1894 | } | |
1895 | } | |
1896 | ||
bb49c8bd | 1897 | if (ts->ss_dur) { |
ba8fb6f6 VF |
1898 | struct json_object *data; |
1899 | struct json_array *iops, *bw; | |
a43f4461 | 1900 | int j, k, l; |
6da94b07 | 1901 | char ss_buf[64]; |
90e678ba | 1902 | int intervals = ts->ss_dur / (ss_check_interval / 1000L); |
16e56d25 | 1903 | |
6da94b07 | 1904 | snprintf(ss_buf, sizeof(ss_buf), "%s%s:%f%s", |
c8caba48 JA |
1905 | ts->ss_state & FIO_SS_IOPS ? "iops" : "bw", |
1906 | ts->ss_state & FIO_SS_SLOPE ? "_slope" : "", | |
bb49c8bd | 1907 | (float) ts->ss_limit.u.f, |
c8caba48 | 1908 | ts->ss_state & FIO_SS_PCT ? "%" : ""); |
16e56d25 VF |
1909 | |
1910 | tmp = json_create_object(); | |
1911 | json_object_add_value_object(root, "steadystate", tmp); | |
6da94b07 | 1912 | json_object_add_value_string(tmp, "ss", ss_buf); |
bb49c8bd | 1913 | json_object_add_value_int(tmp, "duration", (int)ts->ss_dur); |
c8caba48 | 1914 | json_object_add_value_int(tmp, "attained", (ts->ss_state & FIO_SS_ATTAINED) > 0); |
6da94b07 | 1915 | |
bb49c8bd | 1916 | snprintf(ss_buf, sizeof(ss_buf), "%f%s", (float) ts->ss_criterion.u.f, |
c8caba48 | 1917 | ts->ss_state & FIO_SS_PCT ? "%" : ""); |
6da94b07 | 1918 | json_object_add_value_string(tmp, "criterion", ss_buf); |
bb49c8bd VF |
1919 | json_object_add_value_float(tmp, "max_deviation", ts->ss_deviation.u.f); |
1920 | json_object_add_value_float(tmp, "slope", ts->ss_slope.u.f); | |
ba8fb6f6 VF |
1921 | |
1922 | data = json_create_object(); | |
1923 | json_object_add_value_object(tmp, "data", data); | |
1924 | bw = json_create_array(); | |
1925 | iops = json_create_array(); | |
412c7d91 VF |
1926 | |
1927 | /* | |
1928 | ** if ss was attained or the buffer is not full, | |
1929 | ** ss->head points to the first element in the list. | |
1930 | ** otherwise it actually points to the second element | |
1931 | ** in the list | |
1932 | */ | |
c8caba48 | 1933 | if ((ts->ss_state & FIO_SS_ATTAINED) || !(ts->ss_state & FIO_SS_BUFFER_FULL)) |
bb49c8bd | 1934 | j = ts->ss_head; |
412c7d91 | 1935 | else |
90e678ba CL |
1936 | j = ts->ss_head == 0 ? intervals - 1 : ts->ss_head - 1; |
1937 | for (l = 0; l < intervals; l++) { | |
1938 | k = (j + l) % intervals; | |
bb49c8bd VF |
1939 | json_array_add_value_int(bw, ts->ss_bw_data[k]); |
1940 | json_array_add_value_int(iops, ts->ss_iops_data[k]); | |
16e56d25 | 1941 | } |
bb49c8bd VF |
1942 | json_object_add_value_int(data, "bw_mean", steadystate_bw_mean(ts)); |
1943 | json_object_add_value_int(data, "iops_mean", steadystate_iops_mean(ts)); | |
6da94b07 VF |
1944 | json_object_add_value_array(data, "iops", iops); |
1945 | json_object_add_value_array(data, "bw", bw); | |
16e56d25 VF |
1946 | } |
1947 | ||
cc372b17 SL |
1948 | return root; |
1949 | } | |
1950 | ||
4d658652 | 1951 | static void show_thread_status_terse(struct thread_stat *ts, |
a666cab8 JA |
1952 | struct group_run_stats *rs, |
1953 | struct buf_output *out) | |
4d658652 | 1954 | { |
a2c95580 | 1955 | if (terse_version >= 2 && terse_version <= 5) |
bef2112b | 1956 | show_thread_status_terse_all(ts, rs, terse_version, out); |
4d658652 JA |
1957 | else |
1958 | log_err("fio: bad terse version!? %d\n", terse_version); | |
1959 | } | |
1960 | ||
952b05e0 | 1961 | struct json_object *show_thread_status(struct thread_stat *ts, |
a666cab8 | 1962 | struct group_run_stats *rs, |
0279b880 | 1963 | struct flist_head *opt_list, |
a666cab8 | 1964 | struct buf_output *out) |
952b05e0 | 1965 | { |
129fb2d4 JA |
1966 | struct json_object *ret = NULL; |
1967 | ||
1968 | if (output_format & FIO_OUTPUT_TERSE) | |
a666cab8 | 1969 | show_thread_status_terse(ts, rs, out); |
129fb2d4 | 1970 | if (output_format & FIO_OUTPUT_JSON) |
0279b880 | 1971 | ret = show_thread_status_json(ts, rs, opt_list); |
129fb2d4 | 1972 | if (output_format & FIO_OUTPUT_NORMAL) |
a666cab8 | 1973 | show_thread_status_normal(ts, rs, out); |
129fb2d4 JA |
1974 | |
1975 | return ret; | |
952b05e0 CF |
1976 | } |
1977 | ||
70750d6a | 1978 | static void __sum_stat(struct io_stat *dst, struct io_stat *src, bool first) |
756867bd JA |
1979 | { |
1980 | double mean, S; | |
1981 | ||
1982 | dst->min_val = min(dst->min_val, src->min_val); | |
1983 | dst->max_val = max(dst->max_val, src->max_val); | |
756867bd JA |
1984 | |
1985 | /* | |
cdcac5cf YH |
1986 | * Compute new mean and S after the merge |
1987 | * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance | |
1988 | * #Parallel_algorithm> | |
756867bd | 1989 | */ |
fd595830 | 1990 | if (first) { |
802ad4a8 JA |
1991 | mean = src->mean.u.f; |
1992 | S = src->S.u.f; | |
756867bd | 1993 | } else { |
802ad4a8 | 1994 | double delta = src->mean.u.f - dst->mean.u.f; |
cdcac5cf | 1995 | |
802ad4a8 JA |
1996 | mean = ((src->mean.u.f * src->samples) + |
1997 | (dst->mean.u.f * dst->samples)) / | |
cdcac5cf YH |
1998 | (dst->samples + src->samples); |
1999 | ||
802ad4a8 | 2000 | S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) * |
cdcac5cf YH |
2001 | (dst->samples * src->samples) / |
2002 | (dst->samples + src->samples); | |
756867bd JA |
2003 | } |
2004 | ||
cdcac5cf | 2005 | dst->samples += src->samples; |
802ad4a8 JA |
2006 | dst->mean.u.f = mean; |
2007 | dst->S.u.f = S; | |
70750d6a JA |
2008 | |
2009 | } | |
2010 | ||
2011 | /* | |
2012 | * We sum two kinds of stats - one that is time based, in which case we | |
2013 | * apply the proper summing technique, and then one that is iops/bw | |
2014 | * numbers. For group_reporting, we should just add those up, not make | |
2015 | * them the mean of everything. | |
2016 | */ | |
016869be | 2017 | static void sum_stat(struct io_stat *dst, struct io_stat *src, bool pure_sum) |
70750d6a | 2018 | { |
016869be NC |
2019 | bool first = dst->samples == 0; |
2020 | ||
70750d6a JA |
2021 | if (src->samples == 0) |
2022 | return; | |
2023 | ||
2024 | if (!pure_sum) { | |
2025 | __sum_stat(dst, src, first); | |
2026 | return; | |
2027 | } | |
2028 | ||
68afa5b5 JA |
2029 | if (first) { |
2030 | dst->min_val = src->min_val; | |
2031 | dst->max_val = src->max_val; | |
2032 | dst->samples = src->samples; | |
2033 | dst->mean.u.f = src->mean.u.f; | |
2034 | dst->S.u.f = src->S.u.f; | |
2035 | } else { | |
2036 | dst->min_val += src->min_val; | |
2037 | dst->max_val += src->max_val; | |
2038 | dst->samples += src->samples; | |
2039 | dst->mean.u.f += src->mean.u.f; | |
2040 | dst->S.u.f += src->S.u.f; | |
2041 | } | |
756867bd JA |
2042 | } |
2043 | ||
37f0c1ae JA |
2044 | void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src) |
2045 | { | |
2046 | int i; | |
2047 | ||
6eaf09d6 | 2048 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
37f0c1ae JA |
2049 | if (dst->max_run[i] < src->max_run[i]) |
2050 | dst->max_run[i] = src->max_run[i]; | |
2051 | if (dst->min_run[i] && dst->min_run[i] > src->min_run[i]) | |
2052 | dst->min_run[i] = src->min_run[i]; | |
2053 | if (dst->max_bw[i] < src->max_bw[i]) | |
2054 | dst->max_bw[i] = src->max_bw[i]; | |
2055 | if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i]) | |
2056 | dst->min_bw[i] = src->min_bw[i]; | |
2057 | ||
af7f87cb | 2058 | dst->iobytes[i] += src->iobytes[i]; |
37f0c1ae JA |
2059 | dst->agg[i] += src->agg[i]; |
2060 | } | |
2061 | ||
dbae1bd6 JA |
2062 | if (!dst->kb_base) |
2063 | dst->kb_base = src->kb_base; | |
2064 | if (!dst->unit_base) | |
2065 | dst->unit_base = src->unit_base; | |
18aa1998 JF |
2066 | if (!dst->sig_figs) |
2067 | dst->sig_figs = src->sig_figs; | |
37f0c1ae JA |
2068 | } |
2069 | ||
4ad85649 NC |
2070 | /* |
2071 | * Free the clat_prio_stat arrays allocated by alloc_clat_prio_stat_ddir(). | |
2072 | */ | |
2073 | void free_clat_prio_stats(struct thread_stat *ts) | |
2074 | { | |
2075 | enum fio_ddir ddir; | |
2076 | ||
e23aa817 NC |
2077 | if (!ts) |
2078 | return; | |
2079 | ||
4ad85649 NC |
2080 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
2081 | sfree(ts->clat_prio[ddir]); | |
2082 | ts->clat_prio[ddir] = NULL; | |
2083 | ts->nr_clat_prio[ddir] = 0; | |
2084 | } | |
2085 | } | |
2086 | ||
2087 | /* | |
2088 | * Allocate a clat_prio_stat array. The array has to be allocated/freed using | |
2089 | * smalloc/sfree, so that it is accessible by the process/thread summing the | |
2090 | * thread_stats. | |
2091 | */ | |
2092 | int alloc_clat_prio_stat_ddir(struct thread_stat *ts, enum fio_ddir ddir, | |
2093 | int nr_prios) | |
2094 | { | |
2095 | struct clat_prio_stat *clat_prio; | |
2096 | int i; | |
2097 | ||
2098 | clat_prio = scalloc(nr_prios, sizeof(*ts->clat_prio[ddir])); | |
2099 | if (!clat_prio) { | |
2100 | log_err("fio: failed to allocate ts clat data\n"); | |
2101 | return 1; | |
2102 | } | |
2103 | ||
2104 | for (i = 0; i < nr_prios; i++) | |
2105 | clat_prio[i].clat_stat.min_val = ULONG_MAX; | |
2106 | ||
2107 | ts->clat_prio[ddir] = clat_prio; | |
2108 | ts->nr_clat_prio[ddir] = nr_prios; | |
2109 | ||
2110 | return 0; | |
2111 | } | |
2112 | ||
692dec0c NC |
2113 | static int grow_clat_prio_stat(struct thread_stat *dst, enum fio_ddir ddir) |
2114 | { | |
2115 | int curr_len = dst->nr_clat_prio[ddir]; | |
2116 | void *new_arr; | |
2117 | ||
2118 | new_arr = scalloc(curr_len + 1, sizeof(*dst->clat_prio[ddir])); | |
2119 | if (!new_arr) { | |
2120 | log_err("fio: failed to grow clat prio array\n"); | |
2121 | return 1; | |
2122 | } | |
2123 | ||
2124 | memcpy(new_arr, dst->clat_prio[ddir], | |
2125 | curr_len * sizeof(*dst->clat_prio[ddir])); | |
2126 | sfree(dst->clat_prio[ddir]); | |
2127 | ||
2128 | dst->clat_prio[ddir] = new_arr; | |
2129 | dst->clat_prio[ddir][curr_len].clat_stat.min_val = ULONG_MAX; | |
2130 | dst->nr_clat_prio[ddir]++; | |
2131 | ||
2132 | return 0; | |
2133 | } | |
2134 | ||
2135 | static int find_clat_prio_index(struct thread_stat *dst, enum fio_ddir ddir, | |
2136 | uint32_t ioprio) | |
2137 | { | |
2138 | int i, nr_prios = dst->nr_clat_prio[ddir]; | |
2139 | ||
2140 | for (i = 0; i < nr_prios; i++) { | |
2141 | if (dst->clat_prio[ddir][i].ioprio == ioprio) | |
2142 | return i; | |
2143 | } | |
2144 | ||
2145 | return -1; | |
2146 | } | |
2147 | ||
2148 | static int alloc_or_get_clat_prio_index(struct thread_stat *dst, | |
2149 | enum fio_ddir ddir, uint32_t ioprio, | |
2150 | int *idx) | |
2151 | { | |
2152 | int index = find_clat_prio_index(dst, ddir, ioprio); | |
2153 | ||
2154 | if (index == -1) { | |
2155 | index = dst->nr_clat_prio[ddir]; | |
2156 | ||
2157 | if (grow_clat_prio_stat(dst, ddir)) | |
2158 | return 1; | |
2159 | ||
2160 | dst->clat_prio[ddir][index].ioprio = ioprio; | |
2161 | } | |
2162 | ||
2163 | *idx = index; | |
2164 | ||
2165 | return 0; | |
2166 | } | |
2167 | ||
2168 | static int clat_prio_stats_copy(struct thread_stat *dst, struct thread_stat *src, | |
2169 | enum fio_ddir dst_ddir, enum fio_ddir src_ddir) | |
2170 | { | |
2171 | size_t sz = sizeof(*src->clat_prio[src_ddir]) * | |
2172 | src->nr_clat_prio[src_ddir]; | |
2173 | ||
2174 | dst->clat_prio[dst_ddir] = smalloc(sz); | |
2175 | if (!dst->clat_prio[dst_ddir]) { | |
2176 | log_err("fio: failed to alloc clat prio array\n"); | |
2177 | return 1; | |
2178 | } | |
2179 | ||
2180 | memcpy(dst->clat_prio[dst_ddir], src->clat_prio[src_ddir], sz); | |
2181 | dst->nr_clat_prio[dst_ddir] = src->nr_clat_prio[src_ddir]; | |
2182 | ||
2183 | return 0; | |
2184 | } | |
2185 | ||
2186 | static int clat_prio_stat_add_samples(struct thread_stat *dst, | |
2187 | enum fio_ddir dst_ddir, uint32_t ioprio, | |
2188 | struct io_stat *io_stat, | |
2189 | uint64_t *io_u_plat) | |
2190 | { | |
2191 | int i, dst_index; | |
2192 | ||
2193 | if (!io_stat->samples) | |
2194 | return 0; | |
2195 | ||
2196 | if (alloc_or_get_clat_prio_index(dst, dst_ddir, ioprio, &dst_index)) | |
2197 | return 1; | |
2198 | ||
2199 | sum_stat(&dst->clat_prio[dst_ddir][dst_index].clat_stat, io_stat, | |
2200 | false); | |
2201 | ||
2202 | for (i = 0; i < FIO_IO_U_PLAT_NR; i++) | |
2203 | dst->clat_prio[dst_ddir][dst_index].io_u_plat[i] += io_u_plat[i]; | |
2204 | ||
2205 | return 0; | |
2206 | } | |
2207 | ||
2208 | static int sum_clat_prio_stats_src_single_prio(struct thread_stat *dst, | |
2209 | struct thread_stat *src, | |
2210 | enum fio_ddir dst_ddir, | |
2211 | enum fio_ddir src_ddir) | |
2212 | { | |
2213 | struct io_stat *io_stat; | |
2214 | uint64_t *io_u_plat; | |
2215 | ||
2216 | /* | |
2217 | * If src ts has no clat_prio_stat array, then all I/Os were submitted | |
2218 | * using src->ioprio. Thus, the global samples in src->clat_stat (or | |
2219 | * src->lat_stat) can be used as the 'per prio' samples for src->ioprio. | |
2220 | */ | |
2221 | assert(!src->clat_prio[src_ddir]); | |
2222 | assert(src->nr_clat_prio[src_ddir] == 0); | |
2223 | ||
2224 | if (src->lat_percentiles) { | |
2225 | io_u_plat = src->io_u_plat[FIO_LAT][src_ddir]; | |
2226 | io_stat = &src->lat_stat[src_ddir]; | |
2227 | } else { | |
2228 | io_u_plat = src->io_u_plat[FIO_CLAT][src_ddir]; | |
2229 | io_stat = &src->clat_stat[src_ddir]; | |
2230 | } | |
2231 | ||
2232 | return clat_prio_stat_add_samples(dst, dst_ddir, src->ioprio, io_stat, | |
2233 | io_u_plat); | |
2234 | } | |
2235 | ||
2236 | static int sum_clat_prio_stats_src_multi_prio(struct thread_stat *dst, | |
2237 | struct thread_stat *src, | |
2238 | enum fio_ddir dst_ddir, | |
2239 | enum fio_ddir src_ddir) | |
2240 | { | |
2241 | int i; | |
2242 | ||
2243 | /* | |
2244 | * If src ts has a clat_prio_stat array, then there are multiple prios | |
2245 | * in use (i.e. src ts had cmdprio_percentage or cmdprio_bssplit set). | |
2246 | * The samples for the default prio will exist in the src->clat_prio | |
2247 | * array, just like the samples for any other prio. | |
2248 | */ | |
2249 | assert(src->clat_prio[src_ddir]); | |
2250 | assert(src->nr_clat_prio[src_ddir]); | |
2251 | ||
2252 | /* If the dst ts doesn't yet have a clat_prio array, simply memcpy. */ | |
2253 | if (!dst->clat_prio[dst_ddir]) | |
2254 | return clat_prio_stats_copy(dst, src, dst_ddir, src_ddir); | |
2255 | ||
2256 | /* The dst ts already has a clat_prio_array, add src stats into it. */ | |
2257 | for (i = 0; i < src->nr_clat_prio[src_ddir]; i++) { | |
2258 | struct io_stat *io_stat = &src->clat_prio[src_ddir][i].clat_stat; | |
2259 | uint64_t *io_u_plat = src->clat_prio[src_ddir][i].io_u_plat; | |
2260 | uint32_t ioprio = src->clat_prio[src_ddir][i].ioprio; | |
2261 | ||
2262 | if (clat_prio_stat_add_samples(dst, dst_ddir, ioprio, io_stat, io_u_plat)) | |
2263 | return 1; | |
2264 | } | |
2265 | ||
2266 | return 0; | |
2267 | } | |
2268 | ||
2269 | static int sum_clat_prio_stats(struct thread_stat *dst, struct thread_stat *src, | |
2270 | enum fio_ddir dst_ddir, enum fio_ddir src_ddir) | |
2271 | { | |
2272 | if (dst->disable_prio_stat) | |
2273 | return 0; | |
2274 | ||
2275 | if (!src->clat_prio[src_ddir]) | |
2276 | return sum_clat_prio_stats_src_single_prio(dst, src, dst_ddir, | |
2277 | src_ddir); | |
2278 | ||
2279 | return sum_clat_prio_stats_src_multi_prio(dst, src, dst_ddir, src_ddir); | |
2280 | } | |
2281 | ||
016869be | 2282 | void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src) |
5b9babb7 | 2283 | { |
df8781b6 | 2284 | int k, l, m; |
5b9babb7 | 2285 | |
6eaf09d6 | 2286 | for (l = 0; l < DDIR_RWDIR_CNT; l++) { |
6dc75062 | 2287 | if (dst->unified_rw_rep != UNIFIED_MIXED) { |
016869be | 2288 | sum_stat(&dst->clat_stat[l], &src->clat_stat[l], false); |
016869be NC |
2289 | sum_stat(&dst->slat_stat[l], &src->slat_stat[l], false); |
2290 | sum_stat(&dst->lat_stat[l], &src->lat_stat[l], false); | |
2291 | sum_stat(&dst->bw_stat[l], &src->bw_stat[l], true); | |
2292 | sum_stat(&dst->iops_stat[l], &src->iops_stat[l], true); | |
692dec0c | 2293 | sum_clat_prio_stats(dst, src, l, l); |
771e58be JA |
2294 | |
2295 | dst->io_bytes[l] += src->io_bytes[l]; | |
2296 | ||
2297 | if (dst->runtime[l] < src->runtime[l]) | |
2298 | dst->runtime[l] = src->runtime[l]; | |
2299 | } else { | |
016869be | 2300 | sum_stat(&dst->clat_stat[0], &src->clat_stat[l], false); |
016869be NC |
2301 | sum_stat(&dst->slat_stat[0], &src->slat_stat[l], false); |
2302 | sum_stat(&dst->lat_stat[0], &src->lat_stat[l], false); | |
2303 | sum_stat(&dst->bw_stat[0], &src->bw_stat[l], true); | |
2304 | sum_stat(&dst->iops_stat[0], &src->iops_stat[l], true); | |
692dec0c | 2305 | sum_clat_prio_stats(dst, src, 0, l); |
771e58be JA |
2306 | |
2307 | dst->io_bytes[0] += src->io_bytes[l]; | |
2308 | ||
2309 | if (dst->runtime[0] < src->runtime[l]) | |
2310 | dst->runtime[0] = src->runtime[l]; | |
2311 | } | |
5b9babb7 JA |
2312 | } |
2313 | ||
016869be | 2314 | sum_stat(&dst->sync_stat, &src->sync_stat, false); |
5b9babb7 JA |
2315 | dst->usr_time += src->usr_time; |
2316 | dst->sys_time += src->sys_time; | |
2317 | dst->ctx += src->ctx; | |
2318 | dst->majf += src->majf; | |
2319 | dst->minf += src->minf; | |
2320 | ||
b2b3eefe | 2321 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) { |
5b9babb7 | 2322 | dst->io_u_map[k] += src->io_u_map[k]; |
5b9babb7 | 2323 | dst->io_u_submit[k] += src->io_u_submit[k]; |
5b9babb7 | 2324 | dst->io_u_complete[k] += src->io_u_complete[k]; |
b2b3eefe | 2325 | } |
bf14b39e VF |
2326 | |
2327 | for (k = 0; k < FIO_IO_U_LAT_N_NR; k++) | |
d6bb626e | 2328 | dst->io_u_lat_n[k] += src->io_u_lat_n[k]; |
bf14b39e | 2329 | for (k = 0; k < FIO_IO_U_LAT_U_NR; k++) |
5b9babb7 | 2330 | dst->io_u_lat_u[k] += src->io_u_lat_u[k]; |
bf14b39e | 2331 | for (k = 0; k < FIO_IO_U_LAT_M_NR; k++) |
5b9babb7 | 2332 | dst->io_u_lat_m[k] += src->io_u_lat_m[k]; |
bf14b39e | 2333 | |
6eaf09d6 | 2334 | for (k = 0; k < DDIR_RWDIR_CNT; k++) { |
6dc75062 | 2335 | if (dst->unified_rw_rep != UNIFIED_MIXED) { |
771e58be JA |
2336 | dst->total_io_u[k] += src->total_io_u[k]; |
2337 | dst->short_io_u[k] += src->short_io_u[k]; | |
3bcb9d94 | 2338 | dst->drop_io_u[k] += src->drop_io_u[k]; |
771e58be JA |
2339 | } else { |
2340 | dst->total_io_u[0] += src->total_io_u[k]; | |
2341 | dst->short_io_u[0] += src->short_io_u[k]; | |
3bcb9d94 | 2342 | dst->drop_io_u[0] += src->drop_io_u[k]; |
771e58be | 2343 | } |
5b9babb7 JA |
2344 | } |
2345 | ||
7f3ecee2 JA |
2346 | dst->total_io_u[DDIR_SYNC] += src->total_io_u[DDIR_SYNC]; |
2347 | ||
df8781b6 VF |
2348 | for (k = 0; k < FIO_LAT_CNT; k++) |
2349 | for (l = 0; l < DDIR_RWDIR_CNT; l++) | |
2350 | for (m = 0; m < FIO_IO_U_PLAT_NR; m++) | |
6dc75062 | 2351 | if (dst->unified_rw_rep != UNIFIED_MIXED) |
df8781b6 VF |
2352 | dst->io_u_plat[k][l][m] += src->io_u_plat[k][l][m]; |
2353 | else | |
2354 | dst->io_u_plat[k][0][m] += src->io_u_plat[k][l][m]; | |
771e58be | 2355 | |
df8781b6 VF |
2356 | for (k = 0; k < FIO_IO_U_PLAT_NR; k++) |
2357 | dst->io_u_sync_plat[k] += src->io_u_sync_plat[k]; | |
2358 | ||
5b9babb7 JA |
2359 | dst->total_run_time += src->total_run_time; |
2360 | dst->total_submit += src->total_submit; | |
2361 | dst->total_complete += src->total_complete; | |
fd5d733f | 2362 | dst->nr_zone_resets += src->nr_zone_resets; |
96563db9 JA |
2363 | dst->cachehit += src->cachehit; |
2364 | dst->cachemiss += src->cachemiss; | |
5b9babb7 JA |
2365 | } |
2366 | ||
37f0c1ae JA |
2367 | void init_group_run_stat(struct group_run_stats *gs) |
2368 | { | |
6eaf09d6 | 2369 | int i; |
37f0c1ae | 2370 | memset(gs, 0, sizeof(*gs)); |
6eaf09d6 SL |
2371 | |
2372 | for (i = 0; i < DDIR_RWDIR_CNT; i++) | |
2373 | gs->min_bw[i] = gs->min_run[i] = ~0UL; | |
37f0c1ae JA |
2374 | } |
2375 | ||
6619fc32 | 2376 | void init_thread_stat_min_vals(struct thread_stat *ts) |
37f0c1ae | 2377 | { |
6619fc32 NC |
2378 | int i; |
2379 | ||
2380 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { | |
2381 | ts->clat_stat[i].min_val = ULONG_MAX; | |
2382 | ts->slat_stat[i].min_val = ULONG_MAX; | |
2383 | ts->lat_stat[i].min_val = ULONG_MAX; | |
2384 | ts->bw_stat[i].min_val = ULONG_MAX; | |
2385 | ts->iops_stat[i].min_val = ULONG_MAX; | |
6619fc32 NC |
2386 | } |
2387 | ts->sync_stat.min_val = ULONG_MAX; | |
2388 | } | |
37f0c1ae | 2389 | |
6619fc32 NC |
2390 | void init_thread_stat(struct thread_stat *ts) |
2391 | { | |
37f0c1ae JA |
2392 | memset(ts, 0, sizeof(*ts)); |
2393 | ||
6619fc32 | 2394 | init_thread_stat_min_vals(ts); |
37f0c1ae JA |
2395 | ts->groupid = -1; |
2396 | } | |
2397 | ||
691310e2 NC |
2398 | static void init_per_prio_stats(struct thread_stat *threadstats, int nr_ts) |
2399 | { | |
691310e2 NC |
2400 | struct thread_stat *ts; |
2401 | int i, j, last_ts, idx; | |
2402 | enum fio_ddir ddir; | |
2403 | ||
2404 | j = 0; | |
2405 | last_ts = -1; | |
2406 | idx = 0; | |
2407 | ||
2408 | /* | |
2409 | * Loop through all tds, if a td requires per prio stats, temporarily | |
2410 | * store a 1 in ts->disable_prio_stat, and then do an additional | |
2411 | * loop at the end where we invert the ts->disable_prio_stat values. | |
2412 | */ | |
da8f124f | 2413 | for_each_td(td) { |
691310e2 NC |
2414 | if (!td->o.stats) |
2415 | continue; | |
2416 | if (idx && | |
2417 | (!td->o.group_reporting || | |
2418 | (td->o.group_reporting && last_ts != td->groupid))) { | |
2419 | idx = 0; | |
2420 | j++; | |
2421 | } | |
2422 | ||
2423 | last_ts = td->groupid; | |
2424 | ts = &threadstats[j]; | |
2425 | ||
2426 | /* idx == 0 means first td in group, or td is not in a group. */ | |
2427 | if (idx == 0) | |
2428 | ts->ioprio = td->ioprio; | |
2429 | else if (td->ioprio != ts->ioprio) | |
2430 | ts->disable_prio_stat = 1; | |
2431 | ||
2432 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { | |
2433 | if (td->ts.clat_prio[ddir]) { | |
2434 | ts->disable_prio_stat = 1; | |
2435 | break; | |
2436 | } | |
2437 | } | |
2438 | ||
2439 | idx++; | |
da8f124f | 2440 | } end_for_each(); |
691310e2 NC |
2441 | |
2442 | /* Loop through all dst threadstats and fixup the values. */ | |
2443 | for (i = 0; i < nr_ts; i++) { | |
2444 | ts = &threadstats[i]; | |
2445 | ts->disable_prio_stat = !ts->disable_prio_stat; | |
2446 | } | |
2447 | } | |
2448 | ||
83f7b64e | 2449 | void __show_run_stats(void) |
3c39a379 JA |
2450 | { |
2451 | struct group_run_stats *runstats, *rs; | |
756867bd | 2452 | struct thread_stat *threadstats, *ts; |
4da24b69 | 2453 | int i, j, k, nr_ts, last_ts, idx; |
8985b491 JA |
2454 | bool kb_base_warned = false; |
2455 | bool unit_base_warned = false; | |
cc372b17 SL |
2456 | struct json_object *root = NULL; |
2457 | struct json_array *array = NULL; | |
a666cab8 | 2458 | struct buf_output output[FIO_OUTPUT_NR]; |
66e19a38 | 2459 | struct flist_head **opt_lists; |
a666cab8 | 2460 | |
3c39a379 JA |
2461 | runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); |
2462 | ||
37f0c1ae JA |
2463 | for (i = 0; i < groupid + 1; i++) |
2464 | init_group_run_stat(&runstats[i]); | |
3c39a379 | 2465 | |
756867bd JA |
2466 | /* |
2467 | * find out how many threads stats we need. if group reporting isn't | |
2468 | * enabled, it's one-per-td. | |
2469 | */ | |
2470 | nr_ts = 0; | |
2471 | last_ts = -1; | |
da8f124f | 2472 | for_each_td(td) { |
2dc1bbeb | 2473 | if (!td->o.group_reporting) { |
756867bd JA |
2474 | nr_ts++; |
2475 | continue; | |
2476 | } | |
2477 | if (last_ts == td->groupid) | |
2478 | continue; | |
8243be59 JA |
2479 | if (!td->o.stats) |
2480 | continue; | |
756867bd JA |
2481 | |
2482 | last_ts = td->groupid; | |
2483 | nr_ts++; | |
da8f124f | 2484 | } end_for_each(); |
756867bd JA |
2485 | |
2486 | threadstats = malloc(nr_ts * sizeof(struct thread_stat)); | |
66e19a38 | 2487 | opt_lists = malloc(nr_ts * sizeof(struct flist_head *)); |
756867bd | 2488 | |
66e19a38 | 2489 | for (i = 0; i < nr_ts; i++) { |
37f0c1ae | 2490 | init_thread_stat(&threadstats[i]); |
66e19a38 JA |
2491 | opt_lists[i] = NULL; |
2492 | } | |
756867bd | 2493 | |
691310e2 NC |
2494 | init_per_prio_stats(threadstats, nr_ts); |
2495 | ||
756867bd JA |
2496 | j = 0; |
2497 | last_ts = -1; | |
197574e4 | 2498 | idx = 0; |
da8f124f | 2499 | for_each_td(td) { |
8243be59 JA |
2500 | if (!td->o.stats) |
2501 | continue; | |
2dc1bbeb JA |
2502 | if (idx && (!td->o.group_reporting || |
2503 | (td->o.group_reporting && last_ts != td->groupid))) { | |
7abd0e3a JA |
2504 | idx = 0; |
2505 | j++; | |
2506 | } | |
2507 | ||
2508 | last_ts = td->groupid; | |
2509 | ||
756867bd JA |
2510 | ts = &threadstats[j]; |
2511 | ||
83349190 | 2512 | ts->clat_percentiles = td->o.clat_percentiles; |
b599759b | 2513 | ts->lat_percentiles = td->o.lat_percentiles; |
56440e63 | 2514 | ts->slat_percentiles = td->o.slat_percentiles; |
435d195a | 2515 | ts->percentile_precision = td->o.percentile_precision; |
fd112d34 | 2516 | memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list)); |
66e19a38 | 2517 | opt_lists[j] = &td->opt_list; |
83349190 | 2518 | |
197574e4 | 2519 | idx++; |
756867bd | 2520 | |
7abd0e3a | 2521 | if (ts->groupid == -1) { |
2dc84ba7 JA |
2522 | /* |
2523 | * These are per-group shared already | |
2524 | */ | |
36833fb0 | 2525 | snprintf(ts->name, sizeof(ts->name), "%s", td->o.name); |
a64e88da | 2526 | if (td->o.description) |
36833fb0 BVA |
2527 | snprintf(ts->description, |
2528 | sizeof(ts->description), "%s", | |
2529 | td->o.description); | |
a64e88da | 2530 | else |
4e59d0f3 | 2531 | memset(ts->description, 0, FIO_JOBDESC_SIZE); |
a64e88da | 2532 | |
2f122b13 JA |
2533 | /* |
2534 | * If multiple entries in this group, this is | |
2535 | * the first member. | |
2536 | */ | |
2537 | ts->thread_number = td->thread_number; | |
756867bd | 2538 | ts->groupid = td->groupid; |
12d325ca | 2539 | ts->job_start = td->job_start; |
2dc84ba7 JA |
2540 | |
2541 | /* | |
2542 | * first pid in group, not very useful... | |
2543 | */ | |
756867bd | 2544 | ts->pid = td->pid; |
90fef2d1 JA |
2545 | |
2546 | ts->kb_base = td->o.kb_base; | |
ad705bcb | 2547 | ts->unit_base = td->o.unit_base; |
e883cb35 | 2548 | ts->sig_figs = td->o.sig_figs; |
771e58be | 2549 | ts->unified_rw_rep = td->o.unified_rw_rep; |
90fef2d1 JA |
2550 | } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) { |
2551 | log_info("fio: kb_base differs for jobs in group, using" | |
2552 | " %u as the base\n", ts->kb_base); | |
8985b491 | 2553 | kb_base_warned = true; |
ad705bcb SN |
2554 | } else if (ts->unit_base != td->o.unit_base && !unit_base_warned) { |
2555 | log_info("fio: unit_base differs for jobs in group, using" | |
2556 | " %u as the base\n", ts->unit_base); | |
8985b491 | 2557 | unit_base_warned = true; |
2dc84ba7 JA |
2558 | } |
2559 | ||
f2bba182 RR |
2560 | ts->continue_on_error = td->o.continue_on_error; |
2561 | ts->total_err_count += td->total_err_count; | |
2562 | ts->first_error = td->first_error; | |
2563 | if (!ts->error) { | |
2564 | if (!td->error && td->o.continue_on_error && | |
2565 | td->first_error) { | |
2566 | ts->error = td->first_error; | |
36833fb0 BVA |
2567 | snprintf(ts->verror, sizeof(ts->verror), "%s", |
2568 | td->verror); | |
f2bba182 RR |
2569 | } else if (td->error) { |
2570 | ts->error = td->error; | |
36833fb0 BVA |
2571 | snprintf(ts->verror, sizeof(ts->verror), "%s", |
2572 | td->verror); | |
f2bba182 | 2573 | } |
756867bd JA |
2574 | } |
2575 | ||
3e260a46 JA |
2576 | ts->latency_depth = td->latency_qd; |
2577 | ts->latency_target = td->o.latency_target; | |
2578 | ts->latency_percentile = td->o.latency_percentile; | |
2579 | ts->latency_window = td->o.latency_window; | |
2580 | ||
0e4dd95c | 2581 | ts->nr_block_infos = td->ts.nr_block_infos; |
4da24b69 JA |
2582 | for (k = 0; k < ts->nr_block_infos; k++) |
2583 | ts->block_infos[k] = td->ts.block_infos[k]; | |
0e4dd95c | 2584 | |
016869be | 2585 | sum_thread_stats(ts, &td->ts); |
16e56d25 | 2586 | |
a381c018 NC |
2587 | ts->members++; |
2588 | ||
bb49c8bd VF |
2589 | if (td->o.ss_dur) { |
2590 | ts->ss_state = td->ss.state; | |
2591 | ts->ss_dur = td->ss.dur; | |
2592 | ts->ss_head = td->ss.head; | |
bb49c8bd VF |
2593 | ts->ss_bw_data = td->ss.bw_data; |
2594 | ts->ss_iops_data = td->ss.iops_data; | |
2595 | ts->ss_limit.u.f = td->ss.limit; | |
2596 | ts->ss_slope.u.f = td->ss.slope; | |
2597 | ts->ss_deviation.u.f = td->ss.deviation; | |
2598 | ts->ss_criterion.u.f = td->ss.criterion; | |
2599 | } | |
16e56d25 | 2600 | else |
bb49c8bd | 2601 | ts->ss_dur = ts->ss_state = 0; |
da8f124f | 2602 | } end_for_each(); |
756867bd JA |
2603 | |
2604 | for (i = 0; i < nr_ts; i++) { | |
94370ac4 | 2605 | unsigned long long bw; |
3c39a379 | 2606 | |
756867bd | 2607 | ts = &threadstats[i]; |
dedb88eb JA |
2608 | if (ts->groupid == -1) |
2609 | continue; | |
756867bd | 2610 | rs = &runstats[ts->groupid]; |
90fef2d1 | 2611 | rs->kb_base = ts->kb_base; |
ad705bcb | 2612 | rs->unit_base = ts->unit_base; |
e883cb35 | 2613 | rs->sig_figs = ts->sig_figs; |
5cb8a8cd | 2614 | rs->unified_rw_rep |= ts->unified_rw_rep; |
3c39a379 | 2615 | |
6eaf09d6 | 2616 | for (j = 0; j < DDIR_RWDIR_CNT; j++) { |
94370ac4 JA |
2617 | if (!ts->runtime[j]) |
2618 | continue; | |
2619 | if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j]) | |
2620 | rs->min_run[j] = ts->runtime[j]; | |
2621 | if (ts->runtime[j] > rs->max_run[j]) | |
2622 | rs->max_run[j] = ts->runtime[j]; | |
2623 | ||
2624 | bw = 0; | |
af7f87cb RE |
2625 | if (ts->runtime[j]) |
2626 | bw = ts->io_bytes[j] * 1000 / ts->runtime[j]; | |
94370ac4 JA |
2627 | if (bw < rs->min_bw[j]) |
2628 | rs->min_bw[j] = bw; | |
2629 | if (bw > rs->max_bw[j]) | |
2630 | rs->max_bw[j] = bw; | |
2631 | ||
af7f87cb | 2632 | rs->iobytes[j] += ts->io_bytes[j]; |
94370ac4 | 2633 | } |
3c39a379 JA |
2634 | } |
2635 | ||
2636 | for (i = 0; i < groupid + 1; i++) { | |
2e545522 | 2637 | enum fio_ddir ddir; |
6eaf09d6 | 2638 | |
3c39a379 JA |
2639 | rs = &runstats[i]; |
2640 | ||
6eaf09d6 SL |
2641 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
2642 | if (rs->max_run[ddir]) | |
af7f87cb | 2643 | rs->agg[ddir] = (rs->iobytes[ddir] * 1000) / |
6eaf09d6 SL |
2644 | rs->max_run[ddir]; |
2645 | } | |
3c39a379 JA |
2646 | } |
2647 | ||
a666cab8 | 2648 | for (i = 0; i < FIO_OUTPUT_NR; i++) |
e250c0a9 | 2649 | buf_output_init(&output[i]); |
a666cab8 | 2650 | |
3c39a379 JA |
2651 | /* |
2652 | * don't overwrite last signal output | |
2653 | */ | |
129fb2d4 | 2654 | if (output_format & FIO_OUTPUT_NORMAL) |
a666cab8 | 2655 | log_buf(&output[__FIO_OUTPUT_NORMAL], "\n"); |
129fb2d4 | 2656 | if (output_format & FIO_OUTPUT_JSON) { |
66e19a38 | 2657 | struct thread_data *global; |
35326842 | 2658 | char time_buf[32]; |
aa7d2ef0 RH |
2659 | struct timeval now; |
2660 | unsigned long long ms_since_epoch; | |
afd74e2a | 2661 | time_t tv_sec; |
91e53870 | 2662 | |
aa7d2ef0 RH |
2663 | gettimeofday(&now, NULL); |
2664 | ms_since_epoch = (unsigned long long)(now.tv_sec) * 1000 + | |
2665 | (unsigned long long)(now.tv_usec) / 1000; | |
2666 | ||
afd74e2a BVA |
2667 | tv_sec = now.tv_sec; |
2668 | os_ctime_r(&tv_sec, time_buf, sizeof(time_buf)); | |
1d272416 JA |
2669 | if (time_buf[strlen(time_buf) - 1] == '\n') |
2670 | time_buf[strlen(time_buf) - 1] = '\0'; | |
91e53870 | 2671 | |
cc372b17 SL |
2672 | root = json_create_object(); |
2673 | json_object_add_value_string(root, "fio version", fio_version_string); | |
aa7d2ef0 RH |
2674 | json_object_add_value_int(root, "timestamp", now.tv_sec); |
2675 | json_object_add_value_int(root, "timestamp_ms", ms_since_epoch); | |
91e53870 | 2676 | json_object_add_value_string(root, "time", time_buf); |
66e19a38 | 2677 | global = get_global_options(); |
0cf542af | 2678 | json_add_job_opts(root, "global options", &global->opt_list); |
cc372b17 SL |
2679 | array = json_create_array(); |
2680 | json_object_add_value_array(root, "jobs", array); | |
2681 | } | |
3c39a379 | 2682 | |
0279b880 JA |
2683 | if (is_backend) |
2684 | fio_server_send_job_options(&get_global_options()->opt_list, -1U); | |
2685 | ||
756867bd JA |
2686 | for (i = 0; i < nr_ts; i++) { |
2687 | ts = &threadstats[i]; | |
2688 | rs = &runstats[ts->groupid]; | |
3c39a379 | 2689 | |
0279b880 JA |
2690 | if (is_backend) { |
2691 | fio_server_send_job_options(opt_lists[i], i); | |
a64e88da | 2692 | fio_server_send_ts(ts, rs); |
0279b880 | 2693 | } else { |
129fb2d4 | 2694 | if (output_format & FIO_OUTPUT_TERSE) |
a666cab8 | 2695 | show_thread_status_terse(ts, rs, &output[__FIO_OUTPUT_TERSE]); |
129fb2d4 | 2696 | if (output_format & FIO_OUTPUT_JSON) { |
66e19a38 | 2697 | struct json_object *tmp = show_thread_status_json(ts, rs, opt_lists[i]); |
129fb2d4 JA |
2698 | json_array_add_value_object(array, tmp); |
2699 | } | |
2700 | if (output_format & FIO_OUTPUT_NORMAL) | |
a666cab8 | 2701 | show_thread_status_normal(ts, rs, &output[__FIO_OUTPUT_NORMAL]); |
129fb2d4 | 2702 | } |
3c39a379 | 2703 | } |
ab34ddd1 | 2704 | if (!is_backend && (output_format & FIO_OUTPUT_JSON)) { |
cc372b17 | 2705 | /* disk util stats, if any */ |
a666cab8 | 2706 | show_disk_util(1, root, &output[__FIO_OUTPUT_JSON]); |
cc372b17 | 2707 | |
a666cab8 | 2708 | show_idle_prof_stats(FIO_OUTPUT_JSON, root, &output[__FIO_OUTPUT_JSON]); |
f2a2ce0e | 2709 | |
a666cab8 JA |
2710 | json_print_object(root, &output[__FIO_OUTPUT_JSON]); |
2711 | log_buf(&output[__FIO_OUTPUT_JSON], "\n"); | |
cc372b17 SL |
2712 | json_free_object(root); |
2713 | } | |
3c39a379 | 2714 | |
72c27ff8 JA |
2715 | for (i = 0; i < groupid + 1; i++) { |
2716 | rs = &runstats[i]; | |
3c39a379 | 2717 | |
72c27ff8 | 2718 | rs->groupid = i; |
d09a64a0 | 2719 | if (is_backend) |
72c27ff8 | 2720 | fio_server_send_gs(rs); |
129fb2d4 | 2721 | else if (output_format & FIO_OUTPUT_NORMAL) |
a666cab8 | 2722 | show_group_stats(rs, &output[__FIO_OUTPUT_NORMAL]); |
c6ae0a5b | 2723 | } |
eecf272f | 2724 | |
72c27ff8 JA |
2725 | if (is_backend) |
2726 | fio_server_send_du(); | |
129fb2d4 | 2727 | else if (output_format & FIO_OUTPUT_NORMAL) { |
a666cab8 JA |
2728 | show_disk_util(0, NULL, &output[__FIO_OUTPUT_NORMAL]); |
2729 | show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL, &output[__FIO_OUTPUT_NORMAL]); | |
60904003 | 2730 | } |
f2a2ce0e | 2731 | |
3d57c0e9 | 2732 | for (i = 0; i < FIO_OUTPUT_NR; i++) { |
3dc3aa41 | 2733 | struct buf_output *out = &output[i]; |
8dd0eca3 | 2734 | |
3dc3aa41 | 2735 | log_info_buf(out->buf, out->buflen); |
3dc3aa41 | 2736 | buf_output_free(out); |
3d57c0e9 | 2737 | } |
2b8c71b0 | 2738 | |
7ceefc09 FS |
2739 | fio_idle_prof_cleanup(); |
2740 | ||
fdd5f15f | 2741 | log_info_flush(); |
eecf272f | 2742 | free(runstats); |
692dec0c NC |
2743 | |
2744 | /* free arrays allocated by sum_thread_stats(), if any */ | |
2745 | for (i = 0; i < nr_ts; i++) { | |
2746 | ts = &threadstats[i]; | |
2747 | free_clat_prio_stats(ts); | |
2748 | } | |
756867bd | 2749 | free(threadstats); |
66e19a38 | 2750 | free(opt_lists); |
3c39a379 JA |
2751 | } |
2752 | ||
966f8ef9 | 2753 | int __show_running_run_stats(void) |
b852e7cf | 2754 | { |
b852e7cf | 2755 | unsigned long long *rt; |
8b6a404c | 2756 | struct timespec ts; |
b852e7cf | 2757 | |
971caeb1 | 2758 | fio_sem_down(stat_sem); |
90811930 | 2759 | |
b852e7cf | 2760 | rt = malloc(thread_number * sizeof(unsigned long long)); |
8b6a404c | 2761 | fio_gettime(&ts, NULL); |
b852e7cf | 2762 | |
da8f124f | 2763 | for_each_td(td) { |
61850e56 KM |
2764 | if (td->runstate >= TD_EXITED) |
2765 | continue; | |
2766 | ||
c97f1ad6 | 2767 | td->update_rusage = 1; |
dde39f8c AD |
2768 | for_each_rw_ddir(ddir) { |
2769 | td->ts.io_bytes[ddir] = td->io_bytes[ddir]; | |
2770 | } | |
8b6a404c | 2771 | td->ts.total_run_time = mtime_since(&td->epoch, &ts); |
6c041a88 | 2772 | |
da8f124f | 2773 | rt[__td_index] = mtime_since(&td->start, &ts); |
6c041a88 | 2774 | if (td_read(td) && td->ts.io_bytes[DDIR_READ]) |
da8f124f | 2775 | td->ts.runtime[DDIR_READ] += rt[__td_index]; |
6c041a88 | 2776 | if (td_write(td) && td->ts.io_bytes[DDIR_WRITE]) |
da8f124f | 2777 | td->ts.runtime[DDIR_WRITE] += rt[__td_index]; |
6c041a88 | 2778 | if (td_trim(td) && td->ts.io_bytes[DDIR_TRIM]) |
da8f124f H |
2779 | td->ts.runtime[DDIR_TRIM] += rt[__td_index]; |
2780 | } end_for_each(); | |
b852e7cf | 2781 | |
da8f124f | 2782 | for_each_td(td) { |
fda2cfac JA |
2783 | if (td->runstate >= TD_EXITED) |
2784 | continue; | |
c97f1ad6 JA |
2785 | if (td->rusage_sem) { |
2786 | td->update_rusage = 1; | |
971caeb1 | 2787 | fio_sem_down(td->rusage_sem); |
c97f1ad6 JA |
2788 | } |
2789 | td->update_rusage = 0; | |
da8f124f | 2790 | } end_for_each(); |
c97f1ad6 | 2791 | |
cef9175e | 2792 | __show_run_stats(); |
b852e7cf | 2793 | |
da8f124f | 2794 | for_each_td(td) { |
61850e56 KM |
2795 | if (td->runstate >= TD_EXITED) |
2796 | continue; | |
2797 | ||
6c041a88 | 2798 | if (td_read(td) && td->ts.io_bytes[DDIR_READ]) |
da8f124f | 2799 | td->ts.runtime[DDIR_READ] -= rt[__td_index]; |
6c041a88 | 2800 | if (td_write(td) && td->ts.io_bytes[DDIR_WRITE]) |
da8f124f | 2801 | td->ts.runtime[DDIR_WRITE] -= rt[__td_index]; |
6c041a88 | 2802 | if (td_trim(td) && td->ts.io_bytes[DDIR_TRIM]) |
da8f124f H |
2803 | td->ts.runtime[DDIR_TRIM] -= rt[__td_index]; |
2804 | } end_for_each(); | |
b852e7cf JA |
2805 | |
2806 | free(rt); | |
971caeb1 | 2807 | fio_sem_up(stat_sem); |
966f8ef9 BVA |
2808 | |
2809 | return 0; | |
b852e7cf JA |
2810 | } |
2811 | ||
8985b491 | 2812 | static bool status_file_disabled; |
06464907 | 2813 | |
dac45f23 | 2814 | #define FIO_STATUS_FILE "fio-dump-status" |
06464907 JA |
2815 | |
2816 | static int check_status_file(void) | |
2817 | { | |
2818 | struct stat sb; | |
a0bafb7d BC |
2819 | const char *temp_dir; |
2820 | char fio_status_file_path[PATH_MAX]; | |
06464907 | 2821 | |
77d99675 JA |
2822 | if (status_file_disabled) |
2823 | return 0; | |
2824 | ||
a0bafb7d | 2825 | temp_dir = getenv("TMPDIR"); |
48b16e27 | 2826 | if (temp_dir == NULL) { |
a0bafb7d | 2827 | temp_dir = getenv("TEMP"); |
48b16e27 JA |
2828 | if (temp_dir && strlen(temp_dir) >= PATH_MAX) |
2829 | temp_dir = NULL; | |
2830 | } | |
a0bafb7d BC |
2831 | if (temp_dir == NULL) |
2832 | temp_dir = "/tmp"; | |
3544731c BVA |
2833 | #ifdef __COVERITY__ |
2834 | __coverity_tainted_data_sanitize__(temp_dir); | |
2835 | #endif | |
a0bafb7d BC |
2836 | |
2837 | snprintf(fio_status_file_path, sizeof(fio_status_file_path), "%s/%s", temp_dir, FIO_STATUS_FILE); | |
2838 | ||
2839 | if (stat(fio_status_file_path, &sb)) | |
06464907 JA |
2840 | return 0; |
2841 | ||
77d99675 JA |
2842 | if (unlink(fio_status_file_path) < 0) { |
2843 | log_err("fio: failed to unlink %s: %s\n", fio_status_file_path, | |
2844 | strerror(errno)); | |
2845 | log_err("fio: disabling status file updates\n"); | |
8985b491 | 2846 | status_file_disabled = true; |
77d99675 JA |
2847 | } |
2848 | ||
06464907 JA |
2849 | return 1; |
2850 | } | |
2851 | ||
2852 | void check_for_running_stats(void) | |
2853 | { | |
06464907 JA |
2854 | if (check_status_file()) { |
2855 | show_running_run_stats(); | |
2856 | return; | |
2857 | } | |
2858 | } | |
2859 | ||
d6bb626e | 2860 | static inline void add_stat_sample(struct io_stat *is, unsigned long long data) |
3c39a379 | 2861 | { |
68704084 | 2862 | double val = data; |
6660cc67 | 2863 | double delta; |
68704084 JA |
2864 | |
2865 | if (data > is->max_val) | |
2866 | is->max_val = data; | |
2867 | if (data < is->min_val) | |
2868 | is->min_val = data; | |
2869 | ||
802ad4a8 | 2870 | delta = val - is->mean.u.f; |
ef11d737 | 2871 | if (delta) { |
802ad4a8 JA |
2872 | is->mean.u.f += delta / (is->samples + 1.0); |
2873 | is->S.u.f += delta * (val - is->mean.u.f); | |
ef11d737 | 2874 | } |
3c39a379 | 2875 | |
3c39a379 JA |
2876 | is->samples++; |
2877 | } | |
2878 | ||
692dec0c NC |
2879 | static inline void add_stat_prio_sample(struct clat_prio_stat *clat_prio, |
2880 | unsigned short clat_prio_index, | |
2881 | unsigned long long nsec) | |
2882 | { | |
2883 | if (clat_prio) | |
2884 | add_stat_sample(&clat_prio[clat_prio_index].clat_stat, nsec); | |
2885 | } | |
2886 | ||
7e419452 JA |
2887 | /* |
2888 | * Return a struct io_logs, which is added to the tail of the log | |
2889 | * list for 'iolog'. | |
2890 | */ | |
2891 | static struct io_logs *get_new_log(struct io_log *iolog) | |
2892 | { | |
0a852a50 | 2893 | size_t new_samples; |
7e419452 JA |
2894 | struct io_logs *cur_log; |
2895 | ||
2896 | /* | |
2897 | * Cap the size at MAX_LOG_ENTRIES, so we don't keep doubling | |
2898 | * forever | |
2899 | */ | |
0a852a50 | 2900 | if (!iolog->cur_log_max) { |
d7224476 AK |
2901 | if (iolog->td) |
2902 | new_samples = iolog->td->o.log_entries; | |
2903 | else | |
2904 | new_samples = DEF_LOG_ENTRIES; | |
0a852a50 | 2905 | } else { |
7e419452 JA |
2906 | new_samples = iolog->cur_log_max * 2; |
2907 | if (new_samples > MAX_LOG_ENTRIES) | |
2908 | new_samples = MAX_LOG_ENTRIES; | |
2909 | } | |
2910 | ||
90d2d53f | 2911 | cur_log = smalloc(sizeof(*cur_log)); |
7e419452 JA |
2912 | if (cur_log) { |
2913 | INIT_FLIST_HEAD(&cur_log->list); | |
0a852a50 | 2914 | cur_log->log = calloc(new_samples, log_entry_sz(iolog)); |
7e419452 JA |
2915 | if (cur_log->log) { |
2916 | cur_log->nr_samples = 0; | |
2917 | cur_log->max_samples = new_samples; | |
2918 | flist_add_tail(&cur_log->list, &iolog->io_logs); | |
2919 | iolog->cur_log_max = new_samples; | |
2920 | return cur_log; | |
2921 | } | |
90d2d53f | 2922 | sfree(cur_log); |
7e419452 JA |
2923 | } |
2924 | ||
2925 | return NULL; | |
2926 | } | |
2927 | ||
1fed2080 JA |
2928 | /* |
2929 | * Add and return a new log chunk, or return current log if big enough | |
2930 | */ | |
2931 | static struct io_logs *regrow_log(struct io_log *iolog) | |
7e419452 JA |
2932 | { |
2933 | struct io_logs *cur_log; | |
1fed2080 | 2934 | int i; |
7e419452 | 2935 | |
1fed2080 | 2936 | if (!iolog || iolog->disabled) |
2ab71dc4 | 2937 | goto disable; |
7e419452 | 2938 | |
1fed2080 | 2939 | cur_log = iolog_cur_log(iolog); |
a9afa45a JA |
2940 | if (!cur_log) { |
2941 | cur_log = get_new_log(iolog); | |
2942 | if (!cur_log) | |
2943 | return NULL; | |
2944 | } | |
2945 | ||
7e419452 JA |
2946 | if (cur_log->nr_samples < cur_log->max_samples) |
2947 | return cur_log; | |
2948 | ||
2949 | /* | |
2950 | * No room for a new sample. If we're compressing on the fly, flush | |
2951 | * out the current chunk | |
2952 | */ | |
2953 | if (iolog->log_gz) { | |
2954 | if (iolog_cur_flush(iolog, cur_log)) { | |
2955 | log_err("fio: failed flushing iolog! Will stop logging.\n"); | |
2956 | return NULL; | |
2957 | } | |
2958 | } | |
2959 | ||
2960 | /* | |
2961 | * Get a new log array, and add to our list | |
2962 | */ | |
2963 | cur_log = get_new_log(iolog); | |
1fed2080 JA |
2964 | if (!cur_log) { |
2965 | log_err("fio: failed extending iolog! Will stop logging.\n"); | |
2966 | return NULL; | |
2967 | } | |
2968 | ||
2969 | if (!iolog->pending || !iolog->pending->nr_samples) | |
80a24ba9 | 2970 | return cur_log; |
7e419452 | 2971 | |
1fed2080 JA |
2972 | /* |
2973 | * Flush pending items to new log | |
2974 | */ | |
2975 | for (i = 0; i < iolog->pending->nr_samples; i++) { | |
2976 | struct io_sample *src, *dst; | |
2977 | ||
2978 | src = get_sample(iolog, iolog->pending, i); | |
2979 | dst = get_sample(iolog, cur_log, i); | |
2980 | memcpy(dst, src, log_entry_sz(iolog)); | |
2981 | } | |
0b2eef49 | 2982 | cur_log->nr_samples = iolog->pending->nr_samples; |
1fed2080 JA |
2983 | |
2984 | iolog->pending->nr_samples = 0; | |
2985 | return cur_log; | |
2ab71dc4 JA |
2986 | disable: |
2987 | if (iolog) | |
2988 | iolog->disabled = true; | |
2989 | return NULL; | |
1fed2080 JA |
2990 | } |
2991 | ||
2992 | void regrow_logs(struct thread_data *td) | |
2993 | { | |
2ab71dc4 JA |
2994 | regrow_log(td->slat_log); |
2995 | regrow_log(td->clat_log); | |
1e613c9c | 2996 | regrow_log(td->clat_hist_log); |
2ab71dc4 JA |
2997 | regrow_log(td->lat_log); |
2998 | regrow_log(td->bw_log); | |
2999 | regrow_log(td->iops_log); | |
1fed2080 JA |
3000 | td->flags &= ~TD_F_REGROW_LOGS; |
3001 | } | |
3002 | ||
76204de3 PM |
3003 | void regrow_agg_logs(void) |
3004 | { | |
3005 | enum fio_ddir ddir; | |
3006 | ||
3007 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) | |
3008 | regrow_log(agg_io_log[ddir]); | |
3009 | } | |
3010 | ||
1fed2080 JA |
3011 | static struct io_logs *get_cur_log(struct io_log *iolog) |
3012 | { | |
3013 | struct io_logs *cur_log; | |
3014 | ||
3015 | cur_log = iolog_cur_log(iolog); | |
3016 | if (!cur_log) { | |
3017 | cur_log = get_new_log(iolog); | |
3018 | if (!cur_log) | |
3019 | return NULL; | |
3020 | } | |
3021 | ||
3022 | if (cur_log->nr_samples < cur_log->max_samples) | |
3023 | return cur_log; | |
3024 | ||
3025 | /* | |
1eb467fb JA |
3026 | * Out of space. If we're in IO offload mode, or we're not doing |
3027 | * per unit logging (hence logging happens outside of the IO thread | |
3028 | * as well), add a new log chunk inline. If we're doing inline | |
3029 | * submissions, flag 'td' as needing a log regrow and we'll take | |
3030 | * care of it on the submission side. | |
1fed2080 | 3031 | */ |
ab5643cb | 3032 | if ((iolog->td && iolog->td->o.io_submit_mode == IO_MODE_OFFLOAD) || |
1eb467fb | 3033 | !per_unit_log(iolog)) |
1fed2080 JA |
3034 | return regrow_log(iolog); |
3035 | ||
ab5643cb IK |
3036 | if (iolog->td) |
3037 | iolog->td->flags |= TD_F_REGROW_LOGS; | |
3038 | if (iolog->pending) | |
3039 | assert(iolog->pending->nr_samples < iolog->pending->max_samples); | |
1fed2080 | 3040 | return iolog->pending; |
7e419452 JA |
3041 | } |
3042 | ||
2e7da20d SK |
3043 | static void __add_log_sample(struct io_log *iolog, unsigned long t, |
3044 | struct log_sample *sample) | |
3c39a379 | 3045 | { |
7e419452 | 3046 | struct io_logs *cur_log; |
306ddc97 | 3047 | |
3c568239 JA |
3048 | if (iolog->disabled) |
3049 | return; | |
7e419452 | 3050 | if (flist_empty(&iolog->io_logs)) |
2e7da20d | 3051 | iolog->avg_last[sample->ddir] = t; |
b8bc8cba | 3052 | |
7e419452 JA |
3053 | cur_log = get_cur_log(iolog); |
3054 | if (cur_log) { | |
3055 | struct io_sample *s; | |
3c39a379 | 3056 | |
7e419452 | 3057 | s = get_sample(iolog, cur_log, cur_log->nr_samples); |
3c39a379 | 3058 | |
2e7da20d | 3059 | s->data = sample->data; |
12d325ca | 3060 | s->time = t; |
d252275b | 3061 | if (iolog->td && iolog->td->o.log_alternate_epoch) |
12d325ca | 3062 | s->time += iolog->td->alternate_epoch; |
2e7da20d SK |
3063 | io_sample_set_ddir(iolog, s, sample->ddir); |
3064 | s->bs = sample->bs; | |
3065 | s->priority = sample->priority; | |
ae588852 | 3066 | |
9f0a81a6 SK |
3067 | if (iolog->log_offset) |
3068 | s->aux[IOS_AUX_OFFSET_INDEX] = sample->offset; | |
ae588852 | 3069 | |
14d3134a SK |
3070 | if (iolog->log_issue_time) |
3071 | s->aux[IOS_AUX_ISSUE_TIME_INDEX] = sample->issue_time; | |
3072 | ||
7e419452 JA |
3073 | cur_log->nr_samples++; |
3074 | return; | |
ae588852 JA |
3075 | } |
3076 | ||
7e419452 | 3077 | iolog->disabled = true; |
3c39a379 JA |
3078 | } |
3079 | ||
7fb28d36 JA |
3080 | static inline void reset_io_stat(struct io_stat *ios) |
3081 | { | |
5b8f19b7 JA |
3082 | ios->min_val = -1ULL; |
3083 | ios->max_val = ios->samples = 0; | |
7fb28d36 JA |
3084 | ios->mean.u.f = ios->S.u.f = 0; |
3085 | } | |
3086 | ||
2f045d2e NC |
3087 | static inline void reset_io_u_plat(uint64_t *io_u_plat) |
3088 | { | |
3089 | int i; | |
3090 | ||
3091 | for (i = 0; i < FIO_IO_U_PLAT_NR; i++) | |
3092 | io_u_plat[i] = 0; | |
3093 | } | |
3094 | ||
692dec0c NC |
3095 | static inline void reset_clat_prio_stats(struct thread_stat *ts) |
3096 | { | |
3097 | enum fio_ddir ddir; | |
3098 | int i; | |
3099 | ||
3100 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { | |
3101 | if (!ts->clat_prio[ddir]) | |
3102 | continue; | |
3103 | ||
3104 | for (i = 0; i < ts->nr_clat_prio[ddir]; i++) { | |
3105 | reset_io_stat(&ts->clat_prio[ddir][i].clat_stat); | |
3106 | reset_io_u_plat(ts->clat_prio[ddir][i].io_u_plat); | |
3107 | } | |
3108 | } | |
3109 | } | |
3110 | ||
6bb58215 JA |
3111 | void reset_io_stats(struct thread_data *td) |
3112 | { | |
3113 | struct thread_stat *ts = &td->ts; | |
2f045d2e | 3114 | int i, j; |
6bb58215 JA |
3115 | |
3116 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { | |
3117 | reset_io_stat(&ts->clat_stat[i]); | |
3118 | reset_io_stat(&ts->slat_stat[i]); | |
3119 | reset_io_stat(&ts->lat_stat[i]); | |
3120 | reset_io_stat(&ts->bw_stat[i]); | |
3121 | reset_io_stat(&ts->iops_stat[i]); | |
3122 | ||
3123 | ts->io_bytes[i] = 0; | |
3124 | ts->runtime[i] = 0; | |
71cb78c1 VF |
3125 | ts->total_io_u[i] = 0; |
3126 | ts->short_io_u[i] = 0; | |
3127 | ts->drop_io_u[i] = 0; | |
6bb58215 JA |
3128 | } |
3129 | ||
df8781b6 VF |
3130 | for (i = 0; i < FIO_LAT_CNT; i++) |
3131 | for (j = 0; j < DDIR_RWDIR_CNT; j++) | |
2f045d2e | 3132 | reset_io_u_plat(ts->io_u_plat[i][j]); |
df8781b6 | 3133 | |
692dec0c NC |
3134 | reset_clat_prio_stats(ts); |
3135 | ||
7f3ecee2 | 3136 | ts->total_io_u[DDIR_SYNC] = 0; |
2f045d2e | 3137 | reset_io_u_plat(ts->io_u_sync_plat); |
7f3ecee2 | 3138 | |
6bb58215 JA |
3139 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { |
3140 | ts->io_u_map[i] = 0; | |
3141 | ts->io_u_submit[i] = 0; | |
3142 | ts->io_u_complete[i] = 0; | |
71cb78c1 VF |
3143 | } |
3144 | ||
d6bb626e VF |
3145 | for (i = 0; i < FIO_IO_U_LAT_N_NR; i++) |
3146 | ts->io_u_lat_n[i] = 0; | |
71cb78c1 | 3147 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) |
6bb58215 | 3148 | ts->io_u_lat_u[i] = 0; |
71cb78c1 | 3149 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) |
6bb58215 | 3150 | ts->io_u_lat_m[i] = 0; |
6bb58215 | 3151 | |
71cb78c1 VF |
3152 | ts->total_submit = 0; |
3153 | ts->total_complete = 0; | |
fd5d733f | 3154 | ts->nr_zone_resets = 0; |
96563db9 | 3155 | ts->cachehit = ts->cachemiss = 0; |
6bb58215 JA |
3156 | } |
3157 | ||
d96d3bb3 | 3158 | static void __add_stat_to_log(struct io_log *iolog, enum fio_ddir ddir, |
0e14633c | 3159 | unsigned long elapsed, int log_max) |
99007068 PO |
3160 | { |
3161 | /* | |
3162 | * Note an entry in the log. Use the mean from the logged samples, | |
3163 | * making sure to properly round up. Only write a log entry if we | |
3164 | * had actual samples done. | |
3165 | */ | |
d96d3bb3 | 3166 | if (iolog->avg_window[ddir].samples) { |
14d3134a | 3167 | struct log_sample sample = { {{ 0, 0 }}, ddir, 0, 0, 0, 0 }; |
2e7da20d | 3168 | union io_sample_data *d = &sample.data; |
99007068 | 3169 | |
0e14633c | 3170 | if (log_max == IO_LOG_SAMPLE_AVG) { |
2e7da20d SK |
3171 | d->val.val0 = iolog->avg_window[ddir].mean.u.f + 0.50; |
3172 | d->val.val1 = 0; | |
0e14633c | 3173 | } else if (log_max == IO_LOG_SAMPLE_MAX) { |
2e7da20d SK |
3174 | d->val.val0 = iolog->avg_window[ddir].max_val; |
3175 | d->val.val1 = 0; | |
0e14633c | 3176 | } else { |
2e7da20d SK |
3177 | d->val.val0 = iolog->avg_window[ddir].mean.u.f + 0.50; |
3178 | d->val.val1 = iolog->avg_window[ddir].max_val; | |
0e14633c | 3179 | } |
e6989e10 | 3180 | |
2e7da20d | 3181 | __add_log_sample(iolog, elapsed, &sample); |
99007068 | 3182 | } |
99007068 | 3183 | |
d96d3bb3 JA |
3184 | reset_io_stat(&iolog->avg_window[ddir]); |
3185 | } | |
99007068 | 3186 | |
e6989e10 | 3187 | static void _add_stat_to_log(struct io_log *iolog, unsigned long elapsed, |
0e14633c | 3188 | int log_max) |
d96d3bb3 | 3189 | { |
2e545522 | 3190 | enum fio_ddir ddir; |
99007068 | 3191 | |
d96d3bb3 | 3192 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) |
03ec570f | 3193 | __add_stat_to_log(iolog, ddir, elapsed, log_max); |
99007068 PO |
3194 | } |
3195 | ||
674456bf JF |
3196 | static unsigned long add_log_sample(struct thread_data *td, |
3197 | struct io_log *iolog, | |
2e7da20d | 3198 | struct log_sample *sample) |
bb3884d8 | 3199 | { |
7fb28d36 | 3200 | unsigned long elapsed, this_window; |
2e7da20d | 3201 | enum fio_ddir ddir = sample->ddir; |
b8bc8cba | 3202 | |
ff58fced | 3203 | if (!ddir_rw(ddir)) |
d454a205 | 3204 | return 0; |
ff58fced | 3205 | |
b8bc8cba JA |
3206 | elapsed = mtime_since_now(&td->epoch); |
3207 | ||
3208 | /* | |
3209 | * If no time averaging, just add the log sample. | |
3210 | */ | |
3211 | if (!iolog->avg_msec) { | |
2e7da20d | 3212 | __add_log_sample(iolog, elapsed, sample); |
d454a205 | 3213 | return 0; |
b8bc8cba JA |
3214 | } |
3215 | ||
3216 | /* | |
3217 | * Add the sample. If the time period has passed, then | |
3218 | * add that entry to the log and clear. | |
3219 | */ | |
2e7da20d | 3220 | add_stat_sample(&iolog->avg_window[ddir], sample->data.val.val0); |
b8bc8cba | 3221 | |
7fb28d36 JA |
3222 | /* |
3223 | * If period hasn't passed, adding the above sample is all we | |
3224 | * need to do. | |
3225 | */ | |
8355119b SW |
3226 | this_window = elapsed - iolog->avg_last[ddir]; |
3227 | if (elapsed < iolog->avg_last[ddir]) | |
3228 | return iolog->avg_last[ddir] - elapsed; | |
f5a568cf | 3229 | else if (this_window < iolog->avg_msec) { |
674456bf | 3230 | unsigned long diff = iolog->avg_msec - this_window; |
d454a205 | 3231 | |
b392f36d | 3232 | if (inline_log(iolog) || diff > LOG_MSEC_SLACK) |
d454a205 JA |
3233 | return diff; |
3234 | } | |
b8bc8cba | 3235 | |
0e14633c | 3236 | __add_stat_to_log(iolog, ddir, elapsed, td->o.log_max); |
b8bc8cba | 3237 | |
58a2d29d JL |
3238 | iolog->avg_last[ddir] = elapsed - (elapsed % iolog->avg_msec); |
3239 | ||
d454a205 | 3240 | return iolog->avg_msec; |
99007068 | 3241 | } |
6eaf09d6 | 3242 | |
a47591e4 | 3243 | void finalize_logs(struct thread_data *td, bool unit_logs) |
99007068 PO |
3244 | { |
3245 | unsigned long elapsed; | |
6eaf09d6 | 3246 | |
99007068 | 3247 | elapsed = mtime_since_now(&td->epoch); |
b8bc8cba | 3248 | |
a47591e4 | 3249 | if (td->clat_log && unit_logs) |
0e14633c | 3250 | _add_stat_to_log(td->clat_log, elapsed, td->o.log_max); |
a47591e4 | 3251 | if (td->slat_log && unit_logs) |
0e14633c | 3252 | _add_stat_to_log(td->slat_log, elapsed, td->o.log_max); |
a47591e4 | 3253 | if (td->lat_log && unit_logs) |
0e14633c | 3254 | _add_stat_to_log(td->lat_log, elapsed, td->o.log_max); |
a47591e4 | 3255 | if (td->bw_log && (unit_logs == per_unit_log(td->bw_log))) |
0e14633c | 3256 | _add_stat_to_log(td->bw_log, elapsed, td->o.log_max); |
a47591e4 | 3257 | if (td->iops_log && (unit_logs == per_unit_log(td->iops_log))) |
0e14633c | 3258 | _add_stat_to_log(td->iops_log, elapsed, td->o.log_max); |
bb3884d8 JA |
3259 | } |
3260 | ||
03ec570f DLM |
3261 | void add_agg_sample(union io_sample_data data, enum fio_ddir ddir, |
3262 | unsigned long long bs) | |
bb3884d8 | 3263 | { |
ff58fced | 3264 | struct io_log *iolog; |
14d3134a | 3265 | struct log_sample sample = { data, ddir, bs, 0, 0, 0 }; |
bb3884d8 | 3266 | |
ff58fced JA |
3267 | if (!ddir_rw(ddir)) |
3268 | return; | |
3269 | ||
3270 | iolog = agg_io_log[ddir]; | |
2e7da20d | 3271 | __add_log_sample(iolog, mtime_since_genesis(), &sample); |
bb3884d8 JA |
3272 | } |
3273 | ||
b2b3eefe JA |
3274 | void add_sync_clat_sample(struct thread_stat *ts, unsigned long long nsec) |
3275 | { | |
3276 | unsigned int idx = plat_val_to_idx(nsec); | |
3277 | assert(idx < FIO_IO_U_PLAT_NR); | |
3278 | ||
3279 | ts->io_u_sync_plat[idx]++; | |
3280 | add_stat_sample(&ts->sync_stat, nsec); | |
3281 | } | |
3282 | ||
ed7f3a07 NC |
3283 | static inline void add_lat_percentile_sample(struct thread_stat *ts, |
3284 | unsigned long long nsec, | |
3285 | enum fio_ddir ddir, | |
3286 | enum fio_lat lat) | |
83349190 | 3287 | { |
d6bb626e | 3288 | unsigned int idx = plat_val_to_idx(nsec); |
83349190 YH |
3289 | assert(idx < FIO_IO_U_PLAT_NR); |
3290 | ||
56440e63 VF |
3291 | ts->io_u_plat[lat][ddir][idx]++; |
3292 | } | |
b2a432bf | 3293 | |
692dec0c NC |
3294 | static inline void |
3295 | add_lat_percentile_prio_sample(struct thread_stat *ts, unsigned long long nsec, | |
3296 | enum fio_ddir ddir, | |
3297 | unsigned short clat_prio_index) | |
56440e63 VF |
3298 | { |
3299 | unsigned int idx = plat_val_to_idx(nsec); | |
3300 | ||
692dec0c NC |
3301 | if (ts->clat_prio[ddir]) |
3302 | ts->clat_prio[ddir][clat_prio_index].io_u_plat[idx]++; | |
83349190 YH |
3303 | } |
3304 | ||
1e97cce9 | 3305 | void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, |
5fff9543 | 3306 | unsigned long long nsec, unsigned long long bs, |
ac18dd16 | 3307 | struct io_u *io_u) |
3c39a379 | 3308 | { |
26b3a188 | 3309 | const bool needs_lock = td_async_processing(td); |
1e613c9c | 3310 | unsigned long elapsed, this_window; |
756867bd | 3311 | struct thread_stat *ts = &td->ts; |
1e613c9c | 3312 | struct io_log *iolog = td->clat_hist_log; |
ac18dd16 SK |
3313 | uint64_t offset = 0; |
3314 | unsigned int ioprio = 0; | |
3315 | unsigned short clat_prio_index = 0; | |
079ad09b | 3316 | |
26b3a188 JA |
3317 | if (needs_lock) |
3318 | __td_io_u_lock(td); | |
75dc383e | 3319 | |
ac18dd16 SK |
3320 | if (io_u) { |
3321 | offset = io_u->offset; | |
3322 | ioprio = io_u->ioprio; | |
3323 | clat_prio_index = io_u->clat_prio_index; | |
3324 | } | |
3325 | ||
d6bb626e | 3326 | add_stat_sample(&ts->clat_stat[ddir], nsec); |
3c39a379 | 3327 | |
717569b1 | 3328 | /* |
692dec0c | 3329 | * When lat_percentiles=1 (default 0), the reported per priority |
717569b1 NC |
3330 | * percentiles and stats are used for describing total latency values, |
3331 | * even though the variable names themselves start with clat_. | |
3332 | * | |
3333 | * Because of the above definition, add a prio stat sample only when | |
3334 | * lat_percentiles=0. add_lat_sample() will add the prio stat sample | |
3335 | * when lat_percentiles=1. | |
3336 | */ | |
692dec0c NC |
3337 | if (!ts->lat_percentiles) |
3338 | add_stat_prio_sample(ts->clat_prio[ddir], clat_prio_index, | |
3339 | nsec); | |
b2a432bf | 3340 | |
2e7da20d SK |
3341 | if (td->clat_log) { |
3342 | struct log_sample sample = { sample_val(nsec), ddir, bs, | |
a0e2faaf SK |
3343 | offset, ioprio, 0 }; |
3344 | ||
3345 | if (io_u) | |
3346 | sample.issue_time = | |
3347 | ntime_since(&td->epoch, &io_u->issue_time); | |
2e7da20d SK |
3348 | |
3349 | add_log_sample(td, td->clat_log, &sample); | |
3350 | } | |
83349190 | 3351 | |
b2a432bf | 3352 | if (ts->clat_percentiles) { |
717569b1 NC |
3353 | /* |
3354 | * Because of the above definition, add a prio lat percentile | |
3355 | * sample only when lat_percentiles=0. add_lat_sample() will add | |
3356 | * the prio lat percentile sample when lat_percentiles=1. | |
3357 | */ | |
bf65f7c8 NC |
3358 | add_lat_percentile_sample(ts, nsec, ddir, FIO_CLAT); |
3359 | if (!ts->lat_percentiles) | |
3360 | add_lat_percentile_prio_sample(ts, nsec, ddir, | |
692dec0c | 3361 | clat_prio_index); |
b2a432bf | 3362 | } |
75dc383e | 3363 | |
1e613c9c | 3364 | if (iolog && iolog->hist_msec) { |
93168285 JA |
3365 | struct io_hist *hw = &iolog->hist_window[ddir]; |
3366 | ||
3367 | hw->samples++; | |
1e613c9c | 3368 | elapsed = mtime_since_now(&td->epoch); |
93168285 | 3369 | if (!hw->hist_last) |
1e613c9c KC |
3370 | hw->hist_last = elapsed; |
3371 | this_window = elapsed - hw->hist_last; | |
7a4e480d | 3372 | |
1e613c9c | 3373 | if (this_window >= iolog->hist_msec) { |
6cc0e5aa | 3374 | uint64_t *io_u_plat; |
65a4d15c | 3375 | struct io_u_plat_entry *dst; |
2e7da20d | 3376 | struct log_sample sample = { {{ 0, 0 }}, ddir, bs, |
14d3134a | 3377 | offset, ioprio, 0 }; |
93168285 | 3378 | |
1e613c9c | 3379 | /* |
93168285 JA |
3380 | * Make a byte-for-byte copy of the latency histogram |
3381 | * stored in td->ts.io_u_plat[ddir], recording it in a | |
3382 | * log sample. Note that the matching call to free() is | |
3383 | * located in iolog.c after printing this sample to the | |
3384 | * log file. | |
1e613c9c | 3385 | */ |
df8781b6 | 3386 | io_u_plat = (uint64_t *) td->ts.io_u_plat[FIO_CLAT][ddir]; |
65a4d15c KC |
3387 | dst = malloc(sizeof(struct io_u_plat_entry)); |
3388 | memcpy(&(dst->io_u_plat), io_u_plat, | |
1fb9250b | 3389 | FIO_IO_U_PLAT_NR * sizeof(uint64_t)); |
d730bc58 | 3390 | flist_add(&dst->list, &hw->list); |
2e7da20d SK |
3391 | |
3392 | sample.data = sample_plat(dst); | |
3393 | __add_log_sample(iolog, elapsed, &sample); | |
1e613c9c KC |
3394 | |
3395 | /* | |
93168285 JA |
3396 | * Update the last time we recorded as being now, minus |
3397 | * any drift in time we encountered before actually | |
3398 | * making the record. | |
1e613c9c KC |
3399 | */ |
3400 | hw->hist_last = elapsed - (this_window - iolog->hist_msec); | |
3401 | hw->samples = 0; | |
3402 | } | |
3403 | } | |
3404 | ||
26b3a188 JA |
3405 | if (needs_lock) |
3406 | __td_io_u_unlock(td); | |
3c39a379 JA |
3407 | } |
3408 | ||
ac18dd16 | 3409 | void add_slat_sample(struct thread_data *td, struct io_u *io_u) |
3c39a379 | 3410 | { |
26b3a188 | 3411 | const bool needs_lock = td_async_processing(td); |
756867bd | 3412 | struct thread_stat *ts = &td->ts; |
ac18dd16 SK |
3413 | enum fio_ddir ddir; |
3414 | unsigned long long nsec; | |
079ad09b | 3415 | |
ac18dd16 | 3416 | ddir = io_u->ddir; |
ff58fced JA |
3417 | if (!ddir_rw(ddir)) |
3418 | return; | |
3419 | ||
26b3a188 JA |
3420 | if (needs_lock) |
3421 | __td_io_u_lock(td); | |
75dc383e | 3422 | |
ac18dd16 SK |
3423 | nsec = ntime_since(&io_u->start_time, &io_u->issue_time); |
3424 | ||
56440e63 | 3425 | add_stat_sample(&ts->slat_stat[ddir], nsec); |
3c39a379 | 3426 | |
2e7da20d SK |
3427 | if (td->slat_log) { |
3428 | struct log_sample sample = { sample_val(nsec), ddir, | |
14d3134a SK |
3429 | io_u->xfer_buflen, io_u->offset, io_u->ioprio, |
3430 | ntime_since(&td->epoch, &io_u->issue_time) }; | |
2e7da20d SK |
3431 | |
3432 | add_log_sample(td, td->slat_log, &sample); | |
3433 | } | |
75dc383e | 3434 | |
56440e63 | 3435 | if (ts->slat_percentiles) |
3dd92a75 | 3436 | add_lat_percentile_sample(ts, nsec, ddir, FIO_SLAT); |
56440e63 | 3437 | |
26b3a188 JA |
3438 | if (needs_lock) |
3439 | __td_io_u_unlock(td); | |
3c39a379 JA |
3440 | } |
3441 | ||
02af0988 | 3442 | void add_lat_sample(struct thread_data *td, enum fio_ddir ddir, |
5fff9543 | 3443 | unsigned long long nsec, unsigned long long bs, |
ac18dd16 | 3444 | struct io_u * io_u) |
02af0988 | 3445 | { |
26b3a188 | 3446 | const bool needs_lock = td_async_processing(td); |
02af0988 JA |
3447 | struct thread_stat *ts = &td->ts; |
3448 | ||
ff58fced JA |
3449 | if (!ddir_rw(ddir)) |
3450 | return; | |
3451 | ||
26b3a188 JA |
3452 | if (needs_lock) |
3453 | __td_io_u_lock(td); | |
75dc383e | 3454 | |
d6bb626e | 3455 | add_stat_sample(&ts->lat_stat[ddir], nsec); |
02af0988 | 3456 | |
2e7da20d SK |
3457 | if (td->lat_log) { |
3458 | struct log_sample sample = { sample_val(nsec), ddir, bs, | |
14d3134a | 3459 | io_u->offset, io_u->ioprio, 0 }; |
2e7da20d SK |
3460 | |
3461 | add_log_sample(td, td->lat_log, &sample); | |
3462 | } | |
75dc383e | 3463 | |
717569b1 | 3464 | /* |
692dec0c | 3465 | * When lat_percentiles=1 (default 0), the reported per priority |
717569b1 NC |
3466 | * percentiles and stats are used for describing total latency values, |
3467 | * even though the variable names themselves start with clat_. | |
3468 | * | |
3469 | * Because of the above definition, add a prio stat and prio lat | |
3470 | * percentile sample only when lat_percentiles=1. add_clat_sample() will | |
3471 | * add the prio stat and prio lat percentile sample when | |
3472 | * lat_percentiles=0. | |
3473 | */ | |
38ec5c51 | 3474 | if (ts->lat_percentiles) { |
bf65f7c8 | 3475 | add_lat_percentile_sample(ts, nsec, ddir, FIO_LAT); |
ac18dd16 SK |
3476 | add_lat_percentile_prio_sample(ts, nsec, ddir, |
3477 | io_u->clat_prio_index); | |
3478 | add_stat_prio_sample(ts->clat_prio[ddir], io_u->clat_prio_index, | |
692dec0c | 3479 | nsec); |
38ec5c51 | 3480 | } |
26b3a188 JA |
3481 | if (needs_lock) |
3482 | __td_io_u_unlock(td); | |
02af0988 JA |
3483 | } |
3484 | ||
a47591e4 | 3485 | void add_bw_sample(struct thread_data *td, struct io_u *io_u, |
d6bb626e | 3486 | unsigned int bytes, unsigned long long spent) |
a47591e4 | 3487 | { |
26b3a188 | 3488 | const bool needs_lock = td_async_processing(td); |
a47591e4 JA |
3489 | struct thread_stat *ts = &td->ts; |
3490 | unsigned long rate; | |
3491 | ||
3492 | if (spent) | |
d6bb626e | 3493 | rate = (unsigned long) (bytes * 1000000ULL / spent); |
a47591e4 JA |
3494 | else |
3495 | rate = 0; | |
3496 | ||
26b3a188 JA |
3497 | if (needs_lock) |
3498 | __td_io_u_lock(td); | |
a47591e4 JA |
3499 | |
3500 | add_stat_sample(&ts->bw_stat[io_u->ddir], rate); | |
3501 | ||
2e7da20d SK |
3502 | if (td->bw_log) { |
3503 | struct log_sample sample = { sample_val(rate), io_u->ddir, | |
14d3134a | 3504 | bytes, io_u->offset, io_u->ioprio, 0 }; |
2e7da20d SK |
3505 | |
3506 | add_log_sample(td, td->bw_log, &sample); | |
3507 | } | |
a47591e4 JA |
3508 | |
3509 | td->stat_io_bytes[io_u->ddir] = td->this_io_bytes[io_u->ddir]; | |
26b3a188 JA |
3510 | |
3511 | if (needs_lock) | |
3512 | __td_io_u_unlock(td); | |
a47591e4 JA |
3513 | } |
3514 | ||
8b6a404c VF |
3515 | static int __add_samples(struct thread_data *td, struct timespec *parent_tv, |
3516 | struct timespec *t, unsigned int avg_time, | |
4843277a JA |
3517 | uint64_t *this_io_bytes, uint64_t *stat_io_bytes, |
3518 | struct io_stat *stat, struct io_log *log, | |
3519 | bool is_kb) | |
3c39a379 | 3520 | { |
26b3a188 | 3521 | const bool needs_lock = td_async_processing(td); |
ff58fced | 3522 | unsigned long spent, rate; |
a47591e4 | 3523 | enum fio_ddir ddir; |
674456bf | 3524 | unsigned long next, next_log; |
d454a205 | 3525 | |
4843277a | 3526 | next_log = avg_time; |
ff58fced | 3527 | |
4843277a | 3528 | spent = mtime_since(parent_tv, t); |
58a2d29d | 3529 | if (spent < avg_time && avg_time - spent > LOG_MSEC_SLACK) |
4843277a | 3530 | return avg_time - spent; |
9602d8df | 3531 | |
26b3a188 JA |
3532 | if (needs_lock) |
3533 | __td_io_u_lock(td); | |
a9da8ab2 | 3534 | |
9602d8df | 3535 | /* |
5daa4ebe JC |
3536 | * Compute both read and write rates for the interval. |
3537 | */ | |
c1f50f76 | 3538 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
5daa4ebe JC |
3539 | uint64_t delta; |
3540 | ||
4843277a | 3541 | delta = this_io_bytes[ddir] - stat_io_bytes[ddir]; |
5daa4ebe JC |
3542 | if (!delta) |
3543 | continue; /* No entries for interval */ | |
3c39a379 | 3544 | |
4843277a JA |
3545 | if (spent) { |
3546 | if (is_kb) | |
3547 | rate = delta * 1000 / spent / 1024; /* KiB/s */ | |
3548 | else | |
3549 | rate = (delta * 1000) / spent; | |
3550 | } else | |
0956264f JA |
3551 | rate = 0; |
3552 | ||
4843277a | 3553 | add_stat_sample(&stat[ddir], rate); |
3c39a379 | 3554 | |
37181709 | 3555 | if (log) { |
2e7da20d | 3556 | struct log_sample sample = { |
14d3134a | 3557 | sample_val(rate), ddir, 0, 0, 0, 0 }; |
66b98c9f JA |
3558 | |
3559 | if (td->o.min_bs[ddir] == td->o.max_bs[ddir]) | |
2e7da20d SK |
3560 | sample.bs = td->o.min_bs[ddir]; |
3561 | next = add_log_sample(td, log, &sample); | |
d454a205 | 3562 | next_log = min(next_log, next); |
66b98c9f | 3563 | } |
5daa4ebe | 3564 | |
4843277a | 3565 | stat_io_bytes[ddir] = this_io_bytes[ddir]; |
5daa4ebe | 3566 | } |
3c39a379 | 3567 | |
cdb8308d | 3568 | *parent_tv = *t; |
a47591e4 | 3569 | |
26b3a188 JA |
3570 | if (needs_lock) |
3571 | __td_io_u_unlock(td); | |
a47591e4 | 3572 | |
4843277a JA |
3573 | if (spent <= avg_time) |
3574 | next = avg_time; | |
306fea38 | 3575 | else |
4843277a | 3576 | next = avg_time - (1 + spent - avg_time); |
a47591e4 | 3577 | |
d454a205 | 3578 | return min(next, next_log); |
a47591e4 JA |
3579 | } |
3580 | ||
8b6a404c | 3581 | static int add_bw_samples(struct thread_data *td, struct timespec *t) |
4843277a JA |
3582 | { |
3583 | return __add_samples(td, &td->bw_sample_time, t, td->o.bw_avg_time, | |
3584 | td->this_io_bytes, td->stat_io_bytes, | |
3585 | td->ts.bw_stat, td->bw_log, true); | |
3586 | } | |
3587 | ||
a47591e4 JA |
3588 | void add_iops_sample(struct thread_data *td, struct io_u *io_u, |
3589 | unsigned int bytes) | |
3590 | { | |
26b3a188 | 3591 | const bool needs_lock = td_async_processing(td); |
a47591e4 JA |
3592 | struct thread_stat *ts = &td->ts; |
3593 | ||
26b3a188 JA |
3594 | if (needs_lock) |
3595 | __td_io_u_lock(td); | |
a47591e4 JA |
3596 | |
3597 | add_stat_sample(&ts->iops_stat[io_u->ddir], 1); | |
3598 | ||
2e7da20d SK |
3599 | if (td->iops_log) { |
3600 | struct log_sample sample = { sample_val(1), io_u->ddir, bytes, | |
14d3134a | 3601 | io_u->offset, io_u->ioprio, 0 }; |
2e7da20d SK |
3602 | |
3603 | add_log_sample(td, td->iops_log, &sample); | |
3604 | } | |
a47591e4 JA |
3605 | |
3606 | td->stat_io_blocks[io_u->ddir] = td->this_io_blocks[io_u->ddir]; | |
26b3a188 JA |
3607 | |
3608 | if (needs_lock) | |
3609 | __td_io_u_unlock(td); | |
3c39a379 | 3610 | } |
c8eeb9df | 3611 | |
8b6a404c | 3612 | static int add_iops_samples(struct thread_data *td, struct timespec *t) |
c8eeb9df | 3613 | { |
4843277a JA |
3614 | return __add_samples(td, &td->iops_sample_time, t, td->o.iops_avg_time, |
3615 | td->this_io_blocks, td->stat_io_blocks, | |
3616 | td->ts.iops_stat, td->iops_log, false); | |
a47591e4 JA |
3617 | } |
3618 | ||
ba03f5af VF |
3619 | static bool td_in_logging_state(struct thread_data *td) |
3620 | { | |
3621 | if (in_ramp_time(td)) | |
3622 | return false; | |
3623 | ||
3624 | switch(td->runstate) { | |
3625 | case TD_RUNNING: | |
3626 | case TD_VERIFYING: | |
3627 | case TD_FINISHING: | |
3628 | case TD_EXITED: | |
3629 | return true; | |
3630 | default: | |
3631 | return false; | |
3632 | } | |
3633 | } | |
3634 | ||
a47591e4 JA |
3635 | /* |
3636 | * Returns msecs to next event | |
3637 | */ | |
3638 | int calc_log_samples(void) | |
3639 | { | |
58a2d29d | 3640 | unsigned int next = ~0U, tmp = 0, next_mod = 0, log_avg_msec_min = -1U; |
8b6a404c | 3641 | struct timespec now; |
58a2d29d | 3642 | long elapsed_time = 0; |
a47591e4 | 3643 | |
da8f124f | 3644 | for_each_td(td) { |
d09dcd34 VF |
3645 | fio_gettime(&now, NULL); |
3646 | elapsed_time = mtime_since(&td->epoch, &now); | |
58a2d29d | 3647 | |
8243be59 JA |
3648 | if (!td->o.stats) |
3649 | continue; | |
ba03f5af | 3650 | if (!td_in_logging_state(td)) { |
a47591e4 JA |
3651 | next = min(td->o.iops_avg_time, td->o.bw_avg_time); |
3652 | continue; | |
3653 | } | |
37181709 AH |
3654 | if (!td->bw_log || |
3655 | (td->bw_log && !per_unit_log(td->bw_log))) { | |
a47591e4 | 3656 | tmp = add_bw_samples(td, &now); |
58a2d29d JL |
3657 | |
3658 | if (td->bw_log) | |
3659 | log_avg_msec_min = min(log_avg_msec_min, (unsigned int)td->bw_log->avg_msec); | |
a47591e4 | 3660 | } |
37181709 AH |
3661 | if (!td->iops_log || |
3662 | (td->iops_log && !per_unit_log(td->iops_log))) { | |
a47591e4 | 3663 | tmp = add_iops_samples(td, &now); |
58a2d29d JL |
3664 | |
3665 | if (td->iops_log) | |
3666 | log_avg_msec_min = min(log_avg_msec_min, (unsigned int)td->iops_log->avg_msec); | |
a47591e4 | 3667 | } |
58a2d29d JL |
3668 | |
3669 | if (tmp < next) | |
3670 | next = tmp; | |
da8f124f | 3671 | } end_for_each(); |
a47591e4 | 3672 | |
58a2d29d JL |
3673 | /* if log_avg_msec_min has not been changed, set it to 0 */ |
3674 | if (log_avg_msec_min == -1U) | |
3675 | log_avg_msec_min = 0; | |
3676 | ||
3677 | if (log_avg_msec_min == 0) | |
3678 | next_mod = elapsed_time; | |
3679 | else | |
3680 | next_mod = elapsed_time % log_avg_msec_min; | |
3681 | ||
3682 | /* correction to keep the time on the log avg msec boundary */ | |
3683 | next = min(next, (log_avg_msec_min - next_mod)); | |
3684 | ||
a47591e4 | 3685 | return next == ~0U ? 0 : next; |
c8eeb9df | 3686 | } |
cef9175e JA |
3687 | |
3688 | void stat_init(void) | |
3689 | { | |
971caeb1 | 3690 | stat_sem = fio_sem_init(FIO_SEM_UNLOCKED); |
cef9175e JA |
3691 | } |
3692 | ||
3693 | void stat_exit(void) | |
3694 | { | |
3695 | /* | |
3696 | * When we have the mutex, we know out-of-band access to it | |
3697 | * have ended. | |
3698 | */ | |
971caeb1 BVA |
3699 | fio_sem_down(stat_sem); |
3700 | fio_sem_remove(stat_sem); | |
cef9175e | 3701 | } |
b2ee7647 | 3702 | |
b2ee7647 JA |
3703 | /* |
3704 | * Called from signal handler. Wake up status thread. | |
3705 | */ | |
3706 | void show_running_run_stats(void) | |
3707 | { | |
a47591e4 | 3708 | helper_do_stat(); |
b2ee7647 | 3709 | } |
66347cfa DE |
3710 | |
3711 | uint32_t *io_u_block_info(struct thread_data *td, struct io_u *io_u) | |
3712 | { | |
3713 | /* Ignore io_u's which span multiple blocks--they will just get | |
3714 | * inaccurate counts. */ | |
3715 | int idx = (io_u->offset - io_u->file->file_offset) | |
3716 | / td->o.bs[DDIR_TRIM]; | |
3717 | uint32_t *info = &td->ts.block_infos[idx]; | |
3718 | assert(idx < td->ts.nr_block_infos); | |
3719 | return info; | |
3720 | } | |
5c0abd5e | 3721 |