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