Commit | Line | Data |
---|---|---|
263e529f JA |
1 | /* |
2 | * Status and ETA code | |
3 | */ | |
4 | #include <unistd.h> | |
5 | #include <fcntl.h> | |
6 | #include <string.h> | |
4f37732a BVA |
7 | #ifdef CONFIG_VALGRIND_DEV |
8 | #include <valgrind/drd.h> | |
9 | #else | |
10 | #define DRD_IGNORE_VAR(x) do { } while (0) | |
11 | #endif | |
263e529f JA |
12 | |
13 | #include "fio.h" | |
0f38bbef | 14 | #include "lib/pow2.h" |
263e529f | 15 | |
3e2e48a7 | 16 | static char __run_str[REAL_MAX_JOBS + 1]; |
318b9457 | 17 | static char run_str[__THREAD_RUNSTR_SZ(REAL_MAX_JOBS) + 1]; |
3e2e48a7 | 18 | |
8a1db9a1 | 19 | static void update_condensed_str(char *rstr, char *run_str_condensed) |
3e2e48a7 | 20 | { |
8a1db9a1 JA |
21 | if (*rstr) { |
22 | while (*rstr) { | |
595d9e77 AG |
23 | int nr = 1; |
24 | ||
8a1db9a1 JA |
25 | *run_str_condensed++ = *rstr++; |
26 | while (*(rstr - 1) == *rstr) { | |
27 | rstr++; | |
595d9e77 AG |
28 | nr++; |
29 | } | |
30 | run_str_condensed += sprintf(run_str_condensed, "(%u),", nr); | |
3e2e48a7 | 31 | } |
595d9e77 | 32 | run_str_condensed--; |
3e2e48a7 | 33 | } |
595d9e77 | 34 | *run_str_condensed = '\0'; |
6c784104 | 35 | } |
263e529f JA |
36 | |
37 | /* | |
38 | * Sets the status of the 'td' in the printed status map. | |
39 | */ | |
40 | static void check_str_update(struct thread_data *td) | |
41 | { | |
3e2e48a7 | 42 | char c = __run_str[td->thread_number - 1]; |
263e529f JA |
43 | |
44 | switch (td->runstate) { | |
5ec10eaa | 45 | case TD_REAPED: |
4f7e57a4 JA |
46 | if (td->error) |
47 | c = 'X'; | |
a5e371a6 JA |
48 | else if (td->sig) |
49 | c = 'K'; | |
4f7e57a4 JA |
50 | else |
51 | c = '_'; | |
5ec10eaa JA |
52 | break; |
53 | case TD_EXITED: | |
54 | c = 'E'; | |
55 | break; | |
b29ee5b3 JA |
56 | case TD_RAMP: |
57 | c = '/'; | |
58 | break; | |
5ec10eaa JA |
59 | case TD_RUNNING: |
60 | if (td_rw(td)) { | |
e3b3f81e JA |
61 | if (td_random(td)) { |
62 | if (td->o.rwmix[DDIR_READ] == 100) | |
63 | c = 'r'; | |
64 | else if (td->o.rwmix[DDIR_WRITE] == 100) | |
65 | c = 'w'; | |
66 | else | |
67 | c = 'm'; | |
68 | } else { | |
69 | if (td->o.rwmix[DDIR_READ] == 100) | |
70 | c = 'R'; | |
71 | else if (td->o.rwmix[DDIR_WRITE] == 100) | |
72 | c = 'W'; | |
73 | else | |
74 | c = 'M'; | |
75 | } | |
5ec10eaa JA |
76 | } else if (td_read(td)) { |
77 | if (td_random(td)) | |
78 | c = 'r'; | |
79 | else | |
80 | c = 'R'; | |
6eaf09d6 | 81 | } else if (td_write(td)) { |
5ec10eaa JA |
82 | if (td_random(td)) |
83 | c = 'w'; | |
84 | else | |
85 | c = 'W'; | |
6eaf09d6 SL |
86 | } else { |
87 | if (td_random(td)) | |
88 | c = 'd'; | |
89 | else | |
90 | c = 'D'; | |
5ec10eaa JA |
91 | } |
92 | break; | |
b0f65863 JA |
93 | case TD_PRE_READING: |
94 | c = 'p'; | |
95 | break; | |
5ec10eaa JA |
96 | case TD_VERIFYING: |
97 | c = 'V'; | |
98 | break; | |
99 | case TD_FSYNCING: | |
100 | c = 'F'; | |
101 | break; | |
3d434057 JA |
102 | case TD_FINISHING: |
103 | c = 'f'; | |
104 | break; | |
5ec10eaa JA |
105 | case TD_CREATED: |
106 | c = 'C'; | |
107 | break; | |
108 | case TD_INITIALIZED: | |
9c6f6316 | 109 | case TD_SETTING_UP: |
5ec10eaa JA |
110 | c = 'I'; |
111 | break; | |
112 | case TD_NOT_CREATED: | |
113 | c = 'P'; | |
114 | break; | |
115 | default: | |
116 | log_err("state %d\n", td->runstate); | |
263e529f JA |
117 | } |
118 | ||
3e2e48a7 JA |
119 | __run_str[td->thread_number - 1] = c; |
120 | update_condensed_str(__run_str, run_str); | |
263e529f JA |
121 | } |
122 | ||
123 | /* | |
124 | * Convert seconds to a printable string. | |
125 | */ | |
3e47bd25 | 126 | void eta_to_str(char *str, unsigned long eta_sec) |
263e529f JA |
127 | { |
128 | unsigned int d, h, m, s; | |
165faf16 | 129 | int disp_hour = 0; |
263e529f | 130 | |
263775ad LG |
131 | if (eta_sec == -1) { |
132 | sprintf(str, "--"); | |
133 | return; | |
134 | } | |
135 | ||
263e529f JA |
136 | s = eta_sec % 60; |
137 | eta_sec /= 60; | |
138 | m = eta_sec % 60; | |
139 | eta_sec /= 60; | |
140 | h = eta_sec % 24; | |
141 | eta_sec /= 24; | |
142 | d = eta_sec; | |
143 | ||
165faf16 JA |
144 | if (d) { |
145 | disp_hour = 1; | |
1e97cce9 | 146 | str += sprintf(str, "%02ud:", d); |
263e529f | 147 | } |
165faf16 JA |
148 | |
149 | if (h || disp_hour) | |
1e97cce9 | 150 | str += sprintf(str, "%02uh:", h); |
263e529f | 151 | |
1e97cce9 JA |
152 | str += sprintf(str, "%02um:", m); |
153 | str += sprintf(str, "%02us", s); | |
263e529f JA |
154 | } |
155 | ||
156 | /* | |
157 | * Best effort calculation of the estimated pending runtime of a job. | |
158 | */ | |
263775ad | 159 | static unsigned long thread_eta(struct thread_data *td) |
263e529f JA |
160 | { |
161 | unsigned long long bytes_total, bytes_done; | |
1e97cce9 | 162 | unsigned long eta_sec = 0; |
b29ee5b3 | 163 | unsigned long elapsed; |
0de5b26f | 164 | uint64_t timeout; |
b29ee5b3 JA |
165 | |
166 | elapsed = (mtime_since_now(&td->epoch) + 999) / 1000; | |
0de5b26f | 167 | timeout = td->o.timeout / 1000000UL; |
263e529f JA |
168 | |
169 | bytes_total = td->total_io_size; | |
170 | ||
263775ad LG |
171 | if (td->flags & TD_F_NO_PROGRESS) |
172 | return -1; | |
173 | ||
2e3bd4c2 JA |
174 | if (td->o.fill_device && td->o.size == -1ULL) { |
175 | if (!td->fill_device_size || td->fill_device_size == -1ULL) | |
176 | return 0; | |
177 | ||
178 | bytes_total = td->fill_device_size; | |
179 | } | |
180 | ||
0d73a2f9 JA |
181 | if (td->o.zone_size && td->o.zone_skip && bytes_total) { |
182 | unsigned int nr_zones; | |
183 | uint64_t zone_bytes; | |
184 | ||
185 | zone_bytes = bytes_total + td->o.zone_size + td->o.zone_skip; | |
186 | nr_zones = (zone_bytes - 1) / (td->o.zone_size + td->o.zone_skip); | |
187 | bytes_total -= nr_zones * td->o.zone_skip; | |
188 | } | |
189 | ||
74939e38 | 190 | /* |
165eb050 JA |
191 | * if writing and verifying afterwards, bytes_total will be twice the |
192 | * size. In a mixed workload, verify phase will be the size of the | |
193 | * first stage writes. | |
74939e38 | 194 | */ |
0dd8377f | 195 | if (td->o.do_verify && td->o.verify && td_write(td)) { |
165eb050 JA |
196 | if (td_rw(td)) { |
197 | unsigned int perc = 50; | |
198 | ||
199 | if (td->o.rwmix[DDIR_WRITE]) | |
200 | perc = td->o.rwmix[DDIR_WRITE]; | |
201 | ||
202 | bytes_total += (bytes_total * perc) / 100; | |
203 | } else | |
74939e38 JA |
204 | bytes_total <<= 1; |
205 | } | |
206 | ||
263e529f | 207 | if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) { |
cf4464ca | 208 | double perc, perc_t; |
263e529f | 209 | |
342f4be4 | 210 | bytes_done = ddir_rw_sum(td->io_bytes); |
476882d7 JA |
211 | |
212 | if (bytes_total) { | |
213 | perc = (double) bytes_done / (double) bytes_total; | |
214 | if (perc > 1.0) | |
215 | perc = 1.0; | |
216 | } else | |
217 | perc = 0.0; | |
263e529f | 218 | |
cf4464ca | 219 | if (td->o.time_based) { |
476882d7 JA |
220 | if (timeout) { |
221 | perc_t = (double) elapsed / (double) timeout; | |
ada6fcee | 222 | if (perc_t < perc) |
476882d7 JA |
223 | perc = perc_t; |
224 | } else { | |
225 | /* | |
226 | * Will never hit, we can't have time_based | |
227 | * without a timeout set. | |
228 | */ | |
229 | perc = 0.0; | |
230 | } | |
cf4464ca JA |
231 | } |
232 | ||
ae5eaf07 SW |
233 | if (perc == 0.0) { |
234 | eta_sec = timeout; | |
235 | } else { | |
236 | eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed; | |
237 | } | |
263e529f | 238 | |
d3eeeabc | 239 | if (td->o.timeout && |
0de5b26f JA |
240 | eta_sec > (timeout + done_secs - elapsed)) |
241 | eta_sec = timeout + done_secs - elapsed; | |
263e529f | 242 | } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED |
b29ee5b3 | 243 | || td->runstate == TD_INITIALIZED |
714e85f3 | 244 | || td->runstate == TD_SETTING_UP |
b0f65863 JA |
245 | || td->runstate == TD_RAMP |
246 | || td->runstate == TD_PRE_READING) { | |
90eff1c9 | 247 | int64_t t_eta = 0, r_eta = 0; |
342f4be4 | 248 | unsigned long long rate_bytes; |
263e529f JA |
249 | |
250 | /* | |
251 | * We can only guess - assume it'll run the full timeout | |
252 | * if given, otherwise assume it'll run at the specified rate. | |
253 | */ | |
b29ee5b3 | 254 | if (td->o.timeout) { |
8a1db9a1 | 255 | uint64_t __timeout = td->o.timeout; |
0de5b26f JA |
256 | uint64_t start_delay = td->o.start_delay; |
257 | uint64_t ramp_time = td->o.ramp_time; | |
258 | ||
ae5eaf07 SW |
259 | t_eta = __timeout + start_delay; |
260 | if (!td->ramp_time_over) { | |
261 | t_eta += ramp_time; | |
262 | } | |
0de5b26f | 263 | t_eta /= 1000000ULL; |
b29ee5b3 | 264 | |
3379b94e | 265 | if ((td->runstate == TD_RAMP) && in_ramp_time(td)) { |
b29ee5b3 JA |
266 | unsigned long ramp_left; |
267 | ||
cda99fa0 | 268 | ramp_left = mtime_since_now(&td->epoch); |
b29ee5b3 JA |
269 | ramp_left = (ramp_left + 999) / 1000; |
270 | if (ramp_left <= t_eta) | |
271 | t_eta -= ramp_left; | |
272 | } | |
273 | } | |
819a4a96 SW |
274 | rate_bytes = 0; |
275 | if (td_read(td)) | |
276 | rate_bytes = td->o.rate[DDIR_READ]; | |
277 | if (td_write(td)) | |
278 | rate_bytes += td->o.rate[DDIR_WRITE]; | |
279 | if (td_trim(td)) | |
280 | rate_bytes += td->o.rate[DDIR_TRIM]; | |
281 | ||
342f4be4 | 282 | if (rate_bytes) { |
819a4a96 | 283 | r_eta = bytes_total / rate_bytes; |
0de5b26f | 284 | r_eta += (td->o.start_delay / 1000000ULL); |
263e529f JA |
285 | } |
286 | ||
287 | if (r_eta && t_eta) | |
288 | eta_sec = min(r_eta, t_eta); | |
289 | else if (r_eta) | |
290 | eta_sec = r_eta; | |
291 | else if (t_eta) | |
292 | eta_sec = t_eta; | |
293 | else | |
294 | eta_sec = 0; | |
295 | } else { | |
296 | /* | |
297 | * thread is already done or waiting for fsync | |
298 | */ | |
299 | eta_sec = 0; | |
300 | } | |
301 | ||
302 | return eta_sec; | |
303 | } | |
304 | ||
771e58be JA |
305 | static void calc_rate(int unified_rw_rep, unsigned long mtime, |
306 | unsigned long long *io_bytes, | |
90eff1c9 | 307 | unsigned long long *prev_io_bytes, uint64_t *rate) |
46fda8d0 | 308 | { |
b7f05eb0 JA |
309 | int i; |
310 | ||
6eaf09d6 | 311 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
1e271b21 | 312 | unsigned long long diff, this_rate; |
b7f05eb0 JA |
313 | |
314 | diff = io_bytes[i] - prev_io_bytes[i]; | |
1e271b21 | 315 | if (mtime) |
420b104a | 316 | this_rate = ((1000 * diff) / mtime) / 1024; /* KiB/s */ |
1e271b21 JA |
317 | else |
318 | this_rate = 0; | |
319 | ||
771e58be JA |
320 | if (unified_rw_rep) { |
321 | rate[i] = 0; | |
1e271b21 | 322 | rate[0] += this_rate; |
771e58be | 323 | } else |
1e271b21 | 324 | rate[i] = this_rate; |
6eaf09d6 SL |
325 | |
326 | prev_io_bytes[i] = io_bytes[i]; | |
b7f05eb0 | 327 | } |
46fda8d0 | 328 | } |
5ec10eaa | 329 | |
771e58be JA |
330 | static void calc_iops(int unified_rw_rep, unsigned long mtime, |
331 | unsigned long long *io_iops, | |
adb02ba8 JA |
332 | unsigned long long *prev_io_iops, unsigned int *iops) |
333 | { | |
6eaf09d6 SL |
334 | int i; |
335 | ||
336 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { | |
95c2f38e | 337 | unsigned long long diff, this_iops; |
771e58be JA |
338 | |
339 | diff = io_iops[i] - prev_io_iops[i]; | |
95c2f38e JA |
340 | if (mtime) |
341 | this_iops = (diff * 1000) / mtime; | |
342 | else | |
343 | this_iops = 0; | |
344 | ||
771e58be JA |
345 | if (unified_rw_rep) { |
346 | iops[i] = 0; | |
95c2f38e | 347 | iops[0] += this_iops; |
771e58be | 348 | } else |
95c2f38e | 349 | iops[i] = this_iops; |
771e58be | 350 | |
6eaf09d6 SL |
351 | prev_io_iops[i] = io_iops[i]; |
352 | } | |
adb02ba8 JA |
353 | } |
354 | ||
db37d890 JA |
355 | /* |
356 | * Allow a little slack - if we're within 95% of the time, allow ETA. | |
357 | */ | |
358 | bool eta_time_within_slack(unsigned int time) | |
359 | { | |
360 | return time > ((eta_interval_msec * 95) / 100); | |
361 | } | |
362 | ||
263e529f JA |
363 | /* |
364 | * Print status of the jobs we know about. This includes rate estimates, | |
365 | * ETA, thread state, etc. | |
366 | */ | |
8aa89d70 | 367 | bool calc_thread_status(struct jobs_eta *je, int force) |
263e529f | 368 | { |
34572e28 | 369 | struct thread_data *td; |
771e58be | 370 | int i, unified_rw_rep; |
90eff1c9 | 371 | uint64_t rate_time, disp_time, bw_avg_time, *eta_secs; |
6eaf09d6 SL |
372 | unsigned long long io_bytes[DDIR_RWDIR_CNT]; |
373 | unsigned long long io_iops[DDIR_RWDIR_CNT]; | |
8b6a404c | 374 | struct timespec now; |
46fda8d0 | 375 | |
6eaf09d6 SL |
376 | static unsigned long long rate_io_bytes[DDIR_RWDIR_CNT]; |
377 | static unsigned long long disp_io_bytes[DDIR_RWDIR_CNT]; | |
378 | static unsigned long long disp_io_iops[DDIR_RWDIR_CNT]; | |
8b6a404c | 379 | static struct timespec rate_prev_time, disp_prev_time; |
6043c579 | 380 | |
af9c9fb3 | 381 | if (!force) { |
129fb2d4 | 382 | if (!(output_format & FIO_OUTPUT_NORMAL) && |
fc47559b | 383 | f_out == stdout) |
8aa89d70 | 384 | return false; |
f3afa57e | 385 | if (temp_stall_ts || eta_print == FIO_ETA_NEVER) |
8aa89d70 | 386 | return false; |
e592a06b | 387 | |
af9c9fb3 | 388 | if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS)) |
8aa89d70 | 389 | return false; |
af9c9fb3 | 390 | } |
263e529f | 391 | |
342f4be4 | 392 | if (!ddir_rw_sum(rate_io_bytes)) |
46fda8d0 | 393 | fill_start_time(&rate_prev_time); |
342f4be4 | 394 | if (!ddir_rw_sum(disp_io_bytes)) |
46fda8d0 | 395 | fill_start_time(&disp_prev_time); |
6043c579 | 396 | |
90eff1c9 SW |
397 | eta_secs = malloc(thread_number * sizeof(uint64_t)); |
398 | memset(eta_secs, 0, thread_number * sizeof(uint64_t)); | |
263e529f | 399 | |
b75a394f JA |
400 | je->elapsed_sec = (mtime_since_genesis() + 999) / 1000; |
401 | ||
6eaf09d6 SL |
402 | io_bytes[DDIR_READ] = io_bytes[DDIR_WRITE] = io_bytes[DDIR_TRIM] = 0; |
403 | io_iops[DDIR_READ] = io_iops[DDIR_WRITE] = io_iops[DDIR_TRIM] = 0; | |
bb3884d8 | 404 | bw_avg_time = ULONG_MAX; |
771e58be | 405 | unified_rw_rep = 0; |
34572e28 | 406 | for_each_td(td, i) { |
771e58be | 407 | unified_rw_rep += td->o.unified_rw_rep; |
b7f05eb0 JA |
408 | if (is_power_of_2(td->o.kb_base)) |
409 | je->is_pow2 = 1; | |
ad705bcb | 410 | je->unit_base = td->o.unit_base; |
2dc1bbeb JA |
411 | if (td->o.bw_avg_time < bw_avg_time) |
412 | bw_avg_time = td->o.bw_avg_time; | |
46fda8d0 | 413 | if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING |
b0f65863 | 414 | || td->runstate == TD_FSYNCING |
3d434057 JA |
415 | || td->runstate == TD_PRE_READING |
416 | || td->runstate == TD_FINISHING) { | |
b75a394f | 417 | je->nr_running++; |
242c38db | 418 | if (td_read(td)) { |
c2e9cc4d JA |
419 | je->t_rate[0] += td->o.rate[DDIR_READ]; |
420 | je->t_iops[0] += td->o.rate_iops[DDIR_READ]; | |
421 | je->m_rate[0] += td->o.ratemin[DDIR_READ]; | |
422 | je->m_iops[0] += td->o.rate_iops_min[DDIR_READ]; | |
242c38db JA |
423 | } |
424 | if (td_write(td)) { | |
c2e9cc4d JA |
425 | je->t_rate[1] += td->o.rate[DDIR_WRITE]; |
426 | je->t_iops[1] += td->o.rate_iops[DDIR_WRITE]; | |
427 | je->m_rate[1] += td->o.ratemin[DDIR_WRITE]; | |
428 | je->m_iops[1] += td->o.rate_iops_min[DDIR_WRITE]; | |
242c38db | 429 | } |
6eaf09d6 | 430 | if (td_trim(td)) { |
d79db122 JA |
431 | je->t_rate[2] += td->o.rate[DDIR_TRIM]; |
432 | je->t_iops[2] += td->o.rate_iops[DDIR_TRIM]; | |
433 | je->m_rate[2] += td->o.ratemin[DDIR_TRIM]; | |
434 | je->m_iops[2] += td->o.rate_iops_min[DDIR_TRIM]; | |
6eaf09d6 SL |
435 | } |
436 | ||
b75a394f | 437 | je->files_open += td->nr_open_files; |
b29ee5b3 | 438 | } else if (td->runstate == TD_RAMP) { |
b75a394f JA |
439 | je->nr_running++; |
440 | je->nr_ramp++; | |
aef66dec | 441 | } else if (td->runstate == TD_SETTING_UP) |
714e85f3 | 442 | je->nr_setting_up++; |
aef66dec | 443 | else if (td->runstate < TD_RUNNING) |
b75a394f | 444 | je->nr_pending++; |
263e529f | 445 | |
b75a394f | 446 | if (je->elapsed_sec >= 3) |
b29ee5b3 | 447 | eta_secs[i] = thread_eta(td); |
263e529f JA |
448 | else |
449 | eta_secs[i] = INT_MAX; | |
450 | ||
451 | check_str_update(td); | |
b29ee5b3 | 452 | |
714e85f3 | 453 | if (td->runstate > TD_SETTING_UP) { |
6eaf09d6 | 454 | int ddir; |
771e58be | 455 | |
c1f50f76 | 456 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
771e58be JA |
457 | if (unified_rw_rep) { |
458 | io_bytes[0] += td->io_bytes[ddir]; | |
459 | io_iops[0] += td->io_blocks[ddir]; | |
460 | } else { | |
461 | io_bytes[ddir] += td->io_bytes[ddir]; | |
462 | io_iops[ddir] += td->io_blocks[ddir]; | |
463 | } | |
6eaf09d6 | 464 | } |
b29ee5b3 | 465 | } |
263e529f JA |
466 | } |
467 | ||
3379b94e | 468 | if (exitall_on_terminate) { |
b75a394f | 469 | je->eta_sec = INT_MAX; |
3379b94e | 470 | for_each_td(td, i) { |
b75a394f JA |
471 | if (eta_secs[i] < je->eta_sec) |
472 | je->eta_sec = eta_secs[i]; | |
9c5a3854 | 473 | } |
3379b94e JR |
474 | } else { |
475 | unsigned long eta_stone = 0; | |
476 | ||
477 | je->eta_sec = 0; | |
478 | for_each_td(td, i) { | |
479 | if ((td->runstate == TD_NOT_CREATED) && td->o.stonewall) | |
480 | eta_stone += eta_secs[i]; | |
481 | else { | |
482 | if (eta_secs[i] > je->eta_sec) | |
483 | je->eta_sec = eta_secs[i]; | |
484 | } | |
485 | } | |
486 | je->eta_sec += eta_stone; | |
263e529f JA |
487 | } |
488 | ||
eecf272f JA |
489 | free(eta_secs); |
490 | ||
46fda8d0 JA |
491 | fio_gettime(&now, NULL); |
492 | rate_time = mtime_since(&rate_prev_time, &now); | |
493 | ||
b29ee5b3 | 494 | if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) { |
771e58be JA |
495 | calc_rate(unified_rw_rep, rate_time, io_bytes, rate_io_bytes, |
496 | je->rate); | |
46fda8d0 | 497 | memcpy(&rate_prev_time, &now, sizeof(now)); |
af2fde19 SW |
498 | add_agg_sample(sample_val(je->rate[DDIR_READ]), DDIR_READ, 0); |
499 | add_agg_sample(sample_val(je->rate[DDIR_WRITE]), DDIR_WRITE, 0); | |
500 | add_agg_sample(sample_val(je->rate[DDIR_TRIM]), DDIR_TRIM, 0); | |
6043c579 JA |
501 | } |
502 | ||
46fda8d0 | 503 | disp_time = mtime_since(&disp_prev_time, &now); |
a5b01f1b | 504 | |
db37d890 | 505 | if (!force && !eta_time_within_slack(disp_time)) |
8aa89d70 | 506 | return false; |
46fda8d0 | 507 | |
771e58be JA |
508 | calc_rate(unified_rw_rep, disp_time, io_bytes, disp_io_bytes, je->rate); |
509 | calc_iops(unified_rw_rep, disp_time, io_iops, disp_io_iops, je->iops); | |
adb02ba8 | 510 | |
46fda8d0 JA |
511 | memcpy(&disp_prev_time, &now, sizeof(now)); |
512 | ||
af9c9fb3 | 513 | if (!force && !je->nr_running && !je->nr_pending) |
8aa89d70 | 514 | return false; |
b75a394f | 515 | |
1d1f45ae | 516 | je->nr_threads = thread_number; |
6c784104 JA |
517 | update_condensed_str(__run_str, run_str); |
518 | memcpy(je->run_str, run_str, strlen(run_str)); | |
8aa89d70 | 519 | return true; |
b75a394f JA |
520 | } |
521 | ||
cf451d1e | 522 | void display_thread_status(struct jobs_eta *je) |
b75a394f | 523 | { |
8b6a404c | 524 | static struct timespec disp_eta_new_line; |
e382e661 | 525 | static int eta_new_line_init, eta_new_line_pending; |
b75a394f JA |
526 | static int linelen_last; |
527 | static int eta_good; | |
2b34ccad | 528 | char output[__THREAD_RUNSTR_SZ(REAL_MAX_JOBS) + 512], *p = output; |
b75a394f JA |
529 | char eta_str[128]; |
530 | double perc = 0.0; | |
b75a394f | 531 | |
cf451d1e JA |
532 | if (je->eta_sec != INT_MAX && je->elapsed_sec) { |
533 | perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec); | |
534 | eta_to_str(eta_str, je->eta_sec); | |
b75a394f JA |
535 | } |
536 | ||
e382e661 JA |
537 | if (eta_new_line_pending) { |
538 | eta_new_line_pending = 0; | |
ab1ace62 | 539 | linelen_last = 0; |
e382e661 JA |
540 | p += sprintf(p, "\n"); |
541 | } | |
542 | ||
cf451d1e | 543 | p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open); |
d694a6a7 RE |
544 | |
545 | /* rate limits, if any */ | |
546 | if (je->m_rate[0] || je->m_rate[1] || je->m_rate[2] || | |
547 | je->t_rate[0] || je->t_rate[1] || je->t_rate[2]) { | |
581e7141 JA |
548 | char *tr, *mr; |
549 | ||
d694a6a7 | 550 | mr = num2str(je->m_rate[0] + je->m_rate[1] + je->m_rate[2], |
e883cb35 | 551 | je->sig_figs, 0, je->is_pow2, N2S_BYTEPERSEC); |
d694a6a7 | 552 | tr = num2str(je->t_rate[0] + je->t_rate[1] + je->t_rate[2], |
e883cb35 | 553 | je->sig_figs, 0, je->is_pow2, N2S_BYTEPERSEC); |
d694a6a7 RE |
554 | |
555 | p += sprintf(p, ", %s-%s", mr, tr); | |
581e7141 JA |
556 | free(tr); |
557 | free(mr); | |
d694a6a7 RE |
558 | } else if (je->m_iops[0] || je->m_iops[1] || je->m_iops[2] || |
559 | je->t_iops[0] || je->t_iops[1] || je->t_iops[2]) { | |
560 | p += sprintf(p, ", %d-%d IOPS", | |
561 | je->m_iops[0] + je->m_iops[1] + je->m_iops[2], | |
562 | je->t_iops[0] + je->t_iops[1] + je->t_iops[2]); | |
3e47bd25 | 563 | } |
d694a6a7 RE |
564 | |
565 | /* current run string, % done, bandwidth, iops, eta */ | |
cf451d1e | 566 | if (je->eta_sec != INT_MAX && je->nr_running) { |
0721d11e | 567 | char perc_str[32]; |
6eaf09d6 SL |
568 | char *iops_str[DDIR_RWDIR_CNT]; |
569 | char *rate_str[DDIR_RWDIR_CNT]; | |
79074e7c | 570 | size_t left; |
adb02ba8 | 571 | int l; |
6eaf09d6 | 572 | int ddir; |
45d41a8b | 573 | int linelen; |
5ec10eaa | 574 | |
263775ad LG |
575 | if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running || |
576 | je->eta_sec == -1) | |
d694a6a7 | 577 | strcpy(perc_str, "-.-%"); |
cac58fd5 | 578 | else { |
714e85f3 JA |
579 | double mult = 100.0; |
580 | ||
581 | if (je->nr_setting_up && je->nr_running) | |
582 | mult *= (1.0 - (double) je->nr_setting_up / (double) je->nr_running); | |
583 | ||
cac58fd5 | 584 | eta_good = 1; |
714e85f3 | 585 | perc *= mult; |
d694a6a7 | 586 | sprintf(perc_str, "%3.1f%%", perc); |
cac58fd5 | 587 | } |
0721d11e | 588 | |
c1f50f76 | 589 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
d694a6a7 | 590 | rate_str[ddir] = num2str(je->rate[ddir], 4, |
ad705bcb | 591 | 1024, je->is_pow2, je->unit_base); |
d694a6a7 | 592 | iops_str[ddir] = num2str(je->iops[ddir], 4, 1, 0, N2S_NONE); |
6eaf09d6 | 593 | } |
adb02ba8 | 594 | |
38aef42d | 595 | left = sizeof(output) - (p - output) - 1; |
79074e7c | 596 | |
d694a6a7 RE |
597 | if (je->rate[DDIR_TRIM] || je->iops[DDIR_TRIM]) |
598 | l = snprintf(p, left, | |
599 | ": [%s][%s][r=%s,w=%s,t=%s][r=%s,w=%s,t=%s IOPS][eta %s]", | |
6eaf09d6 SL |
600 | je->run_str, perc_str, rate_str[DDIR_READ], |
601 | rate_str[DDIR_WRITE], rate_str[DDIR_TRIM], | |
602 | iops_str[DDIR_READ], iops_str[DDIR_WRITE], | |
603 | iops_str[DDIR_TRIM], eta_str); | |
d694a6a7 RE |
604 | else |
605 | l = snprintf(p, left, | |
606 | ": [%s][%s][r=%s,w=%s][r=%s,w=%s IOPS][eta %s]", | |
607 | je->run_str, perc_str, | |
608 | rate_str[DDIR_READ], rate_str[DDIR_WRITE], | |
609 | iops_str[DDIR_READ], iops_str[DDIR_WRITE], | |
610 | eta_str); | |
38aef42d SW |
611 | /* If truncation occurred adjust l so p is on the null */ |
612 | if (l >= left) | |
613 | l = left - 1; | |
37db14fe | 614 | p += l; |
45d41a8b SW |
615 | linelen = p - output; |
616 | if (l >= 0 && linelen < linelen_last) | |
617 | p += sprintf(p, "%*s", linelen_last - linelen, ""); | |
618 | linelen_last = linelen; | |
d1bd7213 | 619 | |
c1f50f76 | 620 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
6eaf09d6 SL |
621 | free(rate_str[ddir]); |
622 | free(iops_str[ddir]); | |
623 | } | |
263e529f | 624 | } |
37db14fe JA |
625 | p += sprintf(p, "\r"); |
626 | ||
3e47bd25 | 627 | printf("%s", output); |
e382e661 JA |
628 | |
629 | if (!eta_new_line_init) { | |
630 | fio_gettime(&disp_eta_new_line, NULL); | |
631 | eta_new_line_init = 1; | |
88038bc7 | 632 | } else if (eta_new_line && mtime_since_now(&disp_eta_new_line) > eta_new_line) { |
e382e661 JA |
633 | fio_gettime(&disp_eta_new_line, NULL); |
634 | eta_new_line_pending = 1; | |
635 | } | |
636 | ||
3e47bd25 | 637 | fflush(stdout); |
263e529f JA |
638 | } |
639 | ||
c5103619 | 640 | struct jobs_eta *get_jobs_eta(bool force, size_t *size) |
cf451d1e | 641 | { |
1d1f45ae JA |
642 | struct jobs_eta *je; |
643 | ||
b814fb26 | 644 | if (!thread_number) |
723297c9 | 645 | return NULL; |
cf451d1e | 646 | |
e98e0eb5 | 647 | *size = sizeof(*je) + THREAD_RUNSTR_SZ + 8; |
723297c9 | 648 | je = malloc(*size); |
70034d87 RE |
649 | if (!je) |
650 | return NULL; | |
723297c9 JA |
651 | memset(je, 0, *size); |
652 | ||
256bc54c | 653 | if (!calc_thread_status(je, force)) { |
723297c9 JA |
654 | free(je); |
655 | return NULL; | |
656 | } | |
657 | ||
05bff935 | 658 | *size = sizeof(*je) + strlen((char *) je->run_str) + 1; |
723297c9 JA |
659 | return je; |
660 | } | |
661 | ||
662 | void print_thread_status(void) | |
663 | { | |
664 | struct jobs_eta *je; | |
665 | size_t size; | |
cf451d1e | 666 | |
c5103619 | 667 | je = get_jobs_eta(false, &size); |
723297c9 | 668 | if (je) |
1d1f45ae | 669 | display_thread_status(je); |
cf451d1e | 670 | |
1d1f45ae | 671 | free(je); |
cf451d1e | 672 | } |
b75a394f | 673 | |
2b13e716 | 674 | void print_status_init(int thr_number) |
263e529f | 675 | { |
4f37732a | 676 | DRD_IGNORE_VAR(__run_str); |
3e2e48a7 JA |
677 | __run_str[thr_number] = 'P'; |
678 | update_condensed_str(__run_str, run_str); | |
263e529f | 679 | } |