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" |
3c39a379 | 16 | |
3c39a379 JA |
17 | void update_rusage_stat(struct thread_data *td) |
18 | { | |
756867bd | 19 | struct thread_stat *ts = &td->ts; |
3c39a379 | 20 | |
44404c5a | 21 | fio_getrusage(&td->ru_end); |
c8aaba19 JA |
22 | ts->usr_time += mtime_since(&td->ru_start.ru_utime, |
23 | &td->ru_end.ru_utime); | |
24 | ts->sys_time += mtime_since(&td->ru_start.ru_stime, | |
25 | &td->ru_end.ru_stime); | |
26 | ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw | |
27 | - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw); | |
28 | ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt; | |
29 | ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt; | |
5ec10eaa | 30 | |
c8aaba19 | 31 | memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end)); |
3c39a379 JA |
32 | } |
33 | ||
83349190 YH |
34 | /* |
35 | * Given a latency, return the index of the corresponding bucket in | |
36 | * the structure tracking percentiles. | |
37 | * | |
38 | * (1) find the group (and error bits) that the value (latency) | |
39 | * belongs to by looking at its MSB. (2) find the bucket number in the | |
40 | * group by looking at the index bits. | |
41 | * | |
42 | */ | |
43 | static unsigned int plat_val_to_idx(unsigned int val) | |
44 | { | |
45 | unsigned int msb, error_bits, base, offset, idx; | |
46 | ||
47 | /* Find MSB starting from bit 0 */ | |
48 | if (val == 0) | |
49 | msb = 0; | |
50 | else | |
51 | msb = (sizeof(val)*8) - __builtin_clz(val) - 1; | |
52 | ||
716050f2 JA |
53 | /* |
54 | * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use | |
55 | * all bits of the sample as index | |
56 | */ | |
83349190 YH |
57 | if (msb <= FIO_IO_U_PLAT_BITS) |
58 | return val; | |
59 | ||
60 | /* Compute the number of error bits to discard*/ | |
61 | error_bits = msb - FIO_IO_U_PLAT_BITS; | |
62 | ||
63 | /* Compute the number of buckets before the group */ | |
64 | base = (error_bits + 1) << FIO_IO_U_PLAT_BITS; | |
65 | ||
716050f2 JA |
66 | /* |
67 | * Discard the error bits and apply the mask to find the | |
68 | * index for the buckets in the group | |
69 | */ | |
83349190 YH |
70 | offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits); |
71 | ||
72 | /* Make sure the index does not exceed (array size - 1) */ | |
73 | idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1)? | |
74 | (base + offset) : (FIO_IO_U_PLAT_NR - 1); | |
75 | ||
76 | return idx; | |
77 | } | |
78 | ||
79 | /* | |
80 | * Convert the given index of the bucket array to the value | |
81 | * represented by the bucket | |
82 | */ | |
83 | static unsigned int plat_idx_to_val(unsigned int idx) | |
84 | { | |
85 | unsigned int error_bits, k, base; | |
86 | ||
87 | assert(idx < FIO_IO_U_PLAT_NR); | |
88 | ||
89 | /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use | |
90 | * all bits of the sample as index */ | |
91 | if (idx < (FIO_IO_U_PLAT_VAL << 1) ) | |
92 | return idx; | |
93 | ||
94 | /* Find the group and compute the minimum value of that group */ | |
95 | error_bits = (idx >> FIO_IO_U_PLAT_BITS) -1; | |
96 | base = 1 << (error_bits + FIO_IO_U_PLAT_BITS); | |
97 | ||
98 | /* Find its bucket number of the group */ | |
99 | k = idx % FIO_IO_U_PLAT_VAL; | |
100 | ||
101 | /* Return the mean of the range of the bucket */ | |
102 | return base + ((k + 0.5) * (1 << error_bits)); | |
103 | } | |
104 | ||
105 | static int double_cmp(const void *a, const void *b) | |
106 | { | |
802ad4a8 JA |
107 | const fio_fp64_t fa = *(const fio_fp64_t *) a; |
108 | const fio_fp64_t fb = *(const fio_fp64_t *) b; | |
83349190 YH |
109 | int cmp = 0; |
110 | ||
802ad4a8 | 111 | if (fa.u.f > fb.u.f) |
83349190 | 112 | cmp = 1; |
802ad4a8 | 113 | else if (fa.u.f < fb.u.f) |
83349190 YH |
114 | cmp = -1; |
115 | ||
116 | return cmp; | |
117 | } | |
118 | ||
1db92cb6 JA |
119 | static unsigned int calc_clat_percentiles(unsigned int *io_u_plat, |
120 | unsigned long nr, fio_fp64_t *plist, | |
121 | unsigned int **output, | |
122 | unsigned int *maxv, | |
123 | unsigned int *minv) | |
83349190 YH |
124 | { |
125 | unsigned long sum = 0; | |
1db92cb6 JA |
126 | unsigned int len, i, j = 0; |
127 | unsigned int oval_len = 0; | |
128 | unsigned int *ovals = NULL; | |
129 | int is_last; | |
130 | ||
131 | *minv = -1U; | |
132 | *maxv = 0; | |
83349190 | 133 | |
802ad4a8 JA |
134 | len = 0; |
135 | while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0) | |
136 | len++; | |
716050f2 | 137 | |
351de8de | 138 | if (!len) |
1db92cb6 | 139 | return 0; |
351de8de | 140 | |
716050f2 | 141 | /* |
802ad4a8 JA |
142 | * Sort the percentile list. Note that it may already be sorted if |
143 | * we are using the default values, but since it's a short list this | |
144 | * isn't a worry. Also note that this does not work for NaN values. | |
716050f2 | 145 | */ |
802ad4a8 JA |
146 | if (len > 1) |
147 | qsort((void*)plist, len, sizeof(plist[0]), double_cmp); | |
83349190 | 148 | |
4f6f8298 JA |
149 | /* |
150 | * Calculate bucket values, note down max and min values | |
151 | */ | |
07511a63 JA |
152 | is_last = 0; |
153 | for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) { | |
83349190 | 154 | sum += io_u_plat[i]; |
802ad4a8 JA |
155 | while (sum >= (plist[j].u.f / 100.0 * nr)) { |
156 | assert(plist[j].u.f <= 100.0); | |
83349190 | 157 | |
4f6f8298 JA |
158 | if (j == oval_len) { |
159 | oval_len += 100; | |
160 | ovals = realloc(ovals, oval_len * sizeof(unsigned int)); | |
161 | } | |
162 | ||
163 | ovals[j] = plat_idx_to_val(i); | |
1db92cb6 JA |
164 | if (ovals[j] < *minv) |
165 | *minv = ovals[j]; | |
166 | if (ovals[j] > *maxv) | |
167 | *maxv = ovals[j]; | |
07511a63 JA |
168 | |
169 | is_last = (j == len - 1); | |
170 | if (is_last) | |
171 | break; | |
172 | ||
4f6f8298 JA |
173 | j++; |
174 | } | |
175 | } | |
83349190 | 176 | |
1db92cb6 JA |
177 | *output = ovals; |
178 | return len; | |
179 | } | |
180 | ||
181 | /* | |
182 | * Find and display the p-th percentile of clat | |
183 | */ | |
184 | static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr, | |
185 | fio_fp64_t *plist) | |
186 | { | |
187 | unsigned int len, j = 0, minv, maxv; | |
188 | unsigned int *ovals; | |
189 | int is_last, scale_down; | |
190 | ||
191 | len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv); | |
192 | if (!len) | |
193 | goto out; | |
194 | ||
4f6f8298 JA |
195 | /* |
196 | * We default to usecs, but if the value range is such that we | |
197 | * should scale down to msecs, do that. | |
198 | */ | |
199 | if (minv > 2000 && maxv > 99999) { | |
200 | scale_down = 1; | |
201 | log_info(" clat percentiles (msec):\n |"); | |
202 | } else { | |
203 | scale_down = 0; | |
204 | log_info(" clat percentiles (usec):\n |"); | |
205 | } | |
83349190 | 206 | |
4f6f8298 JA |
207 | for (j = 0; j < len; j++) { |
208 | char fbuf[8]; | |
81ab0b3a | 209 | |
4f6f8298 JA |
210 | /* for formatting */ |
211 | if (j != 0 && (j % 4) == 0) | |
212 | log_info(" |"); | |
83349190 | 213 | |
4f6f8298 JA |
214 | /* end of the list */ |
215 | is_last = (j == len - 1); | |
83349190 | 216 | |
4f6f8298 JA |
217 | if (plist[j].u.f < 10.0) |
218 | sprintf(fbuf, " %2.2f", plist[j].u.f); | |
219 | else | |
220 | sprintf(fbuf, "%2.2f", plist[j].u.f); | |
221 | ||
222 | if (scale_down) | |
223 | ovals[j] = (ovals[j] + 999) / 1000; | |
224 | ||
225 | log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ','); | |
226 | ||
227 | if (is_last) | |
228 | break; | |
229 | ||
230 | if (j % 4 == 3) /* for formatting */ | |
231 | log_info("\n"); | |
83349190 | 232 | } |
4f6f8298 | 233 | |
1db92cb6 | 234 | out: |
4f6f8298 JA |
235 | if (ovals) |
236 | free(ovals); | |
83349190 YH |
237 | } |
238 | ||
3c39a379 JA |
239 | static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max, |
240 | double *mean, double *dev) | |
241 | { | |
68704084 | 242 | double n = is->samples; |
3c39a379 JA |
243 | |
244 | if (is->samples == 0) | |
245 | return 0; | |
246 | ||
247 | *min = is->min_val; | |
248 | *max = is->max_val; | |
249 | ||
250 | n = (double) is->samples; | |
802ad4a8 | 251 | *mean = is->mean.u.f; |
e6d276f2 | 252 | |
68704084 | 253 | if (n > 1.0) |
802ad4a8 | 254 | *dev = sqrt(is->S.u.f / (n - 1.0)); |
ef9c5c40 | 255 | else |
4b43f54e | 256 | *dev = 0; |
ef9c5c40 | 257 | |
3c39a379 JA |
258 | return 1; |
259 | } | |
260 | ||
a64e88da | 261 | void show_group_stats(struct group_run_stats *rs) |
3c39a379 | 262 | { |
dbe1125e | 263 | char *p1, *p2, *p3, *p4; |
6eaf09d6 | 264 | const char *ddir_str[] = { " READ", " WRITE" , " TRIM"}; |
dbe1125e JA |
265 | int i; |
266 | ||
7e1773ba | 267 | log_info("\nRun status group %d (all jobs):\n", rs->groupid); |
3c39a379 | 268 | |
6eaf09d6 | 269 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
90fef2d1 JA |
270 | const int i2p = is_power_of_2(rs->kb_base); |
271 | ||
dbe1125e JA |
272 | if (!rs->max_run[i]) |
273 | continue; | |
274 | ||
90fef2d1 JA |
275 | p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p); |
276 | p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p); | |
277 | p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p); | |
278 | p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p); | |
dbe1125e | 279 | |
b22989b9 | 280 | log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s," |
771e58be JA |
281 | " mint=%llumsec, maxt=%llumsec\n", |
282 | rs->unified_rw_rep ? " MIXED" : ddir_str[i], | |
283 | p1, p2, p3, p4, rs->min_run[i], rs->max_run[i]); | |
dbe1125e JA |
284 | |
285 | free(p1); | |
286 | free(p2); | |
287 | free(p3); | |
288 | free(p4); | |
289 | } | |
3c39a379 JA |
290 | } |
291 | ||
b3605062 | 292 | #define ts_total_io_u(ts) \ |
6eaf09d6 SL |
293 | ((ts)->total_io_u[DDIR_READ] + (ts)->total_io_u[DDIR_WRITE] +\ |
294 | (ts)->total_io_u[DDIR_TRIM]) | |
b3605062 | 295 | |
838bc709 JA |
296 | static void stat_calc_dist(unsigned int *map, unsigned long total, |
297 | double *io_u_dist) | |
2270890c JA |
298 | { |
299 | int i; | |
300 | ||
301 | /* | |
302 | * Do depth distribution calculations | |
303 | */ | |
304 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { | |
838bc709 JA |
305 | if (total) { |
306 | io_u_dist[i] = (double) map[i] / (double) total; | |
307 | io_u_dist[i] *= 100.0; | |
308 | if (io_u_dist[i] < 0.1 && map[i]) | |
309 | io_u_dist[i] = 0.1; | |
310 | } else | |
311 | io_u_dist[i] = 0.0; | |
2270890c JA |
312 | } |
313 | } | |
314 | ||
04a0feae JA |
315 | static void stat_calc_lat(struct thread_stat *ts, double *dst, |
316 | unsigned int *src, int nr) | |
2270890c | 317 | { |
838bc709 | 318 | unsigned long total = ts_total_io_u(ts); |
2270890c JA |
319 | int i; |
320 | ||
321 | /* | |
322 | * Do latency distribution calculations | |
323 | */ | |
04a0feae | 324 | for (i = 0; i < nr; i++) { |
838bc709 JA |
325 | if (total) { |
326 | dst[i] = (double) src[i] / (double) total; | |
327 | dst[i] *= 100.0; | |
328 | if (dst[i] < 0.01 && src[i]) | |
329 | dst[i] = 0.01; | |
330 | } else | |
331 | dst[i] = 0.0; | |
2270890c JA |
332 | } |
333 | } | |
334 | ||
04a0feae JA |
335 | static void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat) |
336 | { | |
337 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR); | |
338 | } | |
339 | ||
340 | static void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat) | |
341 | { | |
342 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR); | |
343 | } | |
344 | ||
ea2accc5 JA |
345 | static int usec_to_msec(unsigned long *min, unsigned long *max, double *mean, |
346 | double *dev) | |
347 | { | |
348 | if (*min > 1000 && *max > 1000 && *mean > 1000.0 && *dev > 1000.0) { | |
349 | *min /= 1000; | |
350 | *max /= 1000; | |
351 | *mean /= 1000.0; | |
352 | *dev /= 1000.0; | |
353 | return 0; | |
354 | } | |
355 | ||
356 | return 1; | |
357 | } | |
358 | ||
756867bd | 359 | static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, |
3c39a379 JA |
360 | int ddir) |
361 | { | |
6eaf09d6 | 362 | const char *ddir_str[] = { "read ", "write", "trim" }; |
8879fd15 | 363 | unsigned long min, max, runt; |
b3605062 | 364 | unsigned long long bw, iops; |
3c39a379 | 365 | double mean, dev; |
b3605062 | 366 | char *io_p, *bw_p, *iops_p; |
90fef2d1 | 367 | int i2p; |
3c39a379 | 368 | |
ff58fced JA |
369 | assert(ddir_rw(ddir)); |
370 | ||
756867bd | 371 | if (!ts->runtime[ddir]) |
3c39a379 JA |
372 | return; |
373 | ||
90fef2d1 | 374 | i2p = is_power_of_2(rs->kb_base); |
8879fd15 JA |
375 | runt = ts->runtime[ddir]; |
376 | ||
377 | bw = (1000 * ts->io_bytes[ddir]) / runt; | |
90fef2d1 JA |
378 | io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p); |
379 | bw_p = num2str(bw, 6, 1, i2p); | |
8879fd15 | 380 | |
0aacc50c | 381 | iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt; |
b3605062 | 382 | iops_p = num2str(iops, 6, 1, 0); |
dbe1125e | 383 | |
cda99fa0 | 384 | log_info(" %s: io=%sB, bw=%sB/s, iops=%s, runt=%6llumsec\n", |
771e58be JA |
385 | rs->unified_rw_rep ? "mixed" : ddir_str[ddir], |
386 | io_p, bw_p, iops_p, ts->runtime[ddir]); | |
dbe1125e JA |
387 | |
388 | free(io_p); | |
389 | free(bw_p); | |
b3605062 | 390 | free(iops_p); |
3c39a379 | 391 | |
d85f5118 JA |
392 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) { |
393 | const char *base = "(usec)"; | |
d9309cb1 | 394 | char *minp, *maxp; |
d85f5118 | 395 | |
ea2accc5 | 396 | if (!usec_to_msec(&min, &max, &mean, &dev)) |
d85f5118 | 397 | base = "(msec)"; |
ea2accc5 | 398 | |
d9309cb1 JA |
399 | minp = num2str(min, 6, 1, 0); |
400 | maxp = num2str(max, 6, 1, 0); | |
401 | ||
5ec10eaa JA |
402 | log_info(" slat %s: min=%s, max=%s, avg=%5.02f," |
403 | " stdev=%5.02f\n", base, minp, maxp, mean, dev); | |
d9309cb1 JA |
404 | |
405 | free(minp); | |
406 | free(maxp); | |
d85f5118 JA |
407 | } |
408 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) { | |
409 | const char *base = "(usec)"; | |
d9309cb1 | 410 | char *minp, *maxp; |
d85f5118 | 411 | |
ea2accc5 JA |
412 | if (!usec_to_msec(&min, &max, &mean, &dev)) |
413 | base = "(msec)"; | |
414 | ||
d9309cb1 JA |
415 | minp = num2str(min, 6, 1, 0); |
416 | maxp = num2str(max, 6, 1, 0); | |
5ec10eaa JA |
417 | |
418 | log_info(" clat %s: min=%s, max=%s, avg=%5.02f," | |
419 | " stdev=%5.02f\n", base, minp, maxp, mean, dev); | |
d9309cb1 JA |
420 | |
421 | free(minp); | |
422 | free(maxp); | |
d85f5118 | 423 | } |
02af0988 JA |
424 | if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) { |
425 | const char *base = "(usec)"; | |
426 | char *minp, *maxp; | |
427 | ||
428 | if (!usec_to_msec(&min, &max, &mean, &dev)) | |
429 | base = "(msec)"; | |
430 | ||
431 | minp = num2str(min, 6, 1, 0); | |
432 | maxp = num2str(max, 6, 1, 0); | |
433 | ||
434 | log_info(" lat %s: min=%s, max=%s, avg=%5.02f," | |
435 | " stdev=%5.02f\n", base, minp, maxp, mean, dev); | |
436 | ||
437 | free(minp); | |
438 | free(maxp); | |
439 | } | |
83349190 YH |
440 | if (ts->clat_percentiles) { |
441 | show_clat_percentiles(ts->io_u_plat[ddir], | |
442 | ts->clat_stat[ddir].samples, | |
443 | ts->percentile_list); | |
444 | } | |
079ad09b | 445 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
19d3e967 | 446 | double p_of_agg = 100.0; |
b7017e32 | 447 | const char *bw_str = "KB"; |
3c39a379 | 448 | |
2f2c6924 | 449 | if (rs->agg[ddir]) { |
19d3e967 JA |
450 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; |
451 | if (p_of_agg > 100.0) | |
452 | p_of_agg = 100.0; | |
453 | } | |
b7017e32 JA |
454 | |
455 | if (mean > 999999.9) { | |
456 | min /= 1000.0; | |
457 | max /= 1000.0; | |
458 | mean /= 1000.0; | |
459 | dev /= 1000.0; | |
460 | bw_str = "MB"; | |
461 | } | |
462 | ||
7e1773ba | 463 | log_info(" bw (%s/s) : min=%5lu, max=%5lu, per=%3.2f%%," |
b7017e32 JA |
464 | " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max, |
465 | p_of_agg, mean, dev); | |
3c39a379 JA |
466 | } |
467 | } | |
468 | ||
7e1773ba JA |
469 | static int show_lat(double *io_u_lat, int nr, const char **ranges, |
470 | const char *msg) | |
04a0feae | 471 | { |
7e1773ba | 472 | int new_line = 1, i, line = 0, shown = 0; |
04a0feae JA |
473 | |
474 | for (i = 0; i < nr; i++) { | |
475 | if (io_u_lat[i] <= 0.0) | |
476 | continue; | |
7e1773ba | 477 | shown = 1; |
04a0feae | 478 | if (new_line) { |
4539ed73 JA |
479 | if (line) |
480 | log_info("\n"); | |
7e1773ba | 481 | log_info(" lat (%s) : ", msg); |
04a0feae JA |
482 | new_line = 0; |
483 | line = 0; | |
484 | } | |
485 | if (line) | |
486 | log_info(", "); | |
487 | log_info("%s%3.2f%%", ranges[i], io_u_lat[i]); | |
488 | line++; | |
489 | if (line == 5) | |
490 | new_line = 1; | |
491 | } | |
7e1773ba JA |
492 | |
493 | if (shown) | |
494 | log_info("\n"); | |
495 | ||
496 | return shown; | |
04a0feae JA |
497 | } |
498 | ||
499 | static void show_lat_u(double *io_u_lat_u) | |
500 | { | |
501 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", | |
502 | "250=", "500=", "750=", "1000=", }; | |
503 | ||
504 | show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec"); | |
505 | } | |
506 | ||
507 | static void show_lat_m(double *io_u_lat_m) | |
508 | { | |
509 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", | |
510 | "250=", "500=", "750=", "1000=", "2000=", | |
511 | ">=2000=", }; | |
512 | ||
513 | show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec"); | |
514 | } | |
515 | ||
516 | static void show_latencies(double *io_u_lat_u, double *io_u_lat_m) | |
517 | { | |
518 | show_lat_u(io_u_lat_u); | |
519 | show_lat_m(io_u_lat_m); | |
04a0feae JA |
520 | } |
521 | ||
a64e88da | 522 | void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs) |
3c39a379 JA |
523 | { |
524 | double usr_cpu, sys_cpu; | |
69008999 | 525 | unsigned long runtime; |
71619dc2 | 526 | double io_u_dist[FIO_IO_U_MAP_NR]; |
04a0feae JA |
527 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
528 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
57a64324 JA |
529 | time_t time_p; |
530 | char time_buf[64]; | |
3c39a379 | 531 | |
6eaf09d6 SL |
532 | if (!(ts->io_bytes[DDIR_READ] + ts->io_bytes[DDIR_WRITE] + |
533 | ts->io_bytes[DDIR_TRIM]) && !(ts->total_io_u[DDIR_READ] + | |
534 | ts->total_io_u[DDIR_WRITE] + ts->total_io_u[DDIR_TRIM])) | |
3c39a379 JA |
535 | return; |
536 | ||
57a64324 | 537 | time(&time_p); |
45054cbe | 538 | os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf)); |
57a64324 | 539 | |
5ec10eaa | 540 | if (!ts->error) { |
57a64324 | 541 | log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s", |
5ec10eaa | 542 | ts->name, ts->groupid, ts->members, |
57a64324 | 543 | ts->error, (int) ts->pid, time_buf); |
5ec10eaa | 544 | } else { |
57a64324 | 545 | log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s", |
5ec10eaa | 546 | ts->name, ts->groupid, ts->members, |
57a64324 JA |
547 | ts->error, ts->verror, (int) ts->pid, |
548 | time_buf); | |
5ec10eaa | 549 | } |
3c39a379 | 550 | |
259e47de | 551 | if (strlen(ts->description)) |
6d86144d | 552 | log_info(" Description : [%s]\n", ts->description); |
7bdce1bd | 553 | |
756867bd JA |
554 | if (ts->io_bytes[DDIR_READ]) |
555 | show_ddir_status(rs, ts, DDIR_READ); | |
556 | if (ts->io_bytes[DDIR_WRITE]) | |
557 | show_ddir_status(rs, ts, DDIR_WRITE); | |
6eaf09d6 SL |
558 | if (ts->io_bytes[DDIR_TRIM]) |
559 | show_ddir_status(rs, ts, DDIR_TRIM); | |
3c39a379 | 560 | |
7e1773ba JA |
561 | stat_calc_lat_u(ts, io_u_lat_u); |
562 | stat_calc_lat_m(ts, io_u_lat_m); | |
563 | show_latencies(io_u_lat_u, io_u_lat_m); | |
564 | ||
756867bd | 565 | runtime = ts->total_run_time; |
69008999 | 566 | if (runtime) { |
1e97cce9 | 567 | double runt = (double) runtime; |
3c39a379 | 568 | |
756867bd JA |
569 | usr_cpu = (double) ts->usr_time * 100 / runt; |
570 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
3c39a379 JA |
571 | } else { |
572 | usr_cpu = 0; | |
573 | sys_cpu = 0; | |
574 | } | |
575 | ||
5ec10eaa JA |
576 | log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu," |
577 | " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf); | |
71619dc2 | 578 | |
838bc709 | 579 | stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist); |
5ec10eaa JA |
580 | log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%," |
581 | " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], | |
582 | io_u_dist[1], io_u_dist[2], | |
583 | io_u_dist[3], io_u_dist[4], | |
584 | io_u_dist[5], io_u_dist[6]); | |
838bc709 JA |
585 | |
586 | stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist); | |
587 | log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," | |
588 | " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], | |
589 | io_u_dist[1], io_u_dist[2], | |
590 | io_u_dist[3], io_u_dist[4], | |
591 | io_u_dist[5], io_u_dist[6]); | |
592 | stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist); | |
593 | log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," | |
594 | " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], | |
595 | io_u_dist[1], io_u_dist[2], | |
596 | io_u_dist[3], io_u_dist[4], | |
597 | io_u_dist[5], io_u_dist[6]); | |
7e1773ba JA |
598 | log_info(" issued : total=r=%lu/w=%lu/d=%lu," |
599 | " short=r=%lu/w=%lu/d=%lu\n", | |
5ec10eaa | 600 | ts->total_io_u[0], ts->total_io_u[1], |
0d29de83 JA |
601 | ts->total_io_u[2], |
602 | ts->short_io_u[0], ts->short_io_u[1], | |
603 | ts->short_io_u[2]); | |
f2bba182 | 604 | if (ts->continue_on_error) { |
1ec99eea JA |
605 | log_info(" errors : total=%lu, first_error=%d/<%s>\n", |
606 | ts->total_err_count, | |
607 | ts->first_error, | |
608 | strerror(ts->first_error)); | |
f2bba182 | 609 | } |
3c39a379 JA |
610 | } |
611 | ||
756867bd | 612 | static void show_ddir_status_terse(struct thread_stat *ts, |
c6ae0a5b JA |
613 | struct group_run_stats *rs, int ddir) |
614 | { | |
615 | unsigned long min, max; | |
312b4af2 | 616 | unsigned long long bw, iops; |
1db92cb6 | 617 | unsigned int *ovals = NULL; |
c6ae0a5b | 618 | double mean, dev; |
1db92cb6 JA |
619 | unsigned int len, minv, maxv; |
620 | int i; | |
c6ae0a5b | 621 | |
ff58fced JA |
622 | assert(ddir_rw(ddir)); |
623 | ||
312b4af2 JA |
624 | iops = bw = 0; |
625 | if (ts->runtime[ddir]) { | |
626 | uint64_t runt = ts->runtime[ddir]; | |
627 | ||
033bbb51 | 628 | bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024; |
312b4af2 JA |
629 | iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt; |
630 | } | |
c6ae0a5b | 631 | |
312b4af2 | 632 | log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops, |
5ec10eaa | 633 | ts->runtime[ddir]); |
c6ae0a5b | 634 | |
079ad09b | 635 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
6d86144d | 636 | log_info(";%lu;%lu;%f;%f", min, max, mean, dev); |
c6ae0a5b | 637 | else |
6d86144d | 638 | log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
c6ae0a5b | 639 | |
079ad09b | 640 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) |
6d86144d | 641 | log_info(";%lu;%lu;%f;%f", min, max, mean, dev); |
c6ae0a5b | 642 | else |
6d86144d | 643 | log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
c6ae0a5b | 644 | |
1db92cb6 JA |
645 | if (ts->clat_percentiles) { |
646 | len = calc_clat_percentiles(ts->io_u_plat[ddir], | |
647 | ts->clat_stat[ddir].samples, | |
648 | ts->percentile_list, &ovals, &maxv, | |
649 | &minv); | |
650 | } else | |
651 | len = 0; | |
652 | ||
653 | for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { | |
654 | if (i >= len) { | |
655 | log_info(";0%%=0"); | |
656 | continue; | |
657 | } | |
658 | log_info(";%2.2f%%=%u", ts->percentile_list[i].u.f, ovals[i]); | |
659 | } | |
2341a37a K |
660 | |
661 | if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) | |
662 | log_info(";%lu;%lu;%f;%f", min, max, mean, dev); | |
663 | else | |
664 | log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); | |
665 | ||
1db92cb6 JA |
666 | if (ovals) |
667 | free(ovals); | |
668 | ||
079ad09b | 669 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
19d3e967 JA |
670 | double p_of_agg = 100.0; |
671 | ||
672 | if (rs->agg[ddir]) { | |
673 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; | |
674 | if (p_of_agg > 100.0) | |
675 | p_of_agg = 100.0; | |
676 | } | |
c6ae0a5b | 677 | |
6d86144d | 678 | log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev); |
c6ae0a5b | 679 | } else |
6d86144d | 680 | log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0); |
c6ae0a5b JA |
681 | } |
682 | ||
cc372b17 SL |
683 | static void add_ddir_status_json(struct thread_stat *ts, |
684 | struct group_run_stats *rs, int ddir, struct json_object *parent) | |
685 | { | |
686 | unsigned long min, max; | |
687 | unsigned long long bw, iops; | |
688 | unsigned int *ovals = NULL; | |
689 | double mean, dev; | |
690 | unsigned int len, minv, maxv; | |
691 | int i; | |
692 | const char *ddirname[] = {"read", "write", "trim"}; | |
693 | struct json_object *dir_object, *tmp_object, *percentile_object; | |
694 | char buf[120]; | |
695 | double p_of_agg = 100.0; | |
696 | ||
697 | assert(ddir_rw(ddir)); | |
698 | ||
771e58be JA |
699 | if (ts->unified_rw_rep && ddir != DDIR_READ) |
700 | return; | |
701 | ||
cc372b17 | 702 | dir_object = json_create_object(); |
771e58be JA |
703 | json_object_add_value_object(parent, |
704 | ts->unified_rw_rep ? "mixed" : ddirname[ddir], dir_object); | |
cc372b17 SL |
705 | |
706 | iops = bw = 0; | |
707 | if (ts->runtime[ddir]) { | |
708 | uint64_t runt = ts->runtime[ddir]; | |
709 | ||
710 | bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024; | |
711 | iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt; | |
712 | } | |
713 | ||
714 | json_object_add_value_int(dir_object, "io_bytes", ts->io_bytes[ddir] >> 10); | |
715 | json_object_add_value_int(dir_object, "bw", bw); | |
716 | json_object_add_value_int(dir_object, "iops", iops); | |
717 | json_object_add_value_int(dir_object, "runtime", ts->runtime[ddir]); | |
718 | ||
719 | if (!calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) { | |
720 | min = max = 0; | |
721 | mean = dev = 0.0; | |
722 | } | |
723 | tmp_object = json_create_object(); | |
724 | json_object_add_value_object(dir_object, "slat", tmp_object); | |
725 | json_object_add_value_int(tmp_object, "min", min); | |
726 | json_object_add_value_int(tmp_object, "max", max); | |
727 | json_object_add_value_float(tmp_object, "mean", mean); | |
728 | json_object_add_value_float(tmp_object, "stddev", dev); | |
729 | ||
730 | if (!calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) { | |
731 | min = max = 0; | |
732 | mean = dev = 0.0; | |
733 | } | |
734 | tmp_object = json_create_object(); | |
735 | json_object_add_value_object(dir_object, "clat", tmp_object); | |
736 | json_object_add_value_int(tmp_object, "min", min); | |
737 | json_object_add_value_int(tmp_object, "max", max); | |
738 | json_object_add_value_float(tmp_object, "mean", mean); | |
739 | json_object_add_value_float(tmp_object, "stddev", dev); | |
740 | ||
741 | if (ts->clat_percentiles) { | |
742 | len = calc_clat_percentiles(ts->io_u_plat[ddir], | |
743 | ts->clat_stat[ddir].samples, | |
744 | ts->percentile_list, &ovals, &maxv, | |
745 | &minv); | |
746 | } else | |
747 | len = 0; | |
748 | ||
749 | percentile_object = json_create_object(); | |
750 | json_object_add_value_object(tmp_object, "percentile", percentile_object); | |
751 | for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { | |
752 | if (i >= len) { | |
753 | json_object_add_value_int(percentile_object, "0.00", 0); | |
754 | continue; | |
755 | } | |
98ffb8f3 | 756 | snprintf(buf, sizeof(buf), "%2.2f", ts->percentile_list[i].u.f); |
cc372b17 SL |
757 | json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]); |
758 | } | |
759 | ||
760 | if (!calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) { | |
761 | min = max = 0; | |
762 | mean = dev = 0.0; | |
763 | } | |
764 | tmp_object = json_create_object(); | |
765 | json_object_add_value_object(dir_object, "lat", tmp_object); | |
766 | json_object_add_value_int(tmp_object, "min", min); | |
767 | json_object_add_value_int(tmp_object, "max", max); | |
768 | json_object_add_value_float(tmp_object, "mean", mean); | |
769 | json_object_add_value_float(tmp_object, "stddev", dev); | |
770 | if (ovals) | |
771 | free(ovals); | |
772 | ||
773 | if (!calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { | |
774 | if (rs->agg[ddir]) { | |
775 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; | |
776 | if (p_of_agg > 100.0) | |
777 | p_of_agg = 100.0; | |
778 | } | |
779 | } else { | |
780 | min = max = 0; | |
781 | p_of_agg = mean = dev = 0.0; | |
782 | } | |
783 | json_object_add_value_int(dir_object, "bw_min", min); | |
784 | json_object_add_value_int(dir_object, "bw_max", max); | |
785 | json_object_add_value_float(dir_object, "bw_agg", mean); | |
786 | json_object_add_value_float(dir_object, "bw_mean", mean); | |
787 | json_object_add_value_float(dir_object, "bw_dev", dev); | |
788 | } | |
789 | ||
4d658652 JA |
790 | static void show_thread_status_terse_v2(struct thread_stat *ts, |
791 | struct group_run_stats *rs) | |
792 | { | |
793 | double io_u_dist[FIO_IO_U_MAP_NR]; | |
794 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; | |
795 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
796 | double usr_cpu, sys_cpu; | |
797 | int i; | |
798 | ||
799 | /* General Info */ | |
800 | log_info("2;%s;%d;%d", ts->name, ts->groupid, ts->error); | |
801 | /* Log Read Status */ | |
6eaf09d6 | 802 | show_ddir_status_terse(ts, rs, DDIR_READ); |
4d658652 | 803 | /* Log Write Status */ |
6eaf09d6 SL |
804 | show_ddir_status_terse(ts, rs, DDIR_WRITE); |
805 | /* Log Trim Status */ | |
806 | show_ddir_status_terse(ts, rs, DDIR_TRIM); | |
4d658652 JA |
807 | |
808 | /* CPU Usage */ | |
809 | if (ts->total_run_time) { | |
810 | double runt = (double) ts->total_run_time; | |
811 | ||
812 | usr_cpu = (double) ts->usr_time * 100 / runt; | |
813 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
814 | } else { | |
815 | usr_cpu = 0; | |
816 | sys_cpu = 0; | |
817 | } | |
818 | ||
819 | log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf, | |
820 | ts->minf); | |
821 | ||
822 | /* Calc % distribution of IO depths, usecond, msecond latency */ | |
823 | stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist); | |
824 | stat_calc_lat_u(ts, io_u_lat_u); | |
825 | stat_calc_lat_m(ts, io_u_lat_m); | |
826 | ||
827 | /* Only show fixed 7 I/O depth levels*/ | |
828 | log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", | |
829 | io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], | |
830 | io_u_dist[4], io_u_dist[5], io_u_dist[6]); | |
831 | ||
832 | /* Microsecond latency */ | |
833 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) | |
834 | log_info(";%3.2f%%", io_u_lat_u[i]); | |
835 | /* Millisecond latency */ | |
836 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) | |
837 | log_info(";%3.2f%%", io_u_lat_m[i]); | |
838 | /* Additional output if continue_on_error set - default off*/ | |
839 | if (ts->continue_on_error) | |
840 | log_info(";%lu;%d", ts->total_err_count, ts->first_error); | |
841 | log_info("\n"); | |
842 | ||
843 | /* Additional output if description is set */ | |
844 | if (ts->description) | |
845 | log_info(";%s", ts->description); | |
846 | ||
847 | log_info("\n"); | |
848 | } | |
849 | ||
3449ab8c JA |
850 | static void show_thread_status_terse_v3_v4(struct thread_stat *ts, |
851 | struct group_run_stats *rs, int ver) | |
c6ae0a5b | 852 | { |
2270890c | 853 | double io_u_dist[FIO_IO_U_MAP_NR]; |
04a0feae JA |
854 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
855 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
c6ae0a5b | 856 | double usr_cpu, sys_cpu; |
04a0feae | 857 | int i; |
c6ae0a5b | 858 | |
562c2d2f | 859 | /* General Info */ |
f3afa57e | 860 | log_info("%d;%s;%s;%d;%d", ver, fio_version_string, |
5e726d0a | 861 | ts->name, ts->groupid, ts->error); |
562c2d2f | 862 | /* Log Read Status */ |
6eaf09d6 | 863 | show_ddir_status_terse(ts, rs, DDIR_READ); |
562c2d2f | 864 | /* Log Write Status */ |
6eaf09d6 SL |
865 | show_ddir_status_terse(ts, rs, DDIR_WRITE); |
866 | /* Log Trim Status */ | |
3449ab8c JA |
867 | if (ver == 4) |
868 | show_ddir_status_terse(ts, rs, DDIR_TRIM); | |
c6ae0a5b | 869 | |
562c2d2f | 870 | /* CPU Usage */ |
756867bd JA |
871 | if (ts->total_run_time) { |
872 | double runt = (double) ts->total_run_time; | |
c6ae0a5b | 873 | |
756867bd JA |
874 | usr_cpu = (double) ts->usr_time * 100 / runt; |
875 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
c6ae0a5b JA |
876 | } else { |
877 | usr_cpu = 0; | |
878 | sys_cpu = 0; | |
879 | } | |
880 | ||
5ec10eaa JA |
881 | log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf, |
882 | ts->minf); | |
2270890c | 883 | |
562c2d2f | 884 | /* Calc % distribution of IO depths, usecond, msecond latency */ |
838bc709 | 885 | stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist); |
04a0feae JA |
886 | stat_calc_lat_u(ts, io_u_lat_u); |
887 | stat_calc_lat_m(ts, io_u_lat_m); | |
2270890c | 888 | |
562c2d2f | 889 | /* Only show fixed 7 I/O depth levels*/ |
5ec10eaa JA |
890 | log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", |
891 | io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], | |
892 | io_u_dist[4], io_u_dist[5], io_u_dist[6]); | |
2270890c | 893 | |
562c2d2f | 894 | /* Microsecond latency */ |
04a0feae JA |
895 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) |
896 | log_info(";%3.2f%%", io_u_lat_u[i]); | |
562c2d2f | 897 | /* Millisecond latency */ |
04a0feae JA |
898 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) |
899 | log_info(";%3.2f%%", io_u_lat_m[i]); | |
f2f788dd JA |
900 | |
901 | /* disk util stats, if any */ | |
cc372b17 | 902 | show_disk_util(1, NULL); |
f2f788dd | 903 | |
562c2d2f | 904 | /* Additional output if continue_on_error set - default off*/ |
f2bba182 RR |
905 | if (ts->continue_on_error) |
906 | log_info(";%lu;%d", ts->total_err_count, ts->first_error); | |
2270890c | 907 | |
562c2d2f | 908 | /* Additional output if description is set */ |
4b0f2258 | 909 | if (strlen(ts->description)) |
946e4276 JA |
910 | log_info(";%s", ts->description); |
911 | ||
912 | log_info("\n"); | |
756867bd JA |
913 | } |
914 | ||
cc372b17 SL |
915 | static struct json_object *show_thread_status_json(struct thread_stat *ts, |
916 | struct group_run_stats *rs) | |
917 | { | |
918 | struct json_object *root, *tmp; | |
919 | double io_u_dist[FIO_IO_U_MAP_NR]; | |
920 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; | |
921 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
922 | double usr_cpu, sys_cpu; | |
923 | int i; | |
924 | ||
925 | root = json_create_object(); | |
926 | json_object_add_value_string(root, "jobname", ts->name); | |
927 | json_object_add_value_int(root, "groupid", ts->groupid); | |
928 | json_object_add_value_int(root, "error", ts->error); | |
929 | ||
930 | add_ddir_status_json(ts, rs, DDIR_READ, root); | |
931 | add_ddir_status_json(ts, rs, DDIR_WRITE, root); | |
f3afa57e | 932 | add_ddir_status_json(ts, rs, DDIR_TRIM, root); |
cc372b17 SL |
933 | |
934 | /* CPU Usage */ | |
935 | if (ts->total_run_time) { | |
936 | double runt = (double) ts->total_run_time; | |
937 | ||
938 | usr_cpu = (double) ts->usr_time * 100 / runt; | |
939 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
940 | } else { | |
941 | usr_cpu = 0; | |
942 | sys_cpu = 0; | |
943 | } | |
944 | json_object_add_value_float(root, "usr_cpu", usr_cpu); | |
945 | json_object_add_value_float(root, "sys_cpu", sys_cpu); | |
946 | json_object_add_value_int(root, "ctx", ts->ctx); | |
947 | json_object_add_value_int(root, "majf", ts->majf); | |
948 | json_object_add_value_int(root, "minf", ts->minf); | |
949 | ||
950 | ||
951 | /* Calc % distribution of IO depths, usecond, msecond latency */ | |
952 | stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist); | |
953 | stat_calc_lat_u(ts, io_u_lat_u); | |
954 | stat_calc_lat_m(ts, io_u_lat_m); | |
955 | ||
956 | tmp = json_create_object(); | |
957 | json_object_add_value_object(root, "iodepth_level", tmp); | |
958 | /* Only show fixed 7 I/O depth levels*/ | |
959 | for (i = 0; i < 7; i++) { | |
960 | char name[20]; | |
961 | if (i < 6) | |
98ffb8f3 | 962 | snprintf(name, 20, "%d", 1 << i); |
cc372b17 | 963 | else |
98ffb8f3 | 964 | snprintf(name, 20, ">=%d", 1 << i); |
cc372b17 SL |
965 | json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]); |
966 | } | |
967 | ||
968 | tmp = json_create_object(); | |
969 | json_object_add_value_object(root, "latency_us", tmp); | |
970 | /* Microsecond latency */ | |
971 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) { | |
972 | const char *ranges[] = { "2", "4", "10", "20", "50", "100", | |
973 | "250", "500", "750", "1000", }; | |
974 | json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]); | |
975 | } | |
976 | /* Millisecond latency */ | |
977 | tmp = json_create_object(); | |
978 | json_object_add_value_object(root, "latency_ms", tmp); | |
979 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) { | |
980 | const char *ranges[] = { "2", "4", "10", "20", "50", "100", | |
981 | "250", "500", "750", "1000", "2000", | |
982 | ">=2000", }; | |
983 | json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]); | |
984 | } | |
985 | ||
986 | /* Additional output if continue_on_error set - default off*/ | |
987 | if (ts->continue_on_error) { | |
988 | json_object_add_value_int(root, "total_err", ts->total_err_count); | |
989 | json_object_add_value_int(root, "total_err", ts->first_error); | |
990 | } | |
991 | ||
992 | /* Additional output if description is set */ | |
993 | if (strlen(ts->description)) | |
994 | json_object_add_value_string(root, "desc", ts->description); | |
995 | ||
996 | return root; | |
997 | } | |
998 | ||
4d658652 JA |
999 | static void show_thread_status_terse(struct thread_stat *ts, |
1000 | struct group_run_stats *rs) | |
1001 | { | |
1002 | if (terse_version == 2) | |
1003 | show_thread_status_terse_v2(ts, rs); | |
3449ab8c JA |
1004 | else if (terse_version == 3 || terse_version == 4) |
1005 | show_thread_status_terse_v3_v4(ts, rs, terse_version); | |
4d658652 JA |
1006 | else |
1007 | log_err("fio: bad terse version!? %d\n", terse_version); | |
1008 | } | |
1009 | ||
197574e4 | 1010 | static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr) |
756867bd JA |
1011 | { |
1012 | double mean, S; | |
1013 | ||
e09231c2 ZL |
1014 | if (src->samples == 0) |
1015 | return; | |
1016 | ||
756867bd JA |
1017 | dst->min_val = min(dst->min_val, src->min_val); |
1018 | dst->max_val = max(dst->max_val, src->max_val); | |
756867bd JA |
1019 | |
1020 | /* | |
cdcac5cf YH |
1021 | * Compute new mean and S after the merge |
1022 | * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance | |
1023 | * #Parallel_algorithm> | |
756867bd JA |
1024 | */ |
1025 | if (nr == 1) { | |
802ad4a8 JA |
1026 | mean = src->mean.u.f; |
1027 | S = src->S.u.f; | |
756867bd | 1028 | } else { |
802ad4a8 | 1029 | double delta = src->mean.u.f - dst->mean.u.f; |
cdcac5cf | 1030 | |
802ad4a8 JA |
1031 | mean = ((src->mean.u.f * src->samples) + |
1032 | (dst->mean.u.f * dst->samples)) / | |
cdcac5cf YH |
1033 | (dst->samples + src->samples); |
1034 | ||
802ad4a8 | 1035 | S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) * |
cdcac5cf YH |
1036 | (dst->samples * src->samples) / |
1037 | (dst->samples + src->samples); | |
756867bd JA |
1038 | } |
1039 | ||
cdcac5cf | 1040 | dst->samples += src->samples; |
802ad4a8 JA |
1041 | dst->mean.u.f = mean; |
1042 | dst->S.u.f = S; | |
756867bd JA |
1043 | } |
1044 | ||
37f0c1ae JA |
1045 | void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src) |
1046 | { | |
1047 | int i; | |
1048 | ||
6eaf09d6 | 1049 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
37f0c1ae JA |
1050 | if (dst->max_run[i] < src->max_run[i]) |
1051 | dst->max_run[i] = src->max_run[i]; | |
1052 | if (dst->min_run[i] && dst->min_run[i] > src->min_run[i]) | |
1053 | dst->min_run[i] = src->min_run[i]; | |
1054 | if (dst->max_bw[i] < src->max_bw[i]) | |
1055 | dst->max_bw[i] = src->max_bw[i]; | |
1056 | if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i]) | |
1057 | dst->min_bw[i] = src->min_bw[i]; | |
1058 | ||
1059 | dst->io_kb[i] += src->io_kb[i]; | |
1060 | dst->agg[i] += src->agg[i]; | |
1061 | } | |
1062 | ||
1063 | } | |
1064 | ||
5b9babb7 JA |
1065 | void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr) |
1066 | { | |
1067 | int l, k; | |
1068 | ||
6eaf09d6 | 1069 | for (l = 0; l < DDIR_RWDIR_CNT; l++) { |
771e58be JA |
1070 | if (!dst->unified_rw_rep) { |
1071 | sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr); | |
1072 | sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr); | |
1073 | sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr); | |
1074 | sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr); | |
1075 | ||
1076 | dst->io_bytes[l] += src->io_bytes[l]; | |
1077 | ||
1078 | if (dst->runtime[l] < src->runtime[l]) | |
1079 | dst->runtime[l] = src->runtime[l]; | |
1080 | } else { | |
1081 | sum_stat(&dst->clat_stat[0], &src->clat_stat[l], nr); | |
1082 | sum_stat(&dst->slat_stat[0], &src->slat_stat[l], nr); | |
1083 | sum_stat(&dst->lat_stat[0], &src->lat_stat[l], nr); | |
1084 | sum_stat(&dst->bw_stat[0], &src->bw_stat[l], nr); | |
1085 | ||
1086 | dst->io_bytes[0] += src->io_bytes[l]; | |
1087 | ||
1088 | if (dst->runtime[0] < src->runtime[l]) | |
1089 | dst->runtime[0] = src->runtime[l]; | |
1090 | } | |
5b9babb7 JA |
1091 | } |
1092 | ||
1093 | dst->usr_time += src->usr_time; | |
1094 | dst->sys_time += src->sys_time; | |
1095 | dst->ctx += src->ctx; | |
1096 | dst->majf += src->majf; | |
1097 | dst->minf += src->minf; | |
1098 | ||
1099 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) | |
1100 | dst->io_u_map[k] += src->io_u_map[k]; | |
1101 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) | |
1102 | dst->io_u_submit[k] += src->io_u_submit[k]; | |
1103 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) | |
1104 | dst->io_u_complete[k] += src->io_u_complete[k]; | |
1105 | for (k = 0; k < FIO_IO_U_LAT_U_NR; k++) | |
1106 | dst->io_u_lat_u[k] += src->io_u_lat_u[k]; | |
1107 | for (k = 0; k < FIO_IO_U_LAT_M_NR; k++) | |
1108 | dst->io_u_lat_m[k] += src->io_u_lat_m[k]; | |
1109 | ||
6eaf09d6 | 1110 | for (k = 0; k < DDIR_RWDIR_CNT; k++) { |
771e58be JA |
1111 | if (!dst->unified_rw_rep) { |
1112 | dst->total_io_u[k] += src->total_io_u[k]; | |
1113 | dst->short_io_u[k] += src->short_io_u[k]; | |
1114 | } else { | |
1115 | dst->total_io_u[0] += src->total_io_u[k]; | |
1116 | dst->short_io_u[0] += src->short_io_u[k]; | |
1117 | } | |
5b9babb7 JA |
1118 | } |
1119 | ||
6eaf09d6 | 1120 | for (k = 0; k < DDIR_RWDIR_CNT; k++) { |
5b9babb7 | 1121 | int m; |
771e58be JA |
1122 | |
1123 | for (m = 0; m < FIO_IO_U_PLAT_NR; m++) { | |
1124 | if (!dst->unified_rw_rep) | |
1125 | dst->io_u_plat[k][m] += src->io_u_plat[k][m]; | |
1126 | else | |
1127 | dst->io_u_plat[0][m] += src->io_u_plat[k][m]; | |
1128 | } | |
5b9babb7 JA |
1129 | } |
1130 | ||
1131 | dst->total_run_time += src->total_run_time; | |
1132 | dst->total_submit += src->total_submit; | |
1133 | dst->total_complete += src->total_complete; | |
1134 | } | |
1135 | ||
37f0c1ae JA |
1136 | void init_group_run_stat(struct group_run_stats *gs) |
1137 | { | |
6eaf09d6 | 1138 | int i; |
37f0c1ae | 1139 | memset(gs, 0, sizeof(*gs)); |
6eaf09d6 SL |
1140 | |
1141 | for (i = 0; i < DDIR_RWDIR_CNT; i++) | |
1142 | gs->min_bw[i] = gs->min_run[i] = ~0UL; | |
37f0c1ae JA |
1143 | } |
1144 | ||
1145 | void init_thread_stat(struct thread_stat *ts) | |
1146 | { | |
1147 | int j; | |
1148 | ||
1149 | memset(ts, 0, sizeof(*ts)); | |
1150 | ||
6eaf09d6 | 1151 | for (j = 0; j < DDIR_RWDIR_CNT; j++) { |
37f0c1ae JA |
1152 | ts->lat_stat[j].min_val = -1UL; |
1153 | ts->clat_stat[j].min_val = -1UL; | |
1154 | ts->slat_stat[j].min_val = -1UL; | |
1155 | ts->bw_stat[j].min_val = -1UL; | |
1156 | } | |
1157 | ts->groupid = -1; | |
1158 | } | |
1159 | ||
3c39a379 JA |
1160 | void show_run_stats(void) |
1161 | { | |
1162 | struct group_run_stats *runstats, *rs; | |
1163 | struct thread_data *td; | |
756867bd | 1164 | struct thread_stat *threadstats, *ts; |
5b9babb7 | 1165 | int i, j, nr_ts, last_ts, idx; |
90fef2d1 | 1166 | int kb_base_warned = 0; |
cc372b17 SL |
1167 | struct json_object *root = NULL; |
1168 | struct json_array *array = NULL; | |
3c39a379 JA |
1169 | |
1170 | runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); | |
1171 | ||
37f0c1ae JA |
1172 | for (i = 0; i < groupid + 1; i++) |
1173 | init_group_run_stat(&runstats[i]); | |
3c39a379 | 1174 | |
756867bd JA |
1175 | /* |
1176 | * find out how many threads stats we need. if group reporting isn't | |
1177 | * enabled, it's one-per-td. | |
1178 | */ | |
1179 | nr_ts = 0; | |
1180 | last_ts = -1; | |
1181 | for_each_td(td, i) { | |
2dc1bbeb | 1182 | if (!td->o.group_reporting) { |
756867bd JA |
1183 | nr_ts++; |
1184 | continue; | |
1185 | } | |
1186 | if (last_ts == td->groupid) | |
1187 | continue; | |
1188 | ||
1189 | last_ts = td->groupid; | |
1190 | nr_ts++; | |
1191 | } | |
1192 | ||
1193 | threadstats = malloc(nr_ts * sizeof(struct thread_stat)); | |
1194 | ||
37f0c1ae JA |
1195 | for (i = 0; i < nr_ts; i++) |
1196 | init_thread_stat(&threadstats[i]); | |
756867bd JA |
1197 | |
1198 | j = 0; | |
1199 | last_ts = -1; | |
197574e4 | 1200 | idx = 0; |
34572e28 | 1201 | for_each_td(td, i) { |
2dc1bbeb JA |
1202 | if (idx && (!td->o.group_reporting || |
1203 | (td->o.group_reporting && last_ts != td->groupid))) { | |
7abd0e3a JA |
1204 | idx = 0; |
1205 | j++; | |
1206 | } | |
1207 | ||
1208 | last_ts = td->groupid; | |
1209 | ||
756867bd JA |
1210 | ts = &threadstats[j]; |
1211 | ||
83349190 YH |
1212 | ts->clat_percentiles = td->o.clat_percentiles; |
1213 | if (td->o.overwrite_plist) | |
802ad4a8 | 1214 | memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list)); |
83349190 | 1215 | else |
802ad4a8 | 1216 | memcpy(ts->percentile_list, def_percentile_list, sizeof(def_percentile_list)); |
83349190 | 1217 | |
197574e4 | 1218 | idx++; |
6586ee89 | 1219 | ts->members++; |
756867bd | 1220 | |
7abd0e3a | 1221 | if (ts->groupid == -1) { |
2dc84ba7 JA |
1222 | /* |
1223 | * These are per-group shared already | |
1224 | */ | |
f6bb5b88 | 1225 | strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE); |
a64e88da JA |
1226 | if (td->o.description) |
1227 | strncpy(ts->description, td->o.description, | |
1228 | FIO_JOBNAME_SIZE); | |
1229 | else | |
1230 | memset(ts->description, 0, FIO_JOBNAME_SIZE); | |
1231 | ||
756867bd | 1232 | ts->groupid = td->groupid; |
2dc84ba7 JA |
1233 | |
1234 | /* | |
1235 | * first pid in group, not very useful... | |
1236 | */ | |
756867bd | 1237 | ts->pid = td->pid; |
90fef2d1 JA |
1238 | |
1239 | ts->kb_base = td->o.kb_base; | |
771e58be | 1240 | ts->unified_rw_rep = td->o.unified_rw_rep; |
90fef2d1 JA |
1241 | } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) { |
1242 | log_info("fio: kb_base differs for jobs in group, using" | |
1243 | " %u as the base\n", ts->kb_base); | |
1244 | kb_base_warned = 1; | |
2dc84ba7 JA |
1245 | } |
1246 | ||
f2bba182 RR |
1247 | ts->continue_on_error = td->o.continue_on_error; |
1248 | ts->total_err_count += td->total_err_count; | |
1249 | ts->first_error = td->first_error; | |
1250 | if (!ts->error) { | |
1251 | if (!td->error && td->o.continue_on_error && | |
1252 | td->first_error) { | |
1253 | ts->error = td->first_error; | |
f6bb5b88 | 1254 | strcpy(ts->verror, td->verror); |
f2bba182 RR |
1255 | } else if (td->error) { |
1256 | ts->error = td->error; | |
f6bb5b88 | 1257 | strcpy(ts->verror, td->verror); |
f2bba182 | 1258 | } |
756867bd JA |
1259 | } |
1260 | ||
5b9babb7 | 1261 | sum_thread_stats(ts, &td->ts, idx); |
756867bd JA |
1262 | } |
1263 | ||
1264 | for (i = 0; i < nr_ts; i++) { | |
94370ac4 | 1265 | unsigned long long bw; |
3c39a379 | 1266 | |
756867bd JA |
1267 | ts = &threadstats[i]; |
1268 | rs = &runstats[ts->groupid]; | |
90fef2d1 | 1269 | rs->kb_base = ts->kb_base; |
771e58be | 1270 | rs->unified_rw_rep += ts->unified_rw_rep; |
3c39a379 | 1271 | |
6eaf09d6 | 1272 | for (j = 0; j < DDIR_RWDIR_CNT; j++) { |
94370ac4 JA |
1273 | if (!ts->runtime[j]) |
1274 | continue; | |
1275 | if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j]) | |
1276 | rs->min_run[j] = ts->runtime[j]; | |
1277 | if (ts->runtime[j] > rs->max_run[j]) | |
1278 | rs->max_run[j] = ts->runtime[j]; | |
1279 | ||
1280 | bw = 0; | |
8879fd15 | 1281 | if (ts->runtime[j]) { |
c857cfeb JA |
1282 | unsigned long runt = ts->runtime[j]; |
1283 | unsigned long long kb; | |
8879fd15 | 1284 | |
c857cfeb JA |
1285 | kb = ts->io_bytes[j] / rs->kb_base; |
1286 | bw = kb * 1000 / runt; | |
8879fd15 | 1287 | } |
94370ac4 JA |
1288 | if (bw < rs->min_bw[j]) |
1289 | rs->min_bw[j] = bw; | |
1290 | if (bw > rs->max_bw[j]) | |
1291 | rs->max_bw[j] = bw; | |
1292 | ||
90fef2d1 | 1293 | rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base; |
94370ac4 | 1294 | } |
3c39a379 JA |
1295 | } |
1296 | ||
1297 | for (i = 0; i < groupid + 1; i++) { | |
6eaf09d6 SL |
1298 | int ddir; |
1299 | ||
3c39a379 JA |
1300 | rs = &runstats[i]; |
1301 | ||
6eaf09d6 SL |
1302 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
1303 | if (rs->max_run[ddir]) | |
1304 | rs->agg[ddir] = (rs->io_kb[ddir] * 1000) / | |
1305 | rs->max_run[ddir]; | |
1306 | } | |
3c39a379 JA |
1307 | } |
1308 | ||
1309 | /* | |
1310 | * don't overwrite last signal output | |
1311 | */ | |
f3afa57e | 1312 | if (output_format == FIO_OUTPUT_NORMAL) |
4ceb30d4 | 1313 | log_info("\n"); |
f3afa57e | 1314 | else if (output_format == FIO_OUTPUT_JSON) { |
cc372b17 SL |
1315 | root = json_create_object(); |
1316 | json_object_add_value_string(root, "fio version", fio_version_string); | |
1317 | array = json_create_array(); | |
1318 | json_object_add_value_array(root, "jobs", array); | |
1319 | } | |
1320 | ||
756867bd JA |
1321 | for (i = 0; i < nr_ts; i++) { |
1322 | ts = &threadstats[i]; | |
1323 | rs = &runstats[ts->groupid]; | |
3c39a379 | 1324 | |
a64e88da JA |
1325 | if (is_backend) |
1326 | fio_server_send_ts(ts, rs); | |
f3afa57e JA |
1327 | else if (output_format == FIO_OUTPUT_TERSE) |
1328 | show_thread_status_terse(ts, rs); | |
1329 | else if (output_format == FIO_OUTPUT_JSON) { | |
1330 | struct json_object *tmp = show_thread_status_json(ts, rs); | |
1331 | json_array_add_value_object(array, tmp); | |
cc372b17 | 1332 | } else |
756867bd | 1333 | show_thread_status(ts, rs); |
3c39a379 | 1334 | } |
f3afa57e | 1335 | if (output_format == FIO_OUTPUT_JSON) { |
cc372b17 SL |
1336 | /* disk util stats, if any */ |
1337 | show_disk_util(1, root); | |
1338 | ||
f2a2ce0e HL |
1339 | show_idle_prof_stats(FIO_OUTPUT_JSON, root); |
1340 | ||
cc372b17 SL |
1341 | json_print_object(root); |
1342 | log_info("\n"); | |
1343 | json_free_object(root); | |
1344 | } | |
3c39a379 | 1345 | |
72c27ff8 JA |
1346 | for (i = 0; i < groupid + 1; i++) { |
1347 | rs = &runstats[i]; | |
3c39a379 | 1348 | |
72c27ff8 | 1349 | rs->groupid = i; |
d09a64a0 | 1350 | if (is_backend) |
72c27ff8 | 1351 | fio_server_send_gs(rs); |
f3afa57e | 1352 | else if (output_format == FIO_OUTPUT_NORMAL) |
72c27ff8 | 1353 | show_group_stats(rs); |
c6ae0a5b | 1354 | } |
eecf272f | 1355 | |
72c27ff8 JA |
1356 | if (is_backend) |
1357 | fio_server_send_du(); | |
f3afa57e | 1358 | else if (output_format == FIO_OUTPUT_NORMAL) |
cc372b17 | 1359 | show_disk_util(0, NULL); |
72c27ff8 | 1360 | |
f2a2ce0e HL |
1361 | show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL); |
1362 | ||
eecf272f | 1363 | free(runstats); |
756867bd | 1364 | free(threadstats); |
3c39a379 JA |
1365 | } |
1366 | ||
4c6d91e8 JA |
1367 | static void *__show_running_run_stats(void *arg) |
1368 | { | |
1369 | struct thread_data *td; | |
1370 | unsigned long long *rt; | |
1371 | struct timeval tv; | |
1372 | int i; | |
1373 | ||
1374 | rt = malloc(thread_number * sizeof(unsigned long long)); | |
1375 | fio_gettime(&tv, NULL); | |
1376 | ||
1377 | for_each_td(td, i) { | |
1378 | rt[i] = mtime_since(&td->start, &tv); | |
1379 | if (td_read(td) && td->io_bytes[DDIR_READ]) | |
1380 | td->ts.runtime[DDIR_READ] += rt[i]; | |
1381 | if (td_write(td) && td->io_bytes[DDIR_WRITE]) | |
1382 | td->ts.runtime[DDIR_WRITE] += rt[i]; | |
6eaf09d6 SL |
1383 | if (td_trim(td) && td->io_bytes[DDIR_TRIM]) |
1384 | td->ts.runtime[DDIR_TRIM] += rt[i]; | |
4c6d91e8 JA |
1385 | |
1386 | update_rusage_stat(td); | |
6eaf09d6 SL |
1387 | td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ]; |
1388 | td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE]; | |
1389 | td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM]; | |
4c6d91e8 JA |
1390 | td->ts.total_run_time = mtime_since(&td->epoch, &tv); |
1391 | } | |
1392 | ||
1393 | show_run_stats(); | |
1394 | ||
1395 | for_each_td(td, i) { | |
1396 | if (td_read(td) && td->io_bytes[DDIR_READ]) | |
1397 | td->ts.runtime[DDIR_READ] -= rt[i]; | |
1398 | if (td_write(td) && td->io_bytes[DDIR_WRITE]) | |
1399 | td->ts.runtime[DDIR_WRITE] -= rt[i]; | |
6eaf09d6 SL |
1400 | if (td_trim(td) && td->io_bytes[DDIR_TRIM]) |
1401 | td->ts.runtime[DDIR_TRIM] -= rt[i]; | |
4c6d91e8 JA |
1402 | } |
1403 | ||
1404 | free(rt); | |
1405 | return NULL; | |
1406 | } | |
1407 | ||
1408 | /* | |
1409 | * Called from signal handler. It _should_ be safe to just run this inline | |
1410 | * in the sig handler, but we should be disturbing the system less by just | |
1411 | * creating a thread to do it. | |
1412 | */ | |
1413 | void show_running_run_stats(void) | |
1414 | { | |
1415 | pthread_t thread; | |
1416 | ||
1417 | pthread_create(&thread, NULL, __show_running_run_stats, NULL); | |
1418 | pthread_detach(thread); | |
1419 | } | |
1420 | ||
68704084 | 1421 | static inline void add_stat_sample(struct io_stat *is, unsigned long data) |
3c39a379 | 1422 | { |
68704084 | 1423 | double val = data; |
6660cc67 | 1424 | double delta; |
68704084 JA |
1425 | |
1426 | if (data > is->max_val) | |
1427 | is->max_val = data; | |
1428 | if (data < is->min_val) | |
1429 | is->min_val = data; | |
1430 | ||
802ad4a8 | 1431 | delta = val - is->mean.u.f; |
ef11d737 | 1432 | if (delta) { |
802ad4a8 JA |
1433 | is->mean.u.f += delta / (is->samples + 1.0); |
1434 | is->S.u.f += delta * (val - is->mean.u.f); | |
ef11d737 | 1435 | } |
3c39a379 | 1436 | |
3c39a379 JA |
1437 | is->samples++; |
1438 | } | |
1439 | ||
bb3884d8 | 1440 | static void __add_log_sample(struct io_log *iolog, unsigned long val, |
306ddc97 | 1441 | enum fio_ddir ddir, unsigned int bs, |
2b13e716 | 1442 | unsigned long t) |
3c39a379 | 1443 | { |
306ddc97 JA |
1444 | const int nr_samples = iolog->nr_samples; |
1445 | ||
b8bc8cba JA |
1446 | if (!iolog->nr_samples) |
1447 | iolog->avg_last = t; | |
1448 | ||
3c39a379 JA |
1449 | if (iolog->nr_samples == iolog->max_samples) { |
1450 | int new_size = sizeof(struct io_sample) * iolog->max_samples*2; | |
1451 | ||
1452 | iolog->log = realloc(iolog->log, new_size); | |
1453 | iolog->max_samples <<= 1; | |
1454 | } | |
1455 | ||
306ddc97 | 1456 | iolog->log[nr_samples].val = val; |
2b13e716 | 1457 | iolog->log[nr_samples].time = t; |
306ddc97 JA |
1458 | iolog->log[nr_samples].ddir = ddir; |
1459 | iolog->log[nr_samples].bs = bs; | |
3c39a379 JA |
1460 | iolog->nr_samples++; |
1461 | } | |
1462 | ||
7fb28d36 JA |
1463 | static inline void reset_io_stat(struct io_stat *ios) |
1464 | { | |
1465 | ios->max_val = ios->min_val = ios->samples = 0; | |
1466 | ios->mean.u.f = ios->S.u.f = 0; | |
1467 | } | |
1468 | ||
bb3884d8 | 1469 | static void add_log_sample(struct thread_data *td, struct io_log *iolog, |
306ddc97 JA |
1470 | unsigned long val, enum fio_ddir ddir, |
1471 | unsigned int bs) | |
bb3884d8 | 1472 | { |
7fb28d36 | 1473 | unsigned long elapsed, this_window; |
b8bc8cba | 1474 | |
ff58fced JA |
1475 | if (!ddir_rw(ddir)) |
1476 | return; | |
1477 | ||
b8bc8cba JA |
1478 | elapsed = mtime_since_now(&td->epoch); |
1479 | ||
1480 | /* | |
1481 | * If no time averaging, just add the log sample. | |
1482 | */ | |
1483 | if (!iolog->avg_msec) { | |
1484 | __add_log_sample(iolog, val, ddir, bs, elapsed); | |
1485 | return; | |
1486 | } | |
1487 | ||
1488 | /* | |
1489 | * Add the sample. If the time period has passed, then | |
1490 | * add that entry to the log and clear. | |
1491 | */ | |
1492 | add_stat_sample(&iolog->avg_window[ddir], val); | |
1493 | ||
7fb28d36 JA |
1494 | /* |
1495 | * If period hasn't passed, adding the above sample is all we | |
1496 | * need to do. | |
1497 | */ | |
b8bc8cba JA |
1498 | this_window = elapsed - iolog->avg_last; |
1499 | if (this_window < iolog->avg_msec) | |
1500 | return; | |
1501 | ||
7fb28d36 JA |
1502 | /* |
1503 | * Note an entry in the log. Use the mean from the logged samples, | |
1504 | * making sure to properly round up. Only write a log entry if we | |
1505 | * had actual samples done. | |
1506 | */ | |
1507 | if (iolog->avg_window[DDIR_READ].samples) { | |
1508 | unsigned long mr; | |
b8bc8cba | 1509 | |
7fb28d36 | 1510 | mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50; |
b8bc8cba | 1511 | __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed); |
7fb28d36 JA |
1512 | } |
1513 | if (iolog->avg_window[DDIR_WRITE].samples) { | |
1514 | unsigned long mw; | |
1515 | ||
1516 | mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50; | |
b8bc8cba | 1517 | __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed); |
7fb28d36 | 1518 | } |
6eaf09d6 SL |
1519 | if (iolog->avg_window[DDIR_TRIM].samples) { |
1520 | unsigned long mw; | |
1521 | ||
1522 | mw = iolog->avg_window[DDIR_TRIM].mean.u.f + 0.50; | |
1523 | __add_log_sample(iolog, mw, DDIR_TRIM, 0, elapsed); | |
1524 | } | |
1525 | ||
b8bc8cba | 1526 | |
7fb28d36 JA |
1527 | reset_io_stat(&iolog->avg_window[DDIR_READ]); |
1528 | reset_io_stat(&iolog->avg_window[DDIR_WRITE]); | |
6eaf09d6 | 1529 | reset_io_stat(&iolog->avg_window[DDIR_TRIM]); |
b8bc8cba | 1530 | iolog->avg_last = elapsed; |
bb3884d8 JA |
1531 | } |
1532 | ||
306ddc97 | 1533 | void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs) |
bb3884d8 | 1534 | { |
ff58fced | 1535 | struct io_log *iolog; |
bb3884d8 | 1536 | |
ff58fced JA |
1537 | if (!ddir_rw(ddir)) |
1538 | return; | |
1539 | ||
1540 | iolog = agg_io_log[ddir]; | |
306ddc97 | 1541 | __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis()); |
bb3884d8 JA |
1542 | } |
1543 | ||
83349190 YH |
1544 | static void add_clat_percentile_sample(struct thread_stat *ts, |
1545 | unsigned long usec, enum fio_ddir ddir) | |
1546 | { | |
1547 | unsigned int idx = plat_val_to_idx(usec); | |
1548 | assert(idx < FIO_IO_U_PLAT_NR); | |
1549 | ||
1550 | ts->io_u_plat[ddir][idx]++; | |
1551 | } | |
1552 | ||
1e97cce9 | 1553 | void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, |
306ddc97 | 1554 | unsigned long usec, unsigned int bs) |
3c39a379 | 1555 | { |
756867bd | 1556 | struct thread_stat *ts = &td->ts; |
079ad09b | 1557 | |
ff58fced JA |
1558 | if (!ddir_rw(ddir)) |
1559 | return; | |
1560 | ||
d85f5118 | 1561 | add_stat_sample(&ts->clat_stat[ddir], usec); |
3c39a379 | 1562 | |
7b9f733a JA |
1563 | if (td->clat_log) |
1564 | add_log_sample(td, td->clat_log, usec, ddir, bs); | |
83349190 YH |
1565 | |
1566 | if (ts->clat_percentiles) | |
1567 | add_clat_percentile_sample(ts, usec, ddir); | |
3c39a379 JA |
1568 | } |
1569 | ||
1e97cce9 | 1570 | void add_slat_sample(struct thread_data *td, enum fio_ddir ddir, |
306ddc97 | 1571 | unsigned long usec, unsigned int bs) |
3c39a379 | 1572 | { |
756867bd | 1573 | struct thread_stat *ts = &td->ts; |
079ad09b | 1574 | |
ff58fced JA |
1575 | if (!ddir_rw(ddir)) |
1576 | return; | |
1577 | ||
d85f5118 | 1578 | add_stat_sample(&ts->slat_stat[ddir], usec); |
3c39a379 | 1579 | |
7b9f733a JA |
1580 | if (td->slat_log) |
1581 | add_log_sample(td, td->slat_log, usec, ddir, bs); | |
3c39a379 JA |
1582 | } |
1583 | ||
02af0988 JA |
1584 | void add_lat_sample(struct thread_data *td, enum fio_ddir ddir, |
1585 | unsigned long usec, unsigned int bs) | |
1586 | { | |
1587 | struct thread_stat *ts = &td->ts; | |
1588 | ||
ff58fced JA |
1589 | if (!ddir_rw(ddir)) |
1590 | return; | |
1591 | ||
02af0988 JA |
1592 | add_stat_sample(&ts->lat_stat[ddir], usec); |
1593 | ||
7b9f733a JA |
1594 | if (td->lat_log) |
1595 | add_log_sample(td, td->lat_log, usec, ddir, bs); | |
02af0988 JA |
1596 | } |
1597 | ||
306ddc97 | 1598 | void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs, |
1e97cce9 | 1599 | struct timeval *t) |
3c39a379 | 1600 | { |
756867bd | 1601 | struct thread_stat *ts = &td->ts; |
ff58fced JA |
1602 | unsigned long spent, rate; |
1603 | ||
1604 | if (!ddir_rw(ddir)) | |
1605 | return; | |
3c39a379 | 1606 | |
c8eeb9df | 1607 | spent = mtime_since(&td->bw_sample_time, t); |
2dc1bbeb | 1608 | if (spent < td->o.bw_avg_time) |
3c39a379 | 1609 | return; |
9602d8df JA |
1610 | |
1611 | /* | |
5daa4ebe JC |
1612 | * Compute both read and write rates for the interval. |
1613 | */ | |
6eaf09d6 | 1614 | for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) { |
5daa4ebe JC |
1615 | uint64_t delta; |
1616 | ||
1617 | delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir]; | |
1618 | if (!delta) | |
1619 | continue; /* No entries for interval */ | |
3c39a379 | 1620 | |
5daa4ebe JC |
1621 | rate = delta * 1000 / spent / 1024; |
1622 | add_stat_sample(&ts->bw_stat[ddir], rate); | |
3c39a379 | 1623 | |
5daa4ebe JC |
1624 | if (td->bw_log) |
1625 | add_log_sample(td, td->bw_log, rate, ddir, bs); | |
1626 | ||
1627 | td->stat_io_bytes[ddir] = td->this_io_bytes[ddir]; | |
1628 | } | |
3c39a379 | 1629 | |
c8eeb9df | 1630 | fio_gettime(&td->bw_sample_time, NULL); |
3c39a379 | 1631 | } |
c8eeb9df JA |
1632 | |
1633 | void add_iops_sample(struct thread_data *td, enum fio_ddir ddir, | |
1634 | struct timeval *t) | |
1635 | { | |
1636 | struct thread_stat *ts = &td->ts; | |
1637 | unsigned long spent, iops; | |
1638 | ||
1639 | if (!ddir_rw(ddir)) | |
1640 | return; | |
1641 | ||
1642 | spent = mtime_since(&td->iops_sample_time, t); | |
1643 | if (spent < td->o.iops_avg_time) | |
1644 | return; | |
1645 | ||
9602d8df JA |
1646 | /* |
1647 | * Compute both read and write rates for the interval. | |
1648 | */ | |
6eaf09d6 | 1649 | for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) { |
9602d8df | 1650 | uint64_t delta; |
c8eeb9df | 1651 | |
9602d8df JA |
1652 | delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir]; |
1653 | if (!delta) | |
1654 | continue; /* No entries for interval */ | |
1655 | ||
1656 | iops = (delta * 1000) / spent; | |
1657 | add_stat_sample(&ts->iops_stat[ddir], iops); | |
c8eeb9df | 1658 | |
9602d8df JA |
1659 | if (td->iops_log) |
1660 | add_log_sample(td, td->iops_log, iops, ddir, 0); | |
1661 | ||
421f4a82 | 1662 | td->stat_io_blocks[ddir] = td->this_io_blocks[ddir]; |
9602d8df | 1663 | } |
c8eeb9df JA |
1664 | |
1665 | fio_gettime(&td->iops_sample_time, NULL); | |
c8eeb9df | 1666 | } |