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" |
3c39a379 | 13 | |
3c39a379 JA |
14 | void update_rusage_stat(struct thread_data *td) |
15 | { | |
756867bd | 16 | struct thread_stat *ts = &td->ts; |
3c39a379 | 17 | |
c8aaba19 | 18 | getrusage(RUSAGE_SELF, &td->ru_end); |
079ad09b | 19 | |
c8aaba19 JA |
20 | ts->usr_time += mtime_since(&td->ru_start.ru_utime, |
21 | &td->ru_end.ru_utime); | |
22 | ts->sys_time += mtime_since(&td->ru_start.ru_stime, | |
23 | &td->ru_end.ru_stime); | |
24 | ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw | |
25 | - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw); | |
26 | ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt; | |
27 | ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt; | |
5ec10eaa | 28 | |
c8aaba19 | 29 | memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end)); |
3c39a379 JA |
30 | } |
31 | ||
83349190 YH |
32 | /* |
33 | * Given a latency, return the index of the corresponding bucket in | |
34 | * the structure tracking percentiles. | |
35 | * | |
36 | * (1) find the group (and error bits) that the value (latency) | |
37 | * belongs to by looking at its MSB. (2) find the bucket number in the | |
38 | * group by looking at the index bits. | |
39 | * | |
40 | */ | |
41 | static unsigned int plat_val_to_idx(unsigned int val) | |
42 | { | |
43 | unsigned int msb, error_bits, base, offset, idx; | |
44 | ||
45 | /* Find MSB starting from bit 0 */ | |
46 | if (val == 0) | |
47 | msb = 0; | |
48 | else | |
49 | msb = (sizeof(val)*8) - __builtin_clz(val) - 1; | |
50 | ||
716050f2 JA |
51 | /* |
52 | * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use | |
53 | * all bits of the sample as index | |
54 | */ | |
83349190 YH |
55 | if (msb <= FIO_IO_U_PLAT_BITS) |
56 | return val; | |
57 | ||
58 | /* Compute the number of error bits to discard*/ | |
59 | error_bits = msb - FIO_IO_U_PLAT_BITS; | |
60 | ||
61 | /* Compute the number of buckets before the group */ | |
62 | base = (error_bits + 1) << FIO_IO_U_PLAT_BITS; | |
63 | ||
716050f2 JA |
64 | /* |
65 | * Discard the error bits and apply the mask to find the | |
66 | * index for the buckets in the group | |
67 | */ | |
83349190 YH |
68 | offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits); |
69 | ||
70 | /* Make sure the index does not exceed (array size - 1) */ | |
71 | idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1)? | |
72 | (base + offset) : (FIO_IO_U_PLAT_NR - 1); | |
73 | ||
74 | return idx; | |
75 | } | |
76 | ||
77 | /* | |
78 | * Convert the given index of the bucket array to the value | |
79 | * represented by the bucket | |
80 | */ | |
81 | static unsigned int plat_idx_to_val(unsigned int idx) | |
82 | { | |
83 | unsigned int error_bits, k, base; | |
84 | ||
85 | assert(idx < FIO_IO_U_PLAT_NR); | |
86 | ||
87 | /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use | |
88 | * all bits of the sample as index */ | |
89 | if (idx < (FIO_IO_U_PLAT_VAL << 1) ) | |
90 | return idx; | |
91 | ||
92 | /* Find the group and compute the minimum value of that group */ | |
93 | error_bits = (idx >> FIO_IO_U_PLAT_BITS) -1; | |
94 | base = 1 << (error_bits + FIO_IO_U_PLAT_BITS); | |
95 | ||
96 | /* Find its bucket number of the group */ | |
97 | k = idx % FIO_IO_U_PLAT_VAL; | |
98 | ||
99 | /* Return the mean of the range of the bucket */ | |
100 | return base + ((k + 0.5) * (1 << error_bits)); | |
101 | } | |
102 | ||
103 | static int double_cmp(const void *a, const void *b) | |
104 | { | |
802ad4a8 JA |
105 | const fio_fp64_t fa = *(const fio_fp64_t *) a; |
106 | const fio_fp64_t fb = *(const fio_fp64_t *) b; | |
83349190 YH |
107 | int cmp = 0; |
108 | ||
802ad4a8 | 109 | if (fa.u.f > fb.u.f) |
83349190 | 110 | cmp = 1; |
802ad4a8 | 111 | else if (fa.u.f < fb.u.f) |
83349190 YH |
112 | cmp = -1; |
113 | ||
114 | return cmp; | |
115 | } | |
116 | ||
a269790c JA |
117 | unsigned int calc_clat_percentiles(unsigned int *io_u_plat, unsigned long nr, |
118 | fio_fp64_t *plist, unsigned int **output, | |
119 | unsigned int *maxv, unsigned int *minv) | |
83349190 YH |
120 | { |
121 | unsigned long sum = 0; | |
1db92cb6 JA |
122 | unsigned int len, i, j = 0; |
123 | unsigned int oval_len = 0; | |
124 | unsigned int *ovals = NULL; | |
125 | int is_last; | |
126 | ||
127 | *minv = -1U; | |
128 | *maxv = 0; | |
83349190 | 129 | |
802ad4a8 JA |
130 | len = 0; |
131 | while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0) | |
132 | len++; | |
716050f2 | 133 | |
351de8de | 134 | if (!len) |
1db92cb6 | 135 | return 0; |
351de8de | 136 | |
716050f2 | 137 | /* |
802ad4a8 JA |
138 | * Sort the percentile list. Note that it may already be sorted if |
139 | * we are using the default values, but since it's a short list this | |
140 | * isn't a worry. Also note that this does not work for NaN values. | |
716050f2 | 141 | */ |
802ad4a8 JA |
142 | if (len > 1) |
143 | qsort((void*)plist, len, sizeof(plist[0]), double_cmp); | |
83349190 | 144 | |
4f6f8298 JA |
145 | /* |
146 | * Calculate bucket values, note down max and min values | |
147 | */ | |
07511a63 JA |
148 | is_last = 0; |
149 | for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) { | |
83349190 | 150 | sum += io_u_plat[i]; |
802ad4a8 JA |
151 | while (sum >= (plist[j].u.f / 100.0 * nr)) { |
152 | assert(plist[j].u.f <= 100.0); | |
83349190 | 153 | |
4f6f8298 JA |
154 | if (j == oval_len) { |
155 | oval_len += 100; | |
156 | ovals = realloc(ovals, oval_len * sizeof(unsigned int)); | |
157 | } | |
158 | ||
159 | ovals[j] = plat_idx_to_val(i); | |
1db92cb6 JA |
160 | if (ovals[j] < *minv) |
161 | *minv = ovals[j]; | |
162 | if (ovals[j] > *maxv) | |
163 | *maxv = ovals[j]; | |
07511a63 JA |
164 | |
165 | is_last = (j == len - 1); | |
166 | if (is_last) | |
167 | break; | |
168 | ||
4f6f8298 JA |
169 | j++; |
170 | } | |
171 | } | |
83349190 | 172 | |
1db92cb6 JA |
173 | *output = ovals; |
174 | return len; | |
175 | } | |
176 | ||
177 | /* | |
178 | * Find and display the p-th percentile of clat | |
179 | */ | |
180 | static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr, | |
181 | fio_fp64_t *plist) | |
182 | { | |
183 | unsigned int len, j = 0, minv, maxv; | |
184 | unsigned int *ovals; | |
185 | int is_last, scale_down; | |
186 | ||
187 | len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv); | |
188 | if (!len) | |
189 | goto out; | |
190 | ||
4f6f8298 JA |
191 | /* |
192 | * We default to usecs, but if the value range is such that we | |
193 | * should scale down to msecs, do that. | |
194 | */ | |
195 | if (minv > 2000 && maxv > 99999) { | |
196 | scale_down = 1; | |
197 | log_info(" clat percentiles (msec):\n |"); | |
198 | } else { | |
199 | scale_down = 0; | |
200 | log_info(" clat percentiles (usec):\n |"); | |
201 | } | |
83349190 | 202 | |
4f6f8298 JA |
203 | for (j = 0; j < len; j++) { |
204 | char fbuf[8]; | |
81ab0b3a | 205 | |
4f6f8298 JA |
206 | /* for formatting */ |
207 | if (j != 0 && (j % 4) == 0) | |
208 | log_info(" |"); | |
83349190 | 209 | |
4f6f8298 JA |
210 | /* end of the list */ |
211 | is_last = (j == len - 1); | |
83349190 | 212 | |
4f6f8298 JA |
213 | if (plist[j].u.f < 10.0) |
214 | sprintf(fbuf, " %2.2f", plist[j].u.f); | |
215 | else | |
216 | sprintf(fbuf, "%2.2f", plist[j].u.f); | |
217 | ||
218 | if (scale_down) | |
219 | ovals[j] = (ovals[j] + 999) / 1000; | |
220 | ||
221 | log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ','); | |
222 | ||
223 | if (is_last) | |
224 | break; | |
225 | ||
226 | if (j % 4 == 3) /* for formatting */ | |
227 | log_info("\n"); | |
83349190 | 228 | } |
4f6f8298 | 229 | |
1db92cb6 | 230 | out: |
4f6f8298 JA |
231 | if (ovals) |
232 | free(ovals); | |
83349190 YH |
233 | } |
234 | ||
b29ad562 JA |
235 | int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max, |
236 | double *mean, double *dev) | |
3c39a379 | 237 | { |
68704084 | 238 | double n = is->samples; |
3c39a379 JA |
239 | |
240 | if (is->samples == 0) | |
241 | return 0; | |
242 | ||
243 | *min = is->min_val; | |
244 | *max = is->max_val; | |
245 | ||
246 | n = (double) is->samples; | |
802ad4a8 | 247 | *mean = is->mean.u.f; |
e6d276f2 | 248 | |
68704084 | 249 | if (n > 1.0) |
802ad4a8 | 250 | *dev = sqrt(is->S.u.f / (n - 1.0)); |
ef9c5c40 | 251 | else |
4b43f54e | 252 | *dev = 0; |
ef9c5c40 | 253 | |
3c39a379 JA |
254 | return 1; |
255 | } | |
256 | ||
a64e88da | 257 | void show_group_stats(struct group_run_stats *rs) |
3c39a379 | 258 | { |
dbe1125e JA |
259 | char *p1, *p2, *p3, *p4; |
260 | const char *ddir_str[] = { " READ", " WRITE" }; | |
261 | int i; | |
262 | ||
7e1773ba | 263 | log_info("\nRun status group %d (all jobs):\n", rs->groupid); |
3c39a379 | 264 | |
dbe1125e | 265 | for (i = 0; i <= DDIR_WRITE; i++) { |
90fef2d1 JA |
266 | const int i2p = is_power_of_2(rs->kb_base); |
267 | ||
dbe1125e JA |
268 | if (!rs->max_run[i]) |
269 | continue; | |
270 | ||
90fef2d1 JA |
271 | p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p); |
272 | p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p); | |
273 | p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p); | |
274 | p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p); | |
dbe1125e | 275 | |
b22989b9 | 276 | log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s," |
5ec10eaa JA |
277 | " mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2, |
278 | p3, p4, rs->min_run[i], | |
279 | rs->max_run[i]); | |
dbe1125e JA |
280 | |
281 | free(p1); | |
282 | free(p2); | |
283 | free(p3); | |
284 | free(p4); | |
285 | } | |
3c39a379 JA |
286 | } |
287 | ||
b3605062 JA |
288 | #define ts_total_io_u(ts) \ |
289 | ((ts)->total_io_u[0] + (ts)->total_io_u[1]) | |
290 | ||
838bc709 JA |
291 | static void stat_calc_dist(unsigned int *map, unsigned long total, |
292 | double *io_u_dist) | |
2270890c JA |
293 | { |
294 | int i; | |
295 | ||
296 | /* | |
297 | * Do depth distribution calculations | |
298 | */ | |
299 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { | |
838bc709 JA |
300 | if (total) { |
301 | io_u_dist[i] = (double) map[i] / (double) total; | |
302 | io_u_dist[i] *= 100.0; | |
303 | if (io_u_dist[i] < 0.1 && map[i]) | |
304 | io_u_dist[i] = 0.1; | |
305 | } else | |
306 | io_u_dist[i] = 0.0; | |
2270890c JA |
307 | } |
308 | } | |
309 | ||
04a0feae JA |
310 | static void stat_calc_lat(struct thread_stat *ts, double *dst, |
311 | unsigned int *src, int nr) | |
2270890c | 312 | { |
838bc709 | 313 | unsigned long total = ts_total_io_u(ts); |
2270890c JA |
314 | int i; |
315 | ||
316 | /* | |
317 | * Do latency distribution calculations | |
318 | */ | |
04a0feae | 319 | for (i = 0; i < nr; i++) { |
838bc709 JA |
320 | if (total) { |
321 | dst[i] = (double) src[i] / (double) total; | |
322 | dst[i] *= 100.0; | |
323 | if (dst[i] < 0.01 && src[i]) | |
324 | dst[i] = 0.01; | |
325 | } else | |
326 | dst[i] = 0.0; | |
2270890c JA |
327 | } |
328 | } | |
329 | ||
04a0feae JA |
330 | static void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat) |
331 | { | |
332 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR); | |
333 | } | |
334 | ||
335 | static void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat) | |
336 | { | |
337 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR); | |
338 | } | |
339 | ||
b29ad562 JA |
340 | static void display_lat(const char *name, unsigned long min, unsigned long max, |
341 | double mean, double dev) | |
ea2accc5 | 342 | { |
b29ad562 JA |
343 | const char *base = "(usec)"; |
344 | char *minp, *maxp; | |
ea2accc5 | 345 | |
b29ad562 JA |
346 | if (!usec_to_msec(&min, &max, &mean, &dev)) |
347 | base = "(msec)"; | |
348 | ||
349 | minp = num2str(min, 6, 1, 0); | |
350 | maxp = num2str(max, 6, 1, 0); | |
351 | ||
352 | log_info(" %s %s: min=%s, max=%s, avg=%5.02f," | |
353 | " stdev=%5.02f\n", name, base, minp, maxp, mean, dev); | |
354 | ||
355 | free(minp); | |
356 | free(maxp); | |
ea2accc5 JA |
357 | } |
358 | ||
756867bd | 359 | static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, |
3c39a379 JA |
360 | int ddir) |
361 | { | |
3c9b60c1 | 362 | const char *ddir_str[] = { "read ", "write" }; |
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", |
5ec10eaa JA |
385 | ddir_str[ddir], io_p, bw_p, iops_p, |
386 | ts->runtime[ddir]); | |
dbe1125e JA |
387 | |
388 | free(io_p); | |
389 | free(bw_p); | |
b3605062 | 390 | free(iops_p); |
3c39a379 | 391 | |
b29ad562 JA |
392 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
393 | display_lat("slat", min, max, mean, dev); | |
394 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) | |
395 | display_lat("clat", min, max, mean, dev); | |
396 | if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) | |
397 | display_lat(" lat", min, max, mean, dev); | |
02af0988 | 398 | |
83349190 YH |
399 | if (ts->clat_percentiles) { |
400 | show_clat_percentiles(ts->io_u_plat[ddir], | |
401 | ts->clat_stat[ddir].samples, | |
402 | ts->percentile_list); | |
403 | } | |
079ad09b | 404 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
19d3e967 | 405 | double p_of_agg = 100.0; |
b7017e32 | 406 | const char *bw_str = "KB"; |
3c39a379 | 407 | |
2f2c6924 | 408 | if (rs->agg[ddir]) { |
19d3e967 JA |
409 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; |
410 | if (p_of_agg > 100.0) | |
411 | p_of_agg = 100.0; | |
412 | } | |
b7017e32 JA |
413 | |
414 | if (mean > 999999.9) { | |
415 | min /= 1000.0; | |
416 | max /= 1000.0; | |
417 | mean /= 1000.0; | |
418 | dev /= 1000.0; | |
419 | bw_str = "MB"; | |
420 | } | |
421 | ||
7e1773ba | 422 | log_info(" bw (%s/s) : min=%5lu, max=%5lu, per=%3.2f%%," |
b7017e32 JA |
423 | " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max, |
424 | p_of_agg, mean, dev); | |
3c39a379 JA |
425 | } |
426 | } | |
427 | ||
7e1773ba JA |
428 | static int show_lat(double *io_u_lat, int nr, const char **ranges, |
429 | const char *msg) | |
04a0feae | 430 | { |
7e1773ba | 431 | int new_line = 1, i, line = 0, shown = 0; |
04a0feae JA |
432 | |
433 | for (i = 0; i < nr; i++) { | |
434 | if (io_u_lat[i] <= 0.0) | |
435 | continue; | |
7e1773ba | 436 | shown = 1; |
04a0feae | 437 | if (new_line) { |
4539ed73 JA |
438 | if (line) |
439 | log_info("\n"); | |
7e1773ba | 440 | log_info(" lat (%s) : ", msg); |
04a0feae JA |
441 | new_line = 0; |
442 | line = 0; | |
443 | } | |
444 | if (line) | |
445 | log_info(", "); | |
446 | log_info("%s%3.2f%%", ranges[i], io_u_lat[i]); | |
447 | line++; | |
448 | if (line == 5) | |
449 | new_line = 1; | |
450 | } | |
7e1773ba JA |
451 | |
452 | if (shown) | |
453 | log_info("\n"); | |
454 | ||
455 | return shown; | |
04a0feae JA |
456 | } |
457 | ||
458 | static void show_lat_u(double *io_u_lat_u) | |
459 | { | |
460 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", | |
461 | "250=", "500=", "750=", "1000=", }; | |
462 | ||
463 | show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec"); | |
464 | } | |
465 | ||
466 | static void show_lat_m(double *io_u_lat_m) | |
467 | { | |
468 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", | |
469 | "250=", "500=", "750=", "1000=", "2000=", | |
470 | ">=2000=", }; | |
471 | ||
472 | show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec"); | |
473 | } | |
474 | ||
5a18988e JA |
475 | static void show_latencies(struct thread_stat *ts, double *io_u_lat_u, |
476 | double *io_u_lat_m) | |
04a0feae | 477 | { |
5a18988e JA |
478 | stat_calc_lat_u(ts, io_u_lat_u); |
479 | stat_calc_lat_m(ts, io_u_lat_m); | |
480 | ||
04a0feae JA |
481 | show_lat_u(io_u_lat_u); |
482 | show_lat_m(io_u_lat_m); | |
04a0feae JA |
483 | } |
484 | ||
a64e88da | 485 | void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs) |
3c39a379 JA |
486 | { |
487 | double usr_cpu, sys_cpu; | |
69008999 | 488 | unsigned long runtime; |
71619dc2 | 489 | double io_u_dist[FIO_IO_U_MAP_NR]; |
04a0feae JA |
490 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
491 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
3c39a379 | 492 | |
b4c5e1ac JA |
493 | if (!(ts->io_bytes[0] + ts->io_bytes[1]) && |
494 | !(ts->total_io_u[0] + ts->total_io_u[1])) | |
3c39a379 JA |
495 | return; |
496 | ||
5ec10eaa JA |
497 | if (!ts->error) { |
498 | log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n", | |
499 | ts->name, ts->groupid, ts->members, | |
5921e80c | 500 | ts->error, (int) ts->pid); |
5ec10eaa JA |
501 | } else { |
502 | log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d\n", | |
503 | ts->name, ts->groupid, ts->members, | |
5921e80c | 504 | ts->error, ts->verror, (int) ts->pid); |
5ec10eaa | 505 | } |
3c39a379 | 506 | |
259e47de | 507 | if (strlen(ts->description)) |
6d86144d | 508 | log_info(" Description : [%s]\n", ts->description); |
7bdce1bd | 509 | |
756867bd JA |
510 | if (ts->io_bytes[DDIR_READ]) |
511 | show_ddir_status(rs, ts, DDIR_READ); | |
512 | if (ts->io_bytes[DDIR_WRITE]) | |
513 | show_ddir_status(rs, ts, DDIR_WRITE); | |
3c39a379 | 514 | |
5a18988e | 515 | show_latencies(ts, io_u_lat_u, io_u_lat_m); |
7e1773ba | 516 | |
756867bd | 517 | runtime = ts->total_run_time; |
69008999 | 518 | if (runtime) { |
1e97cce9 | 519 | double runt = (double) runtime; |
3c39a379 | 520 | |
756867bd JA |
521 | usr_cpu = (double) ts->usr_time * 100 / runt; |
522 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
3c39a379 JA |
523 | } else { |
524 | usr_cpu = 0; | |
525 | sys_cpu = 0; | |
526 | } | |
527 | ||
5ec10eaa JA |
528 | log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu," |
529 | " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf); | |
71619dc2 | 530 | |
838bc709 | 531 | stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist); |
5ec10eaa JA |
532 | log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%," |
533 | " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], | |
534 | io_u_dist[1], io_u_dist[2], | |
535 | io_u_dist[3], io_u_dist[4], | |
536 | io_u_dist[5], io_u_dist[6]); | |
838bc709 JA |
537 | |
538 | stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist); | |
539 | log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," | |
540 | " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], | |
541 | io_u_dist[1], io_u_dist[2], | |
542 | io_u_dist[3], io_u_dist[4], | |
543 | io_u_dist[5], io_u_dist[6]); | |
544 | stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist); | |
545 | log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," | |
546 | " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], | |
547 | io_u_dist[1], io_u_dist[2], | |
548 | io_u_dist[3], io_u_dist[4], | |
549 | io_u_dist[5], io_u_dist[6]); | |
7e1773ba JA |
550 | log_info(" issued : total=r=%lu/w=%lu/d=%lu," |
551 | " short=r=%lu/w=%lu/d=%lu\n", | |
5ec10eaa | 552 | ts->total_io_u[0], ts->total_io_u[1], |
0d29de83 JA |
553 | ts->total_io_u[2], |
554 | ts->short_io_u[0], ts->short_io_u[1], | |
555 | ts->short_io_u[2]); | |
f2bba182 | 556 | if (ts->continue_on_error) { |
1ec99eea JA |
557 | log_info(" errors : total=%lu, first_error=%d/<%s>\n", |
558 | ts->total_err_count, | |
559 | ts->first_error, | |
560 | strerror(ts->first_error)); | |
f2bba182 | 561 | } |
3c39a379 JA |
562 | } |
563 | ||
756867bd | 564 | static void show_ddir_status_terse(struct thread_stat *ts, |
c6ae0a5b JA |
565 | struct group_run_stats *rs, int ddir) |
566 | { | |
567 | unsigned long min, max; | |
312b4af2 | 568 | unsigned long long bw, iops; |
1db92cb6 | 569 | unsigned int *ovals = NULL; |
c6ae0a5b | 570 | double mean, dev; |
1db92cb6 JA |
571 | unsigned int len, minv, maxv; |
572 | int i; | |
c6ae0a5b | 573 | |
ff58fced JA |
574 | assert(ddir_rw(ddir)); |
575 | ||
312b4af2 JA |
576 | iops = bw = 0; |
577 | if (ts->runtime[ddir]) { | |
578 | uint64_t runt = ts->runtime[ddir]; | |
579 | ||
580 | bw = ts->io_bytes[ddir] / runt; | |
581 | iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt; | |
582 | } | |
c6ae0a5b | 583 | |
312b4af2 | 584 | log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops, |
5ec10eaa | 585 | ts->runtime[ddir]); |
c6ae0a5b | 586 | |
079ad09b | 587 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
6d86144d | 588 | log_info(";%lu;%lu;%f;%f", min, max, mean, dev); |
c6ae0a5b | 589 | else |
6d86144d | 590 | log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
c6ae0a5b | 591 | |
079ad09b | 592 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) |
6d86144d | 593 | log_info(";%lu;%lu;%f;%f", min, max, mean, dev); |
c6ae0a5b | 594 | else |
6d86144d | 595 | log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
c6ae0a5b | 596 | |
1db92cb6 JA |
597 | if (ts->clat_percentiles) { |
598 | len = calc_clat_percentiles(ts->io_u_plat[ddir], | |
599 | ts->clat_stat[ddir].samples, | |
600 | ts->percentile_list, &ovals, &maxv, | |
601 | &minv); | |
602 | } else | |
603 | len = 0; | |
604 | ||
605 | for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { | |
606 | if (i >= len) { | |
607 | log_info(";0%%=0"); | |
608 | continue; | |
609 | } | |
610 | log_info(";%2.2f%%=%u", ts->percentile_list[i].u.f, ovals[i]); | |
611 | } | |
2341a37a K |
612 | |
613 | if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) | |
614 | log_info(";%lu;%lu;%f;%f", min, max, mean, dev); | |
615 | else | |
616 | log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); | |
617 | ||
1db92cb6 JA |
618 | if (ovals) |
619 | free(ovals); | |
620 | ||
079ad09b | 621 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
19d3e967 JA |
622 | double p_of_agg = 100.0; |
623 | ||
624 | if (rs->agg[ddir]) { | |
625 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; | |
626 | if (p_of_agg > 100.0) | |
627 | p_of_agg = 100.0; | |
628 | } | |
c6ae0a5b | 629 | |
6d86144d | 630 | log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev); |
c6ae0a5b | 631 | } else |
6d86144d | 632 | log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0); |
c6ae0a5b JA |
633 | } |
634 | ||
4d658652 JA |
635 | static void show_thread_status_terse_v2(struct thread_stat *ts, |
636 | struct group_run_stats *rs) | |
637 | { | |
638 | double io_u_dist[FIO_IO_U_MAP_NR]; | |
639 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; | |
640 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
641 | double usr_cpu, sys_cpu; | |
642 | int i; | |
643 | ||
644 | /* General Info */ | |
645 | log_info("2;%s;%d;%d", ts->name, ts->groupid, ts->error); | |
646 | /* Log Read Status */ | |
647 | show_ddir_status_terse(ts, rs, 0); | |
648 | /* Log Write Status */ | |
649 | show_ddir_status_terse(ts, rs, 1); | |
650 | ||
651 | /* CPU Usage */ | |
652 | if (ts->total_run_time) { | |
653 | double runt = (double) ts->total_run_time; | |
654 | ||
655 | usr_cpu = (double) ts->usr_time * 100 / runt; | |
656 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
657 | } else { | |
658 | usr_cpu = 0; | |
659 | sys_cpu = 0; | |
660 | } | |
661 | ||
662 | log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf, | |
663 | ts->minf); | |
664 | ||
665 | /* Calc % distribution of IO depths, usecond, msecond latency */ | |
666 | stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist); | |
667 | stat_calc_lat_u(ts, io_u_lat_u); | |
668 | stat_calc_lat_m(ts, io_u_lat_m); | |
669 | ||
670 | /* Only show fixed 7 I/O depth levels*/ | |
671 | log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", | |
672 | io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], | |
673 | io_u_dist[4], io_u_dist[5], io_u_dist[6]); | |
674 | ||
675 | /* Microsecond latency */ | |
676 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) | |
677 | log_info(";%3.2f%%", io_u_lat_u[i]); | |
678 | /* Millisecond latency */ | |
679 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) | |
680 | log_info(";%3.2f%%", io_u_lat_m[i]); | |
681 | /* Additional output if continue_on_error set - default off*/ | |
682 | if (ts->continue_on_error) | |
683 | log_info(";%lu;%d", ts->total_err_count, ts->first_error); | |
684 | log_info("\n"); | |
685 | ||
686 | /* Additional output if description is set */ | |
687 | if (ts->description) | |
688 | log_info(";%s", ts->description); | |
689 | ||
690 | log_info("\n"); | |
691 | } | |
692 | ||
312b4af2 | 693 | #define FIO_TERSE_VERSION "3" |
c6ae0a5b | 694 | |
4d658652 JA |
695 | static void show_thread_status_terse_v3(struct thread_stat *ts, |
696 | struct group_run_stats *rs) | |
c6ae0a5b | 697 | { |
2270890c | 698 | double io_u_dist[FIO_IO_U_MAP_NR]; |
04a0feae JA |
699 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
700 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
c6ae0a5b | 701 | double usr_cpu, sys_cpu; |
04a0feae | 702 | int i; |
c6ae0a5b | 703 | |
562c2d2f | 704 | /* General Info */ |
5e726d0a JA |
705 | log_info("%s;%s;%s;%d;%d", FIO_TERSE_VERSION, fio_version_string, |
706 | ts->name, ts->groupid, ts->error); | |
562c2d2f | 707 | /* Log Read Status */ |
756867bd | 708 | show_ddir_status_terse(ts, rs, 0); |
562c2d2f | 709 | /* Log Write Status */ |
756867bd | 710 | show_ddir_status_terse(ts, rs, 1); |
c6ae0a5b | 711 | |
562c2d2f | 712 | /* CPU Usage */ |
756867bd JA |
713 | if (ts->total_run_time) { |
714 | double runt = (double) ts->total_run_time; | |
c6ae0a5b | 715 | |
756867bd JA |
716 | usr_cpu = (double) ts->usr_time * 100 / runt; |
717 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
c6ae0a5b JA |
718 | } else { |
719 | usr_cpu = 0; | |
720 | sys_cpu = 0; | |
721 | } | |
722 | ||
5ec10eaa JA |
723 | log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf, |
724 | ts->minf); | |
2270890c | 725 | |
562c2d2f | 726 | /* Calc % distribution of IO depths, usecond, msecond latency */ |
838bc709 | 727 | stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist); |
04a0feae JA |
728 | stat_calc_lat_u(ts, io_u_lat_u); |
729 | stat_calc_lat_m(ts, io_u_lat_m); | |
2270890c | 730 | |
562c2d2f | 731 | /* Only show fixed 7 I/O depth levels*/ |
5ec10eaa JA |
732 | log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", |
733 | io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], | |
734 | io_u_dist[4], io_u_dist[5], io_u_dist[6]); | |
2270890c | 735 | |
562c2d2f | 736 | /* Microsecond latency */ |
04a0feae JA |
737 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) |
738 | log_info(";%3.2f%%", io_u_lat_u[i]); | |
562c2d2f | 739 | /* Millisecond latency */ |
04a0feae JA |
740 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) |
741 | log_info(";%3.2f%%", io_u_lat_m[i]); | |
f2f788dd JA |
742 | |
743 | /* disk util stats, if any */ | |
744 | show_disk_util(1); | |
745 | ||
562c2d2f | 746 | /* Additional output if continue_on_error set - default off*/ |
f2bba182 RR |
747 | if (ts->continue_on_error) |
748 | log_info(";%lu;%d", ts->total_err_count, ts->first_error); | |
04a0feae | 749 | log_info("\n"); |
2270890c | 750 | |
562c2d2f | 751 | /* Additional output if description is set */ |
4b0f2258 | 752 | if (strlen(ts->description)) |
6d86144d | 753 | log_info(";%s", ts->description); |
756867bd JA |
754 | } |
755 | ||
4d658652 JA |
756 | static void show_thread_status_terse(struct thread_stat *ts, |
757 | struct group_run_stats *rs) | |
758 | { | |
759 | if (terse_version == 2) | |
760 | show_thread_status_terse_v2(ts, rs); | |
761 | else if (terse_version == 3) | |
762 | show_thread_status_terse_v3(ts, rs); | |
763 | else | |
764 | log_err("fio: bad terse version!? %d\n", terse_version); | |
765 | } | |
766 | ||
197574e4 | 767 | static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr) |
756867bd JA |
768 | { |
769 | double mean, S; | |
770 | ||
e09231c2 ZL |
771 | if (src->samples == 0) |
772 | return; | |
773 | ||
756867bd JA |
774 | dst->min_val = min(dst->min_val, src->min_val); |
775 | dst->max_val = max(dst->max_val, src->max_val); | |
756867bd JA |
776 | |
777 | /* | |
cdcac5cf YH |
778 | * Compute new mean and S after the merge |
779 | * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance | |
780 | * #Parallel_algorithm> | |
756867bd JA |
781 | */ |
782 | if (nr == 1) { | |
802ad4a8 JA |
783 | mean = src->mean.u.f; |
784 | S = src->S.u.f; | |
756867bd | 785 | } else { |
802ad4a8 | 786 | double delta = src->mean.u.f - dst->mean.u.f; |
cdcac5cf | 787 | |
802ad4a8 JA |
788 | mean = ((src->mean.u.f * src->samples) + |
789 | (dst->mean.u.f * dst->samples)) / | |
cdcac5cf YH |
790 | (dst->samples + src->samples); |
791 | ||
802ad4a8 | 792 | S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) * |
cdcac5cf YH |
793 | (dst->samples * src->samples) / |
794 | (dst->samples + src->samples); | |
756867bd JA |
795 | } |
796 | ||
cdcac5cf | 797 | dst->samples += src->samples; |
802ad4a8 JA |
798 | dst->mean.u.f = mean; |
799 | dst->S.u.f = S; | |
756867bd JA |
800 | } |
801 | ||
37f0c1ae JA |
802 | void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src) |
803 | { | |
804 | int i; | |
805 | ||
806 | for (i = 0; i < 2; i++) { | |
807 | if (dst->max_run[i] < src->max_run[i]) | |
808 | dst->max_run[i] = src->max_run[i]; | |
809 | if (dst->min_run[i] && dst->min_run[i] > src->min_run[i]) | |
810 | dst->min_run[i] = src->min_run[i]; | |
811 | if (dst->max_bw[i] < src->max_bw[i]) | |
812 | dst->max_bw[i] = src->max_bw[i]; | |
813 | if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i]) | |
814 | dst->min_bw[i] = src->min_bw[i]; | |
815 | ||
816 | dst->io_kb[i] += src->io_kb[i]; | |
817 | dst->agg[i] += src->agg[i]; | |
818 | } | |
819 | ||
820 | } | |
821 | ||
5b9babb7 JA |
822 | void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr) |
823 | { | |
824 | int l, k; | |
825 | ||
826 | for (l = 0; l <= DDIR_WRITE; l++) { | |
827 | sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr); | |
828 | sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr); | |
829 | sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr); | |
830 | sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr); | |
831 | ||
832 | dst->io_bytes[l] += src->io_bytes[l]; | |
833 | ||
834 | if (dst->runtime[l] < src->runtime[l]) | |
835 | dst->runtime[l] = src->runtime[l]; | |
836 | } | |
837 | ||
838 | dst->usr_time += src->usr_time; | |
839 | dst->sys_time += src->sys_time; | |
840 | dst->ctx += src->ctx; | |
841 | dst->majf += src->majf; | |
842 | dst->minf += src->minf; | |
843 | ||
844 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) | |
845 | dst->io_u_map[k] += src->io_u_map[k]; | |
846 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) | |
847 | dst->io_u_submit[k] += src->io_u_submit[k]; | |
848 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) | |
849 | dst->io_u_complete[k] += src->io_u_complete[k]; | |
850 | for (k = 0; k < FIO_IO_U_LAT_U_NR; k++) | |
851 | dst->io_u_lat_u[k] += src->io_u_lat_u[k]; | |
852 | for (k = 0; k < FIO_IO_U_LAT_M_NR; k++) | |
853 | dst->io_u_lat_m[k] += src->io_u_lat_m[k]; | |
854 | ||
855 | for (k = 0; k <= 2; k++) { | |
856 | dst->total_io_u[k] += src->total_io_u[k]; | |
857 | dst->short_io_u[k] += src->short_io_u[k]; | |
858 | } | |
859 | ||
860 | for (k = 0; k <= DDIR_WRITE; k++) { | |
861 | int m; | |
862 | for (m = 0; m < FIO_IO_U_PLAT_NR; m++) | |
863 | dst->io_u_plat[k][m] += src->io_u_plat[k][m]; | |
864 | } | |
865 | ||
866 | dst->total_run_time += src->total_run_time; | |
867 | dst->total_submit += src->total_submit; | |
868 | dst->total_complete += src->total_complete; | |
869 | } | |
870 | ||
37f0c1ae JA |
871 | void init_group_run_stat(struct group_run_stats *gs) |
872 | { | |
873 | memset(gs, 0, sizeof(*gs)); | |
874 | gs->min_bw[0] = gs->min_run[0] = ~0UL; | |
875 | gs->min_bw[1] = gs->min_run[1] = ~0UL; | |
876 | } | |
877 | ||
878 | void init_thread_stat(struct thread_stat *ts) | |
879 | { | |
880 | int j; | |
881 | ||
882 | memset(ts, 0, sizeof(*ts)); | |
883 | ||
884 | for (j = 0; j <= DDIR_WRITE; j++) { | |
885 | ts->lat_stat[j].min_val = -1UL; | |
886 | ts->clat_stat[j].min_val = -1UL; | |
887 | ts->slat_stat[j].min_val = -1UL; | |
888 | ts->bw_stat[j].min_val = -1UL; | |
889 | } | |
890 | ts->groupid = -1; | |
891 | } | |
892 | ||
3c39a379 JA |
893 | void show_run_stats(void) |
894 | { | |
895 | struct group_run_stats *runstats, *rs; | |
896 | struct thread_data *td; | |
756867bd | 897 | struct thread_stat *threadstats, *ts; |
5b9babb7 | 898 | int i, j, nr_ts, last_ts, idx; |
90fef2d1 | 899 | int kb_base_warned = 0; |
3c39a379 JA |
900 | |
901 | runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); | |
902 | ||
37f0c1ae JA |
903 | for (i = 0; i < groupid + 1; i++) |
904 | init_group_run_stat(&runstats[i]); | |
3c39a379 | 905 | |
756867bd JA |
906 | /* |
907 | * find out how many threads stats we need. if group reporting isn't | |
908 | * enabled, it's one-per-td. | |
909 | */ | |
910 | nr_ts = 0; | |
911 | last_ts = -1; | |
912 | for_each_td(td, i) { | |
2dc1bbeb | 913 | if (!td->o.group_reporting) { |
756867bd JA |
914 | nr_ts++; |
915 | continue; | |
916 | } | |
917 | if (last_ts == td->groupid) | |
918 | continue; | |
919 | ||
920 | last_ts = td->groupid; | |
921 | nr_ts++; | |
922 | } | |
923 | ||
924 | threadstats = malloc(nr_ts * sizeof(struct thread_stat)); | |
925 | ||
37f0c1ae JA |
926 | for (i = 0; i < nr_ts; i++) |
927 | init_thread_stat(&threadstats[i]); | |
756867bd JA |
928 | |
929 | j = 0; | |
930 | last_ts = -1; | |
197574e4 | 931 | idx = 0; |
34572e28 | 932 | for_each_td(td, i) { |
2dc1bbeb JA |
933 | if (idx && (!td->o.group_reporting || |
934 | (td->o.group_reporting && last_ts != td->groupid))) { | |
7abd0e3a JA |
935 | idx = 0; |
936 | j++; | |
937 | } | |
938 | ||
939 | last_ts = td->groupid; | |
940 | ||
756867bd JA |
941 | ts = &threadstats[j]; |
942 | ||
83349190 YH |
943 | ts->clat_percentiles = td->o.clat_percentiles; |
944 | if (td->o.overwrite_plist) | |
802ad4a8 | 945 | memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list)); |
83349190 | 946 | else |
802ad4a8 | 947 | memcpy(ts->percentile_list, def_percentile_list, sizeof(def_percentile_list)); |
83349190 | 948 | |
197574e4 | 949 | idx++; |
6586ee89 | 950 | ts->members++; |
756867bd | 951 | |
7abd0e3a | 952 | if (ts->groupid == -1) { |
2dc84ba7 JA |
953 | /* |
954 | * These are per-group shared already | |
955 | */ | |
f6bb5b88 | 956 | strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE); |
a64e88da JA |
957 | if (td->o.description) |
958 | strncpy(ts->description, td->o.description, | |
959 | FIO_JOBNAME_SIZE); | |
960 | else | |
961 | memset(ts->description, 0, FIO_JOBNAME_SIZE); | |
962 | ||
756867bd | 963 | ts->groupid = td->groupid; |
2dc84ba7 JA |
964 | |
965 | /* | |
966 | * first pid in group, not very useful... | |
967 | */ | |
756867bd | 968 | ts->pid = td->pid; |
90fef2d1 JA |
969 | |
970 | ts->kb_base = td->o.kb_base; | |
971 | } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) { | |
972 | log_info("fio: kb_base differs for jobs in group, using" | |
973 | " %u as the base\n", ts->kb_base); | |
974 | kb_base_warned = 1; | |
2dc84ba7 JA |
975 | } |
976 | ||
f2bba182 RR |
977 | ts->continue_on_error = td->o.continue_on_error; |
978 | ts->total_err_count += td->total_err_count; | |
979 | ts->first_error = td->first_error; | |
980 | if (!ts->error) { | |
981 | if (!td->error && td->o.continue_on_error && | |
982 | td->first_error) { | |
983 | ts->error = td->first_error; | |
f6bb5b88 | 984 | strcpy(ts->verror, td->verror); |
f2bba182 RR |
985 | } else if (td->error) { |
986 | ts->error = td->error; | |
f6bb5b88 | 987 | strcpy(ts->verror, td->verror); |
f2bba182 | 988 | } |
756867bd JA |
989 | } |
990 | ||
5b9babb7 | 991 | sum_thread_stats(ts, &td->ts, idx); |
756867bd JA |
992 | } |
993 | ||
994 | for (i = 0; i < nr_ts; i++) { | |
94370ac4 | 995 | unsigned long long bw; |
3c39a379 | 996 | |
756867bd JA |
997 | ts = &threadstats[i]; |
998 | rs = &runstats[ts->groupid]; | |
90fef2d1 | 999 | rs->kb_base = ts->kb_base; |
3c39a379 | 1000 | |
de64df05 | 1001 | for (j = 0; j <= DDIR_WRITE; j++) { |
94370ac4 JA |
1002 | if (!ts->runtime[j]) |
1003 | continue; | |
1004 | if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j]) | |
1005 | rs->min_run[j] = ts->runtime[j]; | |
1006 | if (ts->runtime[j] > rs->max_run[j]) | |
1007 | rs->max_run[j] = ts->runtime[j]; | |
1008 | ||
1009 | bw = 0; | |
8879fd15 JA |
1010 | if (ts->runtime[j]) { |
1011 | unsigned long runt; | |
1012 | ||
90fef2d1 | 1013 | runt = ts->runtime[j]; |
8879fd15 JA |
1014 | bw = ts->io_bytes[j] / runt; |
1015 | } | |
94370ac4 JA |
1016 | if (bw < rs->min_bw[j]) |
1017 | rs->min_bw[j] = bw; | |
1018 | if (bw > rs->max_bw[j]) | |
1019 | rs->max_bw[j] = bw; | |
1020 | ||
90fef2d1 | 1021 | rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base; |
94370ac4 | 1022 | } |
3c39a379 JA |
1023 | } |
1024 | ||
1025 | for (i = 0; i < groupid + 1; i++) { | |
8879fd15 JA |
1026 | unsigned long max_run[2]; |
1027 | ||
3c39a379 | 1028 | rs = &runstats[i]; |
90fef2d1 JA |
1029 | max_run[0] = rs->max_run[0]; |
1030 | max_run[1] = rs->max_run[1]; | |
3c39a379 JA |
1031 | |
1032 | if (rs->max_run[0]) | |
4cf1abc3 | 1033 | rs->agg[0] = (rs->io_kb[0] * 1000) / max_run[0]; |
3c39a379 | 1034 | if (rs->max_run[1]) |
4cf1abc3 | 1035 | rs->agg[1] = (rs->io_kb[1] * 1000) / max_run[1]; |
3c39a379 JA |
1036 | } |
1037 | ||
1038 | /* | |
1039 | * don't overwrite last signal output | |
1040 | */ | |
c6ae0a5b | 1041 | if (!terse_output) |
4ceb30d4 | 1042 | log_info("\n"); |
3c39a379 | 1043 | |
756867bd JA |
1044 | for (i = 0; i < nr_ts; i++) { |
1045 | ts = &threadstats[i]; | |
1046 | rs = &runstats[ts->groupid]; | |
3c39a379 | 1047 | |
a64e88da JA |
1048 | if (is_backend) |
1049 | fio_server_send_ts(ts, rs); | |
1050 | else if (terse_output) | |
756867bd | 1051 | show_thread_status_terse(ts, rs); |
c6ae0a5b | 1052 | else |
756867bd | 1053 | show_thread_status(ts, rs); |
3c39a379 JA |
1054 | } |
1055 | ||
72c27ff8 JA |
1056 | for (i = 0; i < groupid + 1; i++) { |
1057 | rs = &runstats[i]; | |
3c39a379 | 1058 | |
72c27ff8 | 1059 | rs->groupid = i; |
d09a64a0 | 1060 | if (is_backend) |
72c27ff8 JA |
1061 | fio_server_send_gs(rs); |
1062 | else if (!terse_output) | |
1063 | show_group_stats(rs); | |
c6ae0a5b | 1064 | } |
eecf272f | 1065 | |
72c27ff8 JA |
1066 | if (is_backend) |
1067 | fio_server_send_du(); | |
1068 | else if (!terse_output) | |
1069 | show_disk_util(0); | |
1070 | ||
1071 | free_disk_util(); | |
1072 | ||
eecf272f | 1073 | free(runstats); |
756867bd | 1074 | free(threadstats); |
3c39a379 JA |
1075 | } |
1076 | ||
68704084 | 1077 | static inline void add_stat_sample(struct io_stat *is, unsigned long data) |
3c39a379 | 1078 | { |
68704084 | 1079 | double val = data; |
6660cc67 | 1080 | double delta; |
68704084 JA |
1081 | |
1082 | if (data > is->max_val) | |
1083 | is->max_val = data; | |
1084 | if (data < is->min_val) | |
1085 | is->min_val = data; | |
1086 | ||
802ad4a8 | 1087 | delta = val - is->mean.u.f; |
ef11d737 | 1088 | if (delta) { |
802ad4a8 JA |
1089 | is->mean.u.f += delta / (is->samples + 1.0); |
1090 | is->S.u.f += delta * (val - is->mean.u.f); | |
ef11d737 | 1091 | } |
3c39a379 | 1092 | |
3c39a379 JA |
1093 | is->samples++; |
1094 | } | |
1095 | ||
bb3884d8 | 1096 | static void __add_log_sample(struct io_log *iolog, unsigned long val, |
306ddc97 | 1097 | enum fio_ddir ddir, unsigned int bs, |
2b13e716 | 1098 | unsigned long t) |
3c39a379 | 1099 | { |
306ddc97 JA |
1100 | const int nr_samples = iolog->nr_samples; |
1101 | ||
b8bc8cba JA |
1102 | if (!iolog->nr_samples) |
1103 | iolog->avg_last = t; | |
1104 | ||
3c39a379 JA |
1105 | if (iolog->nr_samples == iolog->max_samples) { |
1106 | int new_size = sizeof(struct io_sample) * iolog->max_samples*2; | |
1107 | ||
1108 | iolog->log = realloc(iolog->log, new_size); | |
1109 | iolog->max_samples <<= 1; | |
1110 | } | |
1111 | ||
306ddc97 | 1112 | iolog->log[nr_samples].val = val; |
2b13e716 | 1113 | iolog->log[nr_samples].time = t; |
306ddc97 JA |
1114 | iolog->log[nr_samples].ddir = ddir; |
1115 | iolog->log[nr_samples].bs = bs; | |
3c39a379 JA |
1116 | iolog->nr_samples++; |
1117 | } | |
1118 | ||
7fb28d36 JA |
1119 | static inline void reset_io_stat(struct io_stat *ios) |
1120 | { | |
1121 | ios->max_val = ios->min_val = ios->samples = 0; | |
1122 | ios->mean.u.f = ios->S.u.f = 0; | |
1123 | } | |
1124 | ||
bb3884d8 | 1125 | static void add_log_sample(struct thread_data *td, struct io_log *iolog, |
306ddc97 JA |
1126 | unsigned long val, enum fio_ddir ddir, |
1127 | unsigned int bs) | |
bb3884d8 | 1128 | { |
7fb28d36 | 1129 | unsigned long elapsed, this_window; |
b8bc8cba | 1130 | |
ff58fced JA |
1131 | if (!ddir_rw(ddir)) |
1132 | return; | |
1133 | ||
b8bc8cba JA |
1134 | elapsed = mtime_since_now(&td->epoch); |
1135 | ||
1136 | /* | |
1137 | * If no time averaging, just add the log sample. | |
1138 | */ | |
1139 | if (!iolog->avg_msec) { | |
1140 | __add_log_sample(iolog, val, ddir, bs, elapsed); | |
1141 | return; | |
1142 | } | |
1143 | ||
1144 | /* | |
1145 | * Add the sample. If the time period has passed, then | |
1146 | * add that entry to the log and clear. | |
1147 | */ | |
1148 | add_stat_sample(&iolog->avg_window[ddir], val); | |
1149 | ||
7fb28d36 JA |
1150 | /* |
1151 | * If period hasn't passed, adding the above sample is all we | |
1152 | * need to do. | |
1153 | */ | |
b8bc8cba JA |
1154 | this_window = elapsed - iolog->avg_last; |
1155 | if (this_window < iolog->avg_msec) | |
1156 | return; | |
1157 | ||
7fb28d36 JA |
1158 | /* |
1159 | * Note an entry in the log. Use the mean from the logged samples, | |
1160 | * making sure to properly round up. Only write a log entry if we | |
1161 | * had actual samples done. | |
1162 | */ | |
1163 | if (iolog->avg_window[DDIR_READ].samples) { | |
1164 | unsigned long mr; | |
b8bc8cba | 1165 | |
7fb28d36 | 1166 | mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50; |
b8bc8cba | 1167 | __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed); |
7fb28d36 JA |
1168 | } |
1169 | if (iolog->avg_window[DDIR_WRITE].samples) { | |
1170 | unsigned long mw; | |
1171 | ||
1172 | mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50; | |
b8bc8cba | 1173 | __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed); |
7fb28d36 | 1174 | } |
b8bc8cba | 1175 | |
7fb28d36 JA |
1176 | reset_io_stat(&iolog->avg_window[DDIR_READ]); |
1177 | reset_io_stat(&iolog->avg_window[DDIR_WRITE]); | |
b8bc8cba | 1178 | iolog->avg_last = elapsed; |
bb3884d8 JA |
1179 | } |
1180 | ||
306ddc97 | 1181 | void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs) |
bb3884d8 | 1182 | { |
ff58fced | 1183 | struct io_log *iolog; |
bb3884d8 | 1184 | |
ff58fced JA |
1185 | if (!ddir_rw(ddir)) |
1186 | return; | |
1187 | ||
1188 | iolog = agg_io_log[ddir]; | |
306ddc97 | 1189 | __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis()); |
bb3884d8 JA |
1190 | } |
1191 | ||
83349190 YH |
1192 | static void add_clat_percentile_sample(struct thread_stat *ts, |
1193 | unsigned long usec, enum fio_ddir ddir) | |
1194 | { | |
1195 | unsigned int idx = plat_val_to_idx(usec); | |
1196 | assert(idx < FIO_IO_U_PLAT_NR); | |
1197 | ||
1198 | ts->io_u_plat[ddir][idx]++; | |
1199 | } | |
1200 | ||
1e97cce9 | 1201 | void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, |
306ddc97 | 1202 | unsigned long usec, unsigned int bs) |
3c39a379 | 1203 | { |
756867bd | 1204 | struct thread_stat *ts = &td->ts; |
079ad09b | 1205 | |
ff58fced JA |
1206 | if (!ddir_rw(ddir)) |
1207 | return; | |
1208 | ||
d85f5118 | 1209 | add_stat_sample(&ts->clat_stat[ddir], usec); |
3c39a379 | 1210 | |
7b9f733a JA |
1211 | if (td->clat_log) |
1212 | add_log_sample(td, td->clat_log, usec, ddir, bs); | |
83349190 YH |
1213 | |
1214 | if (ts->clat_percentiles) | |
1215 | add_clat_percentile_sample(ts, usec, ddir); | |
3c39a379 JA |
1216 | } |
1217 | ||
1e97cce9 | 1218 | void add_slat_sample(struct thread_data *td, enum fio_ddir ddir, |
306ddc97 | 1219 | unsigned long usec, unsigned int bs) |
3c39a379 | 1220 | { |
756867bd | 1221 | struct thread_stat *ts = &td->ts; |
079ad09b | 1222 | |
ff58fced JA |
1223 | if (!ddir_rw(ddir)) |
1224 | return; | |
1225 | ||
d85f5118 | 1226 | add_stat_sample(&ts->slat_stat[ddir], usec); |
3c39a379 | 1227 | |
7b9f733a JA |
1228 | if (td->slat_log) |
1229 | add_log_sample(td, td->slat_log, usec, ddir, bs); | |
3c39a379 JA |
1230 | } |
1231 | ||
02af0988 JA |
1232 | void add_lat_sample(struct thread_data *td, enum fio_ddir ddir, |
1233 | unsigned long usec, unsigned int bs) | |
1234 | { | |
1235 | struct thread_stat *ts = &td->ts; | |
1236 | ||
ff58fced JA |
1237 | if (!ddir_rw(ddir)) |
1238 | return; | |
1239 | ||
02af0988 JA |
1240 | add_stat_sample(&ts->lat_stat[ddir], usec); |
1241 | ||
7b9f733a JA |
1242 | if (td->lat_log) |
1243 | add_log_sample(td, td->lat_log, usec, ddir, bs); | |
02af0988 JA |
1244 | } |
1245 | ||
306ddc97 | 1246 | void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs, |
1e97cce9 | 1247 | struct timeval *t) |
3c39a379 | 1248 | { |
756867bd | 1249 | struct thread_stat *ts = &td->ts; |
ff58fced JA |
1250 | unsigned long spent, rate; |
1251 | ||
1252 | if (!ddir_rw(ddir)) | |
1253 | return; | |
3c39a379 | 1254 | |
c8eeb9df | 1255 | spent = mtime_since(&td->bw_sample_time, t); |
2dc1bbeb | 1256 | if (spent < td->o.bw_avg_time) |
3c39a379 | 1257 | return; |
9602d8df JA |
1258 | |
1259 | /* | |
5daa4ebe JC |
1260 | * Compute both read and write rates for the interval. |
1261 | */ | |
1262 | for (ddir = DDIR_READ; ddir <= DDIR_WRITE; ddir++) { | |
1263 | uint64_t delta; | |
1264 | ||
1265 | delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir]; | |
1266 | if (!delta) | |
1267 | continue; /* No entries for interval */ | |
3c39a379 | 1268 | |
5daa4ebe JC |
1269 | rate = delta * 1000 / spent / 1024; |
1270 | add_stat_sample(&ts->bw_stat[ddir], rate); | |
3c39a379 | 1271 | |
5daa4ebe JC |
1272 | if (td->bw_log) |
1273 | add_log_sample(td, td->bw_log, rate, ddir, bs); | |
1274 | ||
1275 | td->stat_io_bytes[ddir] = td->this_io_bytes[ddir]; | |
1276 | } | |
3c39a379 | 1277 | |
c8eeb9df | 1278 | fio_gettime(&td->bw_sample_time, NULL); |
3c39a379 | 1279 | } |
c8eeb9df JA |
1280 | |
1281 | void add_iops_sample(struct thread_data *td, enum fio_ddir ddir, | |
1282 | struct timeval *t) | |
1283 | { | |
1284 | struct thread_stat *ts = &td->ts; | |
1285 | unsigned long spent, iops; | |
1286 | ||
1287 | if (!ddir_rw(ddir)) | |
1288 | return; | |
1289 | ||
1290 | spent = mtime_since(&td->iops_sample_time, t); | |
1291 | if (spent < td->o.iops_avg_time) | |
1292 | return; | |
1293 | ||
9602d8df JA |
1294 | /* |
1295 | * Compute both read and write rates for the interval. | |
1296 | */ | |
1297 | for (ddir = DDIR_READ; ddir <= DDIR_WRITE; ddir++) { | |
1298 | uint64_t delta; | |
c8eeb9df | 1299 | |
9602d8df JA |
1300 | delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir]; |
1301 | if (!delta) | |
1302 | continue; /* No entries for interval */ | |
1303 | ||
1304 | iops = (delta * 1000) / spent; | |
1305 | add_stat_sample(&ts->iops_stat[ddir], iops); | |
c8eeb9df | 1306 | |
9602d8df JA |
1307 | if (td->iops_log) |
1308 | add_log_sample(td, td->iops_log, iops, ddir, 0); | |
1309 | ||
421f4a82 | 1310 | td->stat_io_blocks[ddir] = td->this_io_blocks[ddir]; |
9602d8df | 1311 | } |
c8eeb9df JA |
1312 | |
1313 | fio_gettime(&td->iops_sample_time, NULL); | |
c8eeb9df | 1314 | } |