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