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" | |
3c39a379 | 11 | |
dbe1125e | 12 | /* |
34403fb1 | 13 | * Cheesy number->string conversion, complete with carry rounding error. |
dbe1125e | 14 | */ |
b3605062 | 15 | static char *num2str(unsigned long num, int maxlen, int base, int pow2) |
dbe1125e | 16 | { |
b3605062 JA |
17 | char postfix[] = { ' ', 'K', 'M', 'G', 'P', 'E' }; |
18 | unsigned int thousand; | |
dbe1125e JA |
19 | char *buf; |
20 | int i; | |
21 | ||
b3605062 JA |
22 | if (pow2) |
23 | thousand = 1024; | |
24 | else | |
25 | thousand = 1000; | |
26 | ||
dbe1125e JA |
27 | buf = malloc(128); |
28 | ||
29 | for (i = 0; base > 1; i++) | |
30 | base /= thousand; | |
31 | ||
32 | do { | |
33 | int len, carry = 0; | |
34 | ||
35 | len = sprintf(buf, "%'lu", num); | |
36 | if (len <= maxlen) { | |
b3605062 JA |
37 | if (i >= 1) { |
38 | buf[len] = postfix[i]; | |
39 | buf[len + 1] = '\0'; | |
40 | } | |
dbe1125e JA |
41 | return buf; |
42 | } | |
43 | ||
44 | if ((num % thousand) >= (thousand / 2)) | |
45 | carry = 1; | |
46 | ||
47 | num /= thousand; | |
48 | num += carry; | |
49 | i++; | |
f3502ba2 | 50 | } while (i <= 5); |
dbe1125e JA |
51 | |
52 | return buf; | |
53 | } | |
54 | ||
3c39a379 JA |
55 | void update_rusage_stat(struct thread_data *td) |
56 | { | |
756867bd | 57 | struct thread_stat *ts = &td->ts; |
3c39a379 | 58 | |
079ad09b JA |
59 | getrusage(RUSAGE_SELF, &ts->ru_end); |
60 | ||
5ec10eaa JA |
61 | ts->usr_time += mtime_since(&ts->ru_start.ru_utime, |
62 | &ts->ru_end.ru_utime); | |
63 | ts->sys_time += mtime_since(&ts->ru_start.ru_stime, | |
64 | &ts->ru_end.ru_stime); | |
65 | ts->ctx += ts->ru_end.ru_nvcsw + ts->ru_end.ru_nivcsw | |
66 | - (ts->ru_start.ru_nvcsw + ts->ru_start.ru_nivcsw); | |
e7823a94 JA |
67 | ts->minf += ts->ru_end.ru_minflt - ts->ru_start.ru_minflt; |
68 | ts->majf += ts->ru_end.ru_majflt - ts->ru_start.ru_majflt; | |
5ec10eaa | 69 | |
079ad09b | 70 | memcpy(&ts->ru_start, &ts->ru_end, sizeof(ts->ru_end)); |
3c39a379 JA |
71 | } |
72 | ||
73 | static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max, | |
74 | double *mean, double *dev) | |
75 | { | |
68704084 | 76 | double n = is->samples; |
3c39a379 JA |
77 | |
78 | if (is->samples == 0) | |
79 | return 0; | |
80 | ||
81 | *min = is->min_val; | |
82 | *max = is->max_val; | |
83 | ||
84 | n = (double) is->samples; | |
68704084 | 85 | *mean = is->mean; |
e6d276f2 | 86 | |
68704084 JA |
87 | if (n > 1.0) |
88 | *dev = sqrt(is->S / (n - 1.0)); | |
ef9c5c40 | 89 | else |
4b43f54e | 90 | *dev = 0; |
ef9c5c40 | 91 | |
3c39a379 JA |
92 | return 1; |
93 | } | |
94 | ||
95 | static void show_group_stats(struct group_run_stats *rs, int id) | |
96 | { | |
dbe1125e JA |
97 | char *p1, *p2, *p3, *p4; |
98 | const char *ddir_str[] = { " READ", " WRITE" }; | |
99 | int i; | |
100 | ||
6d86144d | 101 | log_info("\nRun status group %d (all jobs):\n", id); |
3c39a379 | 102 | |
dbe1125e JA |
103 | for (i = 0; i <= DDIR_WRITE; i++) { |
104 | if (!rs->max_run[i]) | |
105 | continue; | |
106 | ||
b3605062 JA |
107 | p1 = num2str(rs->io_kb[i], 6, 1000, 1); |
108 | p2 = num2str(rs->agg[i], 6, 1000, 1); | |
109 | p3 = num2str(rs->min_bw[i], 6, 1000, 1); | |
110 | p4 = num2str(rs->max_bw[i], 6, 1000, 1); | |
dbe1125e | 111 | |
5ec10eaa JA |
112 | log_info("%s: io=%siB, aggrb=%siB/s, minb=%siB/s, maxb=%siB/s," |
113 | " mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2, | |
114 | p3, p4, rs->min_run[i], | |
115 | rs->max_run[i]); | |
dbe1125e JA |
116 | |
117 | free(p1); | |
118 | free(p2); | |
119 | free(p3); | |
120 | free(p4); | |
121 | } | |
3c39a379 JA |
122 | } |
123 | ||
b3605062 JA |
124 | #define ts_total_io_u(ts) \ |
125 | ((ts)->total_io_u[0] + (ts)->total_io_u[1]) | |
126 | ||
2270890c JA |
127 | static void stat_calc_dist(struct thread_stat *ts, double *io_u_dist) |
128 | { | |
129 | int i; | |
130 | ||
131 | /* | |
132 | * Do depth distribution calculations | |
133 | */ | |
134 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { | |
5ec10eaa JA |
135 | io_u_dist[i] = (double) ts->io_u_map[i] |
136 | / (double) ts_total_io_u(ts); | |
2270890c | 137 | io_u_dist[i] *= 100.0; |
d0f62ba3 JA |
138 | if (io_u_dist[i] < 0.1 && ts->io_u_map[i]) |
139 | io_u_dist[i] = 0.1; | |
2270890c JA |
140 | } |
141 | } | |
142 | ||
04a0feae JA |
143 | static void stat_calc_lat(struct thread_stat *ts, double *dst, |
144 | unsigned int *src, int nr) | |
2270890c JA |
145 | { |
146 | int i; | |
147 | ||
148 | /* | |
149 | * Do latency distribution calculations | |
150 | */ | |
04a0feae JA |
151 | for (i = 0; i < nr; i++) { |
152 | dst[i] = (double) src[i] / (double) ts_total_io_u(ts); | |
153 | dst[i] *= 100.0; | |
154 | if (dst[i] < 0.01 && src[i]) | |
155 | dst[i] = 0.01; | |
2270890c JA |
156 | } |
157 | } | |
158 | ||
04a0feae JA |
159 | static void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat) |
160 | { | |
161 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR); | |
162 | } | |
163 | ||
164 | static void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat) | |
165 | { | |
166 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR); | |
167 | } | |
168 | ||
ea2accc5 JA |
169 | static int usec_to_msec(unsigned long *min, unsigned long *max, double *mean, |
170 | double *dev) | |
171 | { | |
172 | if (*min > 1000 && *max > 1000 && *mean > 1000.0 && *dev > 1000.0) { | |
173 | *min /= 1000; | |
174 | *max /= 1000; | |
175 | *mean /= 1000.0; | |
176 | *dev /= 1000.0; | |
177 | return 0; | |
178 | } | |
179 | ||
180 | return 1; | |
181 | } | |
182 | ||
756867bd | 183 | static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, |
3c39a379 JA |
184 | int ddir) |
185 | { | |
3c9b60c1 | 186 | const char *ddir_str[] = { "read ", "write" }; |
3c39a379 | 187 | unsigned long min, max; |
b3605062 | 188 | unsigned long long bw, iops; |
3c39a379 | 189 | double mean, dev; |
b3605062 | 190 | char *io_p, *bw_p, *iops_p; |
3c39a379 | 191 | |
756867bd | 192 | if (!ts->runtime[ddir]) |
3c39a379 JA |
193 | return; |
194 | ||
756867bd | 195 | bw = ts->io_bytes[ddir] / ts->runtime[ddir]; |
b3605062 JA |
196 | iops = (1000 * ts->total_io_u[ddir]) / ts->runtime[ddir]; |
197 | io_p = num2str(ts->io_bytes[ddir] >> 10, 6, 1000, 1); | |
198 | bw_p = num2str(bw, 6, 1000, 1); | |
199 | iops_p = num2str(iops, 6, 1, 0); | |
dbe1125e | 200 | |
5ec10eaa JA |
201 | log_info(" %s: io=%siB, bw=%siB/s, iops=%s, runt=%6lumsec\n", |
202 | ddir_str[ddir], io_p, bw_p, iops_p, | |
203 | ts->runtime[ddir]); | |
dbe1125e JA |
204 | |
205 | free(io_p); | |
206 | free(bw_p); | |
b3605062 | 207 | free(iops_p); |
3c39a379 | 208 | |
d85f5118 JA |
209 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) { |
210 | const char *base = "(usec)"; | |
d9309cb1 | 211 | char *minp, *maxp; |
d85f5118 | 212 | |
ea2accc5 | 213 | if (!usec_to_msec(&min, &max, &mean, &dev)) |
d85f5118 | 214 | base = "(msec)"; |
ea2accc5 | 215 | |
d9309cb1 JA |
216 | minp = num2str(min, 6, 1, 0); |
217 | maxp = num2str(max, 6, 1, 0); | |
218 | ||
5ec10eaa JA |
219 | log_info(" slat %s: min=%s, max=%s, avg=%5.02f," |
220 | " stdev=%5.02f\n", base, minp, maxp, mean, dev); | |
d9309cb1 JA |
221 | |
222 | free(minp); | |
223 | free(maxp); | |
d85f5118 JA |
224 | } |
225 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) { | |
226 | const char *base = "(usec)"; | |
d9309cb1 | 227 | char *minp, *maxp; |
d85f5118 | 228 | |
ea2accc5 JA |
229 | if (!usec_to_msec(&min, &max, &mean, &dev)) |
230 | base = "(msec)"; | |
231 | ||
d9309cb1 JA |
232 | minp = num2str(min, 6, 1, 0); |
233 | maxp = num2str(max, 6, 1, 0); | |
5ec10eaa JA |
234 | |
235 | log_info(" clat %s: min=%s, max=%s, avg=%5.02f," | |
236 | " stdev=%5.02f\n", base, minp, maxp, mean, dev); | |
d9309cb1 JA |
237 | |
238 | free(minp); | |
239 | free(maxp); | |
d85f5118 | 240 | } |
079ad09b | 241 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
3c39a379 JA |
242 | double p_of_agg; |
243 | ||
244 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; | |
5ec10eaa JA |
245 | log_info(" bw (KiB/s) : min=%5lu, max=%5lu, per=%3.2f%%," |
246 | " avg=%5.02f, stdev=%5.02f\n", min, max, p_of_agg, | |
247 | mean, dev); | |
3c39a379 JA |
248 | } |
249 | } | |
250 | ||
04a0feae JA |
251 | static void show_lat(double *io_u_lat, int nr, const char **ranges, |
252 | const char *msg) | |
253 | { | |
254 | int new_line = 1, i, line = 0; | |
255 | ||
256 | for (i = 0; i < nr; i++) { | |
257 | if (io_u_lat[i] <= 0.0) | |
258 | continue; | |
259 | if (new_line) { | |
4539ed73 JA |
260 | if (line) |
261 | log_info("\n"); | |
04a0feae JA |
262 | log_info(" lat (%s): ", msg); |
263 | new_line = 0; | |
264 | line = 0; | |
265 | } | |
266 | if (line) | |
267 | log_info(", "); | |
268 | log_info("%s%3.2f%%", ranges[i], io_u_lat[i]); | |
269 | line++; | |
270 | if (line == 5) | |
271 | new_line = 1; | |
272 | } | |
04a0feae JA |
273 | } |
274 | ||
275 | static void show_lat_u(double *io_u_lat_u) | |
276 | { | |
277 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", | |
278 | "250=", "500=", "750=", "1000=", }; | |
279 | ||
280 | show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec"); | |
281 | } | |
282 | ||
283 | static void show_lat_m(double *io_u_lat_m) | |
284 | { | |
285 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", | |
286 | "250=", "500=", "750=", "1000=", "2000=", | |
287 | ">=2000=", }; | |
288 | ||
289 | show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec"); | |
290 | } | |
291 | ||
292 | static void show_latencies(double *io_u_lat_u, double *io_u_lat_m) | |
293 | { | |
294 | show_lat_u(io_u_lat_u); | |
4539ed73 | 295 | log_info("\n"); |
04a0feae JA |
296 | show_lat_m(io_u_lat_m); |
297 | log_info("\n"); | |
298 | } | |
299 | ||
756867bd | 300 | static void show_thread_status(struct thread_stat *ts, |
3c39a379 JA |
301 | struct group_run_stats *rs) |
302 | { | |
303 | double usr_cpu, sys_cpu; | |
69008999 | 304 | unsigned long runtime; |
71619dc2 | 305 | double io_u_dist[FIO_IO_U_MAP_NR]; |
04a0feae JA |
306 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
307 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
3c39a379 | 308 | |
b4c5e1ac JA |
309 | if (!(ts->io_bytes[0] + ts->io_bytes[1]) && |
310 | !(ts->total_io_u[0] + ts->total_io_u[1])) | |
3c39a379 JA |
311 | return; |
312 | ||
5ec10eaa JA |
313 | if (!ts->error) { |
314 | log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n", | |
315 | ts->name, ts->groupid, ts->members, | |
316 | ts->error, ts->pid); | |
317 | } else { | |
318 | log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d\n", | |
319 | ts->name, ts->groupid, ts->members, | |
320 | ts->error, ts->verror, ts->pid); | |
321 | } | |
3c39a379 | 322 | |
7bdce1bd | 323 | if (ts->description) |
6d86144d | 324 | log_info(" Description : [%s]\n", ts->description); |
7bdce1bd | 325 | |
756867bd JA |
326 | if (ts->io_bytes[DDIR_READ]) |
327 | show_ddir_status(rs, ts, DDIR_READ); | |
328 | if (ts->io_bytes[DDIR_WRITE]) | |
329 | show_ddir_status(rs, ts, DDIR_WRITE); | |
3c39a379 | 330 | |
756867bd | 331 | runtime = ts->total_run_time; |
69008999 | 332 | if (runtime) { |
1e97cce9 | 333 | double runt = (double) runtime; |
3c39a379 | 334 | |
756867bd JA |
335 | usr_cpu = (double) ts->usr_time * 100 / runt; |
336 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
3c39a379 JA |
337 | } else { |
338 | usr_cpu = 0; | |
339 | sys_cpu = 0; | |
340 | } | |
341 | ||
5ec10eaa JA |
342 | log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu," |
343 | " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf); | |
71619dc2 | 344 | |
2270890c | 345 | stat_calc_dist(ts, io_u_dist); |
04a0feae JA |
346 | stat_calc_lat_u(ts, io_u_lat_u); |
347 | stat_calc_lat_m(ts, io_u_lat_m); | |
71619dc2 | 348 | |
5ec10eaa JA |
349 | log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%," |
350 | " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], | |
351 | io_u_dist[1], io_u_dist[2], | |
352 | io_u_dist[3], io_u_dist[4], | |
353 | io_u_dist[5], io_u_dist[6]); | |
354 | log_info(" issued r/w: total=%lu/%lu, short=%lu/%lu\n", | |
355 | ts->total_io_u[0], ts->total_io_u[1], | |
356 | ts->short_io_u[0], ts->short_io_u[1]); | |
61697c37 | 357 | |
04a0feae | 358 | show_latencies(io_u_lat_u, io_u_lat_m); |
3c39a379 JA |
359 | } |
360 | ||
756867bd | 361 | static void show_ddir_status_terse(struct thread_stat *ts, |
c6ae0a5b JA |
362 | struct group_run_stats *rs, int ddir) |
363 | { | |
364 | unsigned long min, max; | |
365 | unsigned long long bw; | |
366 | double mean, dev; | |
367 | ||
368 | bw = 0; | |
756867bd JA |
369 | if (ts->runtime[ddir]) |
370 | bw = ts->io_bytes[ddir] / ts->runtime[ddir]; | |
c6ae0a5b | 371 | |
5ec10eaa JA |
372 | log_info(";%llu;%llu;%lu", ts->io_bytes[ddir] >> 10, bw, |
373 | ts->runtime[ddir]); | |
c6ae0a5b | 374 | |
079ad09b | 375 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
6d86144d | 376 | log_info(";%lu;%lu;%f;%f", min, max, mean, dev); |
c6ae0a5b | 377 | else |
6d86144d | 378 | log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
c6ae0a5b | 379 | |
079ad09b | 380 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) |
6d86144d | 381 | log_info(";%lu;%lu;%f;%f", min, max, mean, dev); |
c6ae0a5b | 382 | else |
6d86144d | 383 | log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
c6ae0a5b | 384 | |
079ad09b | 385 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
c6ae0a5b JA |
386 | double p_of_agg; |
387 | ||
388 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; | |
6d86144d | 389 | log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev); |
c6ae0a5b | 390 | } else |
6d86144d | 391 | log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0); |
c6ae0a5b JA |
392 | } |
393 | ||
394 | ||
756867bd | 395 | static void show_thread_status_terse(struct thread_stat *ts, |
c6ae0a5b JA |
396 | struct group_run_stats *rs) |
397 | { | |
2270890c | 398 | double io_u_dist[FIO_IO_U_MAP_NR]; |
04a0feae JA |
399 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
400 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; | |
c6ae0a5b | 401 | double usr_cpu, sys_cpu; |
04a0feae | 402 | int i; |
c6ae0a5b | 403 | |
6d86144d | 404 | log_info("%s;%d;%d", ts->name, ts->groupid, ts->error); |
c6ae0a5b | 405 | |
756867bd JA |
406 | show_ddir_status_terse(ts, rs, 0); |
407 | show_ddir_status_terse(ts, rs, 1); | |
c6ae0a5b | 408 | |
756867bd JA |
409 | if (ts->total_run_time) { |
410 | double runt = (double) ts->total_run_time; | |
c6ae0a5b | 411 | |
756867bd JA |
412 | usr_cpu = (double) ts->usr_time * 100 / runt; |
413 | sys_cpu = (double) ts->sys_time * 100 / runt; | |
c6ae0a5b JA |
414 | } else { |
415 | usr_cpu = 0; | |
416 | sys_cpu = 0; | |
417 | } | |
418 | ||
5ec10eaa JA |
419 | log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf, |
420 | ts->minf); | |
2270890c JA |
421 | |
422 | stat_calc_dist(ts, io_u_dist); | |
04a0feae JA |
423 | stat_calc_lat_u(ts, io_u_lat_u); |
424 | stat_calc_lat_m(ts, io_u_lat_m); | |
2270890c | 425 | |
5ec10eaa JA |
426 | log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", |
427 | io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], | |
428 | io_u_dist[4], io_u_dist[5], io_u_dist[6]); | |
2270890c | 429 | |
04a0feae JA |
430 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) |
431 | log_info(";%3.2f%%", io_u_lat_u[i]); | |
432 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) | |
433 | log_info(";%3.2f%%", io_u_lat_m[i]); | |
434 | log_info("\n"); | |
2270890c JA |
435 | |
436 | if (ts->description) | |
6d86144d | 437 | log_info(";%s", ts->description); |
2270890c | 438 | |
6d86144d | 439 | log_info("\n"); |
756867bd JA |
440 | } |
441 | ||
197574e4 | 442 | static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr) |
756867bd JA |
443 | { |
444 | double mean, S; | |
445 | ||
446 | dst->min_val = min(dst->min_val, src->min_val); | |
447 | dst->max_val = max(dst->max_val, src->max_val); | |
448 | dst->samples += src->samples; | |
449 | ||
450 | /* | |
451 | * Needs a new method for calculating stddev, we cannot just | |
452 | * average them we do below for nr > 1 | |
453 | */ | |
454 | if (nr == 1) { | |
455 | mean = src->mean; | |
456 | S = src->S; | |
457 | } else { | |
5ec10eaa JA |
458 | mean = ((src->mean * (double) (nr - 1)) |
459 | + dst->mean) / ((double) nr); | |
c39cced6 | 460 | S = ((src->S * (double) (nr - 1)) + dst->S) / ((double) nr); |
756867bd JA |
461 | } |
462 | ||
463 | dst->mean = mean; | |
464 | dst->S = S; | |
465 | } | |
466 | ||
3c39a379 JA |
467 | void show_run_stats(void) |
468 | { | |
469 | struct group_run_stats *runstats, *rs; | |
470 | struct thread_data *td; | |
756867bd | 471 | struct thread_stat *threadstats, *ts; |
197574e4 | 472 | int i, j, k, l, nr_ts, last_ts, idx; |
3c39a379 JA |
473 | |
474 | runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); | |
475 | ||
476 | for (i = 0; i < groupid + 1; i++) { | |
477 | rs = &runstats[i]; | |
478 | ||
479 | memset(rs, 0, sizeof(*rs)); | |
480 | rs->min_bw[0] = rs->min_run[0] = ~0UL; | |
481 | rs->min_bw[1] = rs->min_run[1] = ~0UL; | |
482 | } | |
483 | ||
756867bd JA |
484 | /* |
485 | * find out how many threads stats we need. if group reporting isn't | |
486 | * enabled, it's one-per-td. | |
487 | */ | |
488 | nr_ts = 0; | |
489 | last_ts = -1; | |
490 | for_each_td(td, i) { | |
2dc1bbeb | 491 | if (!td->o.group_reporting) { |
756867bd JA |
492 | nr_ts++; |
493 | continue; | |
494 | } | |
495 | if (last_ts == td->groupid) | |
496 | continue; | |
497 | ||
498 | last_ts = td->groupid; | |
499 | nr_ts++; | |
500 | } | |
501 | ||
502 | threadstats = malloc(nr_ts * sizeof(struct thread_stat)); | |
503 | ||
504 | for (i = 0; i < nr_ts; i++) { | |
505 | ts = &threadstats[i]; | |
506 | ||
507 | memset(ts, 0, sizeof(*ts)); | |
de64df05 | 508 | for (j = 0; j <= DDIR_WRITE; j++) { |
197574e4 JA |
509 | ts->clat_stat[j].min_val = -1UL; |
510 | ts->slat_stat[j].min_val = -1UL; | |
511 | ts->bw_stat[j].min_val = -1UL; | |
512 | } | |
7abd0e3a | 513 | ts->groupid = -1; |
756867bd JA |
514 | } |
515 | ||
516 | j = 0; | |
517 | last_ts = -1; | |
197574e4 | 518 | idx = 0; |
34572e28 | 519 | for_each_td(td, i) { |
2dc1bbeb JA |
520 | if (idx && (!td->o.group_reporting || |
521 | (td->o.group_reporting && last_ts != td->groupid))) { | |
7abd0e3a JA |
522 | idx = 0; |
523 | j++; | |
524 | } | |
525 | ||
526 | last_ts = td->groupid; | |
527 | ||
756867bd JA |
528 | ts = &threadstats[j]; |
529 | ||
197574e4 | 530 | idx++; |
6586ee89 | 531 | ts->members++; |
756867bd | 532 | |
7abd0e3a | 533 | if (ts->groupid == -1) { |
2dc84ba7 JA |
534 | /* |
535 | * These are per-group shared already | |
536 | */ | |
2dc1bbeb JA |
537 | ts->name = td->o.name; |
538 | ts->description = td->o.description; | |
756867bd | 539 | ts->groupid = td->groupid; |
2dc84ba7 JA |
540 | |
541 | /* | |
542 | * first pid in group, not very useful... | |
543 | */ | |
756867bd | 544 | ts->pid = td->pid; |
2dc84ba7 JA |
545 | } |
546 | ||
547 | if (td->error && !ts->error) { | |
548 | ts->error = td->error; | |
756867bd JA |
549 | ts->verror = td->verror; |
550 | } | |
551 | ||
de64df05 | 552 | for (l = 0; l <= DDIR_WRITE; l++) { |
197574e4 JA |
553 | sum_stat(&ts->clat_stat[l], &td->ts.clat_stat[l], idx); |
554 | sum_stat(&ts->slat_stat[l], &td->ts.slat_stat[l], idx); | |
555 | sum_stat(&ts->bw_stat[l], &td->ts.bw_stat[l], idx); | |
756867bd | 556 | |
197574e4 JA |
557 | ts->stat_io_bytes[l] += td->ts.stat_io_bytes[l]; |
558 | ts->io_bytes[l] += td->ts.io_bytes[l]; | |
559 | ||
560 | if (ts->runtime[l] < td->ts.runtime[l]) | |
561 | ts->runtime[l] = td->ts.runtime[l]; | |
562 | } | |
756867bd JA |
563 | |
564 | ts->usr_time += td->ts.usr_time; | |
565 | ts->sys_time += td->ts.sys_time; | |
566 | ts->ctx += td->ts.ctx; | |
e7823a94 JA |
567 | ts->majf += td->ts.majf; |
568 | ts->minf += td->ts.minf; | |
756867bd JA |
569 | |
570 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) | |
571 | ts->io_u_map[k] += td->ts.io_u_map[k]; | |
04a0feae JA |
572 | for (k = 0; k < FIO_IO_U_LAT_U_NR; k++) |
573 | ts->io_u_lat_u[k] += td->ts.io_u_lat_u[k]; | |
574 | for (k = 0; k < FIO_IO_U_LAT_M_NR; k++) | |
575 | ts->io_u_lat_m[k] += td->ts.io_u_lat_m[k]; | |
576 | ||
756867bd | 577 | |
30061b97 | 578 | for (k = 0; k <= DDIR_WRITE; k++) { |
b3605062 | 579 | ts->total_io_u[k] += td->ts.total_io_u[k]; |
30061b97 JA |
580 | ts->short_io_u[k] += td->ts.short_io_u[k]; |
581 | } | |
756867bd JA |
582 | |
583 | ts->total_run_time += td->ts.total_run_time; | |
756867bd JA |
584 | } |
585 | ||
586 | for (i = 0; i < nr_ts; i++) { | |
94370ac4 | 587 | unsigned long long bw; |
3c39a379 | 588 | |
756867bd JA |
589 | ts = &threadstats[i]; |
590 | rs = &runstats[ts->groupid]; | |
3c39a379 | 591 | |
de64df05 | 592 | for (j = 0; j <= DDIR_WRITE; j++) { |
94370ac4 JA |
593 | if (!ts->runtime[j]) |
594 | continue; | |
595 | if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j]) | |
596 | rs->min_run[j] = ts->runtime[j]; | |
597 | if (ts->runtime[j] > rs->max_run[j]) | |
598 | rs->max_run[j] = ts->runtime[j]; | |
599 | ||
600 | bw = 0; | |
601 | if (ts->runtime[j]) | |
5ec10eaa JA |
602 | bw = ts->io_bytes[j] |
603 | / (unsigned long long) ts->runtime[j]; | |
94370ac4 JA |
604 | if (bw < rs->min_bw[j]) |
605 | rs->min_bw[j] = bw; | |
606 | if (bw > rs->max_bw[j]) | |
607 | rs->max_bw[j] = bw; | |
608 | ||
609 | rs->io_kb[j] += ts->io_bytes[j] >> 10; | |
610 | } | |
3c39a379 JA |
611 | } |
612 | ||
613 | for (i = 0; i < groupid + 1; i++) { | |
614 | rs = &runstats[i]; | |
615 | ||
616 | if (rs->max_run[0]) | |
617 | rs->agg[0] = (rs->io_kb[0]*1024) / rs->max_run[0]; | |
618 | if (rs->max_run[1]) | |
619 | rs->agg[1] = (rs->io_kb[1]*1024) / rs->max_run[1]; | |
620 | } | |
621 | ||
622 | /* | |
623 | * don't overwrite last signal output | |
624 | */ | |
c6ae0a5b JA |
625 | if (!terse_output) |
626 | printf("\n"); | |
3c39a379 | 627 | |
756867bd JA |
628 | for (i = 0; i < nr_ts; i++) { |
629 | ts = &threadstats[i]; | |
630 | rs = &runstats[ts->groupid]; | |
3c39a379 | 631 | |
c6ae0a5b | 632 | if (terse_output) |
756867bd | 633 | show_thread_status_terse(ts, rs); |
c6ae0a5b | 634 | else |
756867bd | 635 | show_thread_status(ts, rs); |
3c39a379 JA |
636 | } |
637 | ||
c6ae0a5b JA |
638 | if (!terse_output) { |
639 | for (i = 0; i < groupid + 1; i++) | |
640 | show_group_stats(&runstats[i], i); | |
3c39a379 | 641 | |
c6ae0a5b JA |
642 | show_disk_util(); |
643 | } | |
eecf272f JA |
644 | |
645 | free(runstats); | |
756867bd | 646 | free(threadstats); |
3c39a379 JA |
647 | } |
648 | ||
68704084 | 649 | static inline void add_stat_sample(struct io_stat *is, unsigned long data) |
3c39a379 | 650 | { |
68704084 | 651 | double val = data; |
6660cc67 | 652 | double delta; |
68704084 JA |
653 | |
654 | if (data > is->max_val) | |
655 | is->max_val = data; | |
656 | if (data < is->min_val) | |
657 | is->min_val = data; | |
658 | ||
659 | delta = val - is->mean; | |
ef11d737 JA |
660 | if (delta) { |
661 | is->mean += delta / (is->samples + 1.0); | |
662 | is->S += delta * (val - is->mean); | |
663 | } | |
3c39a379 | 664 | |
3c39a379 JA |
665 | is->samples++; |
666 | } | |
667 | ||
bb3884d8 JA |
668 | static void __add_log_sample(struct io_log *iolog, unsigned long val, |
669 | enum fio_ddir ddir, unsigned long time) | |
3c39a379 JA |
670 | { |
671 | if (iolog->nr_samples == iolog->max_samples) { | |
672 | int new_size = sizeof(struct io_sample) * iolog->max_samples*2; | |
673 | ||
674 | iolog->log = realloc(iolog->log, new_size); | |
675 | iolog->max_samples <<= 1; | |
676 | } | |
677 | ||
678 | iolog->log[iolog->nr_samples].val = val; | |
bb3884d8 | 679 | iolog->log[iolog->nr_samples].time = time; |
3c39a379 JA |
680 | iolog->log[iolog->nr_samples].ddir = ddir; |
681 | iolog->nr_samples++; | |
682 | } | |
683 | ||
bb3884d8 JA |
684 | static void add_log_sample(struct thread_data *td, struct io_log *iolog, |
685 | unsigned long val, enum fio_ddir ddir) | |
686 | { | |
687 | __add_log_sample(iolog, val, ddir, mtime_since_now(&td->epoch)); | |
688 | } | |
689 | ||
690 | void add_agg_sample(unsigned long val, enum fio_ddir ddir) | |
691 | { | |
692 | struct io_log *iolog = agg_io_log[ddir]; | |
693 | ||
694 | __add_log_sample(iolog, val, ddir, mtime_since_genesis()); | |
695 | } | |
696 | ||
1e97cce9 | 697 | void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, |
d85f5118 | 698 | unsigned long usec) |
3c39a379 | 699 | { |
756867bd | 700 | struct thread_stat *ts = &td->ts; |
079ad09b | 701 | |
d85f5118 | 702 | add_stat_sample(&ts->clat_stat[ddir], usec); |
3c39a379 | 703 | |
079ad09b | 704 | if (ts->clat_log) |
d85f5118 | 705 | add_log_sample(td, ts->clat_log, usec, ddir); |
3c39a379 JA |
706 | } |
707 | ||
1e97cce9 | 708 | void add_slat_sample(struct thread_data *td, enum fio_ddir ddir, |
d85f5118 | 709 | unsigned long usec) |
3c39a379 | 710 | { |
756867bd | 711 | struct thread_stat *ts = &td->ts; |
079ad09b | 712 | |
d85f5118 | 713 | add_stat_sample(&ts->slat_stat[ddir], usec); |
3c39a379 | 714 | |
079ad09b | 715 | if (ts->slat_log) |
d85f5118 | 716 | add_log_sample(td, ts->slat_log, usec, ddir); |
3c39a379 JA |
717 | } |
718 | ||
1e97cce9 JA |
719 | void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, |
720 | struct timeval *t) | |
3c39a379 | 721 | { |
756867bd | 722 | struct thread_stat *ts = &td->ts; |
079ad09b | 723 | unsigned long spent = mtime_since(&ts->stat_sample_time[ddir], t); |
3c39a379 JA |
724 | unsigned long rate; |
725 | ||
2dc1bbeb | 726 | if (spent < td->o.bw_avg_time) |
3c39a379 JA |
727 | return; |
728 | ||
079ad09b JA |
729 | rate = (td->this_io_bytes[ddir] - ts->stat_io_bytes[ddir]) / spent; |
730 | add_stat_sample(&ts->bw_stat[ddir], rate); | |
3c39a379 | 731 | |
079ad09b JA |
732 | if (ts->bw_log) |
733 | add_log_sample(td, ts->bw_log, rate, ddir); | |
3c39a379 | 734 | |
079ad09b JA |
735 | fio_gettime(&ts->stat_sample_time[ddir], NULL); |
736 | ts->stat_io_bytes[ddir] = td->this_io_bytes[ddir]; | |
3c39a379 | 737 | } |