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