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