Commit | Line | Data |
---|---|---|
263e529f JA |
1 | /* |
2 | * Status and ETA code | |
3 | */ | |
4 | #include <unistd.h> | |
263e529f | 5 | #include <string.h> |
0fc3cb4c | 6 | #include <stdlib.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 | 152 | str += sprintf(str, "%02um:", m); |
1612c4a5 | 153 | 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 | ||
c3795cb0 DLM |
181 | /* |
182 | * If io_size is set, bytes_total is an exact value that does not need | |
183 | * adjustment. | |
184 | */ | |
185 | if (td->o.zone_size && td->o.zone_skip && bytes_total && | |
186 | !fio_option_is_set(&td->o, io_size)) { | |
0d73a2f9 JA |
187 | unsigned int nr_zones; |
188 | uint64_t zone_bytes; | |
189 | ||
c3795cb0 DLM |
190 | /* |
191 | * Calculate the upper bound of the number of zones that will | |
192 | * be processed, including skipped bytes between zones. If this | |
193 | * is larger than total_io_size (e.g. when --io_size or --size | |
194 | * specify a small value), use the lower bound to avoid | |
195 | * adjustments to a negative value that would result in a very | |
196 | * large bytes_total and an incorrect eta. | |
197 | */ | |
198 | zone_bytes = td->o.zone_size + td->o.zone_skip; | |
199 | nr_zones = (bytes_total + zone_bytes - 1) / zone_bytes; | |
200 | if (bytes_total < nr_zones * td->o.zone_skip) | |
201 | nr_zones = bytes_total / zone_bytes; | |
0d73a2f9 JA |
202 | bytes_total -= nr_zones * td->o.zone_skip; |
203 | } | |
204 | ||
74939e38 | 205 | /* |
165eb050 JA |
206 | * if writing and verifying afterwards, bytes_total will be twice the |
207 | * size. In a mixed workload, verify phase will be the size of the | |
208 | * first stage writes. | |
74939e38 | 209 | */ |
0dd8377f | 210 | if (td->o.do_verify && td->o.verify && td_write(td)) { |
165eb050 JA |
211 | if (td_rw(td)) { |
212 | unsigned int perc = 50; | |
213 | ||
214 | if (td->o.rwmix[DDIR_WRITE]) | |
215 | perc = td->o.rwmix[DDIR_WRITE]; | |
216 | ||
217 | bytes_total += (bytes_total * perc) / 100; | |
218 | } else | |
74939e38 JA |
219 | bytes_total <<= 1; |
220 | } | |
221 | ||
263e529f | 222 | if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) { |
cf4464ca | 223 | double perc, perc_t; |
263e529f | 224 | |
342f4be4 | 225 | bytes_done = ddir_rw_sum(td->io_bytes); |
476882d7 JA |
226 | |
227 | if (bytes_total) { | |
228 | perc = (double) bytes_done / (double) bytes_total; | |
229 | if (perc > 1.0) | |
230 | perc = 1.0; | |
231 | } else | |
232 | perc = 0.0; | |
263e529f | 233 | |
cf4464ca | 234 | if (td->o.time_based) { |
476882d7 JA |
235 | if (timeout) { |
236 | perc_t = (double) elapsed / (double) timeout; | |
ada6fcee | 237 | if (perc_t < perc) |
476882d7 JA |
238 | perc = perc_t; |
239 | } else { | |
240 | /* | |
241 | * Will never hit, we can't have time_based | |
242 | * without a timeout set. | |
243 | */ | |
244 | perc = 0.0; | |
245 | } | |
cf4464ca JA |
246 | } |
247 | ||
ae5eaf07 SW |
248 | if (perc == 0.0) { |
249 | eta_sec = timeout; | |
250 | } else { | |
251 | eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed; | |
252 | } | |
263e529f | 253 | |
d3eeeabc | 254 | if (td->o.timeout && |
0de5b26f JA |
255 | eta_sec > (timeout + done_secs - elapsed)) |
256 | eta_sec = timeout + done_secs - elapsed; | |
263e529f | 257 | } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED |
b29ee5b3 | 258 | || td->runstate == TD_INITIALIZED |
714e85f3 | 259 | || td->runstate == TD_SETTING_UP |
b0f65863 JA |
260 | || td->runstate == TD_RAMP |
261 | || td->runstate == TD_PRE_READING) { | |
90eff1c9 | 262 | int64_t t_eta = 0, r_eta = 0; |
342f4be4 | 263 | unsigned long long rate_bytes; |
263e529f JA |
264 | |
265 | /* | |
266 | * We can only guess - assume it'll run the full timeout | |
267 | * if given, otherwise assume it'll run at the specified rate. | |
268 | */ | |
b29ee5b3 | 269 | if (td->o.timeout) { |
8a1db9a1 | 270 | uint64_t __timeout = td->o.timeout; |
0de5b26f JA |
271 | uint64_t start_delay = td->o.start_delay; |
272 | uint64_t ramp_time = td->o.ramp_time; | |
273 | ||
ae5eaf07 SW |
274 | t_eta = __timeout + start_delay; |
275 | if (!td->ramp_time_over) { | |
276 | t_eta += ramp_time; | |
277 | } | |
0de5b26f | 278 | t_eta /= 1000000ULL; |
b29ee5b3 | 279 | |
3379b94e | 280 | if ((td->runstate == TD_RAMP) && in_ramp_time(td)) { |
b29ee5b3 JA |
281 | unsigned long ramp_left; |
282 | ||
cda99fa0 | 283 | ramp_left = mtime_since_now(&td->epoch); |
b29ee5b3 JA |
284 | ramp_left = (ramp_left + 999) / 1000; |
285 | if (ramp_left <= t_eta) | |
286 | t_eta -= ramp_left; | |
287 | } | |
288 | } | |
819a4a96 SW |
289 | rate_bytes = 0; |
290 | if (td_read(td)) | |
291 | rate_bytes = td->o.rate[DDIR_READ]; | |
292 | if (td_write(td)) | |
293 | rate_bytes += td->o.rate[DDIR_WRITE]; | |
294 | if (td_trim(td)) | |
295 | rate_bytes += td->o.rate[DDIR_TRIM]; | |
296 | ||
342f4be4 | 297 | if (rate_bytes) { |
819a4a96 | 298 | r_eta = bytes_total / rate_bytes; |
0de5b26f | 299 | r_eta += (td->o.start_delay / 1000000ULL); |
263e529f JA |
300 | } |
301 | ||
302 | if (r_eta && t_eta) | |
303 | eta_sec = min(r_eta, t_eta); | |
304 | else if (r_eta) | |
305 | eta_sec = r_eta; | |
306 | else if (t_eta) | |
307 | eta_sec = t_eta; | |
308 | else | |
309 | eta_sec = 0; | |
310 | } else { | |
311 | /* | |
312 | * thread is already done or waiting for fsync | |
313 | */ | |
314 | eta_sec = 0; | |
315 | } | |
316 | ||
317 | return eta_sec; | |
318 | } | |
319 | ||
771e58be JA |
320 | static void calc_rate(int unified_rw_rep, unsigned long mtime, |
321 | unsigned long long *io_bytes, | |
90eff1c9 | 322 | unsigned long long *prev_io_bytes, uint64_t *rate) |
46fda8d0 | 323 | { |
b7f05eb0 JA |
324 | int i; |
325 | ||
6eaf09d6 | 326 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
1e271b21 | 327 | unsigned long long diff, this_rate; |
b7f05eb0 JA |
328 | |
329 | diff = io_bytes[i] - prev_io_bytes[i]; | |
1e271b21 | 330 | if (mtime) |
420b104a | 331 | this_rate = ((1000 * diff) / mtime) / 1024; /* KiB/s */ |
1e271b21 JA |
332 | else |
333 | this_rate = 0; | |
334 | ||
5cb8a8cd | 335 | if (unified_rw_rep == UNIFIED_MIXED) { |
771e58be | 336 | rate[i] = 0; |
1e271b21 | 337 | rate[0] += this_rate; |
771e58be | 338 | } else |
1e271b21 | 339 | rate[i] = this_rate; |
6eaf09d6 SL |
340 | |
341 | prev_io_bytes[i] = io_bytes[i]; | |
b7f05eb0 | 342 | } |
46fda8d0 | 343 | } |
5ec10eaa | 344 | |
771e58be JA |
345 | static void calc_iops(int unified_rw_rep, unsigned long mtime, |
346 | unsigned long long *io_iops, | |
adb02ba8 JA |
347 | unsigned long long *prev_io_iops, unsigned int *iops) |
348 | { | |
6eaf09d6 SL |
349 | int i; |
350 | ||
351 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { | |
95c2f38e | 352 | unsigned long long diff, this_iops; |
771e58be JA |
353 | |
354 | diff = io_iops[i] - prev_io_iops[i]; | |
95c2f38e JA |
355 | if (mtime) |
356 | this_iops = (diff * 1000) / mtime; | |
357 | else | |
358 | this_iops = 0; | |
359 | ||
5cb8a8cd | 360 | if (unified_rw_rep == UNIFIED_MIXED) { |
771e58be | 361 | iops[i] = 0; |
95c2f38e | 362 | iops[0] += this_iops; |
771e58be | 363 | } else |
95c2f38e | 364 | iops[i] = this_iops; |
771e58be | 365 | |
6eaf09d6 SL |
366 | prev_io_iops[i] = io_iops[i]; |
367 | } | |
adb02ba8 JA |
368 | } |
369 | ||
db37d890 JA |
370 | /* |
371 | * Allow a little slack - if we're within 95% of the time, allow ETA. | |
372 | */ | |
373 | bool eta_time_within_slack(unsigned int time) | |
374 | { | |
375 | return time > ((eta_interval_msec * 95) / 100); | |
376 | } | |
377 | ||
263e529f JA |
378 | /* |
379 | * Print status of the jobs we know about. This includes rate estimates, | |
380 | * ETA, thread state, etc. | |
381 | */ | |
8aa89d70 | 382 | bool calc_thread_status(struct jobs_eta *je, int force) |
263e529f | 383 | { |
34572e28 | 384 | struct thread_data *td; |
771e58be | 385 | int i, unified_rw_rep; |
90eff1c9 | 386 | uint64_t rate_time, disp_time, bw_avg_time, *eta_secs; |
dde39f8c AD |
387 | unsigned long long io_bytes[DDIR_RWDIR_CNT] = {}; |
388 | unsigned long long io_iops[DDIR_RWDIR_CNT] = {}; | |
8b6a404c | 389 | struct timespec now; |
46fda8d0 | 390 | |
6eaf09d6 SL |
391 | static unsigned long long rate_io_bytes[DDIR_RWDIR_CNT]; |
392 | static unsigned long long disp_io_bytes[DDIR_RWDIR_CNT]; | |
393 | static unsigned long long disp_io_iops[DDIR_RWDIR_CNT]; | |
8b6a404c | 394 | static struct timespec rate_prev_time, disp_prev_time; |
6043c579 | 395 | |
af9c9fb3 | 396 | if (!force) { |
129fb2d4 | 397 | if (!(output_format & FIO_OUTPUT_NORMAL) && |
fc47559b | 398 | f_out == stdout) |
8aa89d70 | 399 | return false; |
f3afa57e | 400 | if (temp_stall_ts || eta_print == FIO_ETA_NEVER) |
8aa89d70 | 401 | return false; |
e592a06b | 402 | |
af9c9fb3 | 403 | if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS)) |
8aa89d70 | 404 | return false; |
af9c9fb3 | 405 | } |
263e529f | 406 | |
342f4be4 | 407 | if (!ddir_rw_sum(rate_io_bytes)) |
46fda8d0 | 408 | fill_start_time(&rate_prev_time); |
342f4be4 | 409 | if (!ddir_rw_sum(disp_io_bytes)) |
46fda8d0 | 410 | fill_start_time(&disp_prev_time); |
6043c579 | 411 | |
90eff1c9 SW |
412 | eta_secs = malloc(thread_number * sizeof(uint64_t)); |
413 | memset(eta_secs, 0, thread_number * sizeof(uint64_t)); | |
263e529f | 414 | |
b75a394f JA |
415 | je->elapsed_sec = (mtime_since_genesis() + 999) / 1000; |
416 | ||
bb3884d8 | 417 | bw_avg_time = ULONG_MAX; |
771e58be | 418 | unified_rw_rep = 0; |
34572e28 | 419 | for_each_td(td, i) { |
771e58be | 420 | unified_rw_rep += td->o.unified_rw_rep; |
b7f05eb0 JA |
421 | if (is_power_of_2(td->o.kb_base)) |
422 | je->is_pow2 = 1; | |
ad705bcb | 423 | je->unit_base = td->o.unit_base; |
21cab03c | 424 | je->sig_figs = td->o.sig_figs; |
2dc1bbeb JA |
425 | if (td->o.bw_avg_time < bw_avg_time) |
426 | bw_avg_time = td->o.bw_avg_time; | |
46fda8d0 | 427 | if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING |
b0f65863 | 428 | || td->runstate == TD_FSYNCING |
3d434057 JA |
429 | || td->runstate == TD_PRE_READING |
430 | || td->runstate == TD_FINISHING) { | |
b75a394f | 431 | je->nr_running++; |
242c38db | 432 | if (td_read(td)) { |
c2e9cc4d JA |
433 | je->t_rate[0] += td->o.rate[DDIR_READ]; |
434 | je->t_iops[0] += td->o.rate_iops[DDIR_READ]; | |
435 | je->m_rate[0] += td->o.ratemin[DDIR_READ]; | |
436 | je->m_iops[0] += td->o.rate_iops_min[DDIR_READ]; | |
242c38db JA |
437 | } |
438 | if (td_write(td)) { | |
c2e9cc4d JA |
439 | je->t_rate[1] += td->o.rate[DDIR_WRITE]; |
440 | je->t_iops[1] += td->o.rate_iops[DDIR_WRITE]; | |
441 | je->m_rate[1] += td->o.ratemin[DDIR_WRITE]; | |
442 | je->m_iops[1] += td->o.rate_iops_min[DDIR_WRITE]; | |
242c38db | 443 | } |
6eaf09d6 | 444 | if (td_trim(td)) { |
d79db122 JA |
445 | je->t_rate[2] += td->o.rate[DDIR_TRIM]; |
446 | je->t_iops[2] += td->o.rate_iops[DDIR_TRIM]; | |
447 | je->m_rate[2] += td->o.ratemin[DDIR_TRIM]; | |
448 | je->m_iops[2] += td->o.rate_iops_min[DDIR_TRIM]; | |
6eaf09d6 SL |
449 | } |
450 | ||
b75a394f | 451 | je->files_open += td->nr_open_files; |
b29ee5b3 | 452 | } else if (td->runstate == TD_RAMP) { |
b75a394f JA |
453 | je->nr_running++; |
454 | je->nr_ramp++; | |
aef66dec | 455 | } else if (td->runstate == TD_SETTING_UP) |
714e85f3 | 456 | je->nr_setting_up++; |
aef66dec | 457 | else if (td->runstate < TD_RUNNING) |
b75a394f | 458 | je->nr_pending++; |
263e529f | 459 | |
b75a394f | 460 | if (je->elapsed_sec >= 3) |
b29ee5b3 | 461 | eta_secs[i] = thread_eta(td); |
263e529f JA |
462 | else |
463 | eta_secs[i] = INT_MAX; | |
464 | ||
465 | check_str_update(td); | |
b29ee5b3 | 466 | |
714e85f3 | 467 | if (td->runstate > TD_SETTING_UP) { |
6eaf09d6 | 468 | int ddir; |
771e58be | 469 | |
c1f50f76 | 470 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
771e58be JA |
471 | if (unified_rw_rep) { |
472 | io_bytes[0] += td->io_bytes[ddir]; | |
473 | io_iops[0] += td->io_blocks[ddir]; | |
474 | } else { | |
475 | io_bytes[ddir] += td->io_bytes[ddir]; | |
476 | io_iops[ddir] += td->io_blocks[ddir]; | |
477 | } | |
6eaf09d6 | 478 | } |
b29ee5b3 | 479 | } |
263e529f JA |
480 | } |
481 | ||
3379b94e | 482 | if (exitall_on_terminate) { |
b75a394f | 483 | je->eta_sec = INT_MAX; |
3379b94e | 484 | for_each_td(td, i) { |
b75a394f JA |
485 | if (eta_secs[i] < je->eta_sec) |
486 | je->eta_sec = eta_secs[i]; | |
9c5a3854 | 487 | } |
3379b94e JR |
488 | } else { |
489 | unsigned long eta_stone = 0; | |
490 | ||
491 | je->eta_sec = 0; | |
492 | for_each_td(td, i) { | |
493 | if ((td->runstate == TD_NOT_CREATED) && td->o.stonewall) | |
494 | eta_stone += eta_secs[i]; | |
495 | else { | |
496 | if (eta_secs[i] > je->eta_sec) | |
497 | je->eta_sec = eta_secs[i]; | |
498 | } | |
499 | } | |
500 | je->eta_sec += eta_stone; | |
263e529f JA |
501 | } |
502 | ||
eecf272f JA |
503 | free(eta_secs); |
504 | ||
46fda8d0 JA |
505 | fio_gettime(&now, NULL); |
506 | rate_time = mtime_since(&rate_prev_time, &now); | |
507 | ||
b29ee5b3 | 508 | if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) { |
771e58be | 509 | calc_rate(unified_rw_rep, rate_time, io_bytes, rate_io_bytes, |
da92f848 | 510 | je->rate); |
46fda8d0 | 511 | memcpy(&rate_prev_time, &now, sizeof(now)); |
76204de3 | 512 | regrow_agg_logs(); |
dde39f8c | 513 | for_each_rw_ddir(ddir) { |
03ec570f | 514 | add_agg_sample(sample_val(je->rate[ddir]), ddir, 0); |
dde39f8c | 515 | } |
6043c579 JA |
516 | } |
517 | ||
46fda8d0 | 518 | disp_time = mtime_since(&disp_prev_time, &now); |
a5b01f1b | 519 | |
db37d890 | 520 | if (!force && !eta_time_within_slack(disp_time)) |
8aa89d70 | 521 | return false; |
46fda8d0 | 522 | |
da92f848 BVA |
523 | calc_rate(unified_rw_rep, disp_time, io_bytes, disp_io_bytes, je->rate); |
524 | calc_iops(unified_rw_rep, disp_time, io_iops, disp_io_iops, je->iops); | |
adb02ba8 | 525 | |
46fda8d0 JA |
526 | memcpy(&disp_prev_time, &now, sizeof(now)); |
527 | ||
af9c9fb3 | 528 | if (!force && !je->nr_running && !je->nr_pending) |
8aa89d70 | 529 | return false; |
b75a394f | 530 | |
1d1f45ae | 531 | je->nr_threads = thread_number; |
6c784104 JA |
532 | update_condensed_str(__run_str, run_str); |
533 | memcpy(je->run_str, run_str, strlen(run_str)); | |
8aa89d70 | 534 | return true; |
b75a394f JA |
535 | } |
536 | ||
73027fb9 JA |
537 | static int gen_eta_str(struct jobs_eta *je, char *p, size_t left, |
538 | char **rate_str, char **iops_str) | |
539 | { | |
1582d1ca AD |
540 | static const char c[DDIR_RWDIR_CNT] = {'r', 'w', 't'}; |
541 | bool has[DDIR_RWDIR_CNT]; | |
542 | bool has_any = false; | |
543 | const char *sep; | |
73027fb9 JA |
544 | int l = 0; |
545 | ||
1582d1ca AD |
546 | for_each_rw_ddir(ddir) { |
547 | has[ddir] = (je->rate[ddir] || je->iops[ddir]); | |
548 | has_any |= has[ddir]; | |
549 | } | |
550 | if (!has_any) | |
73027fb9 JA |
551 | return 0; |
552 | ||
1582d1ca AD |
553 | l += snprintf(p + l, left - l, "["); |
554 | sep = ""; | |
555 | for_each_rw_ddir(ddir) { | |
556 | if (has[ddir]) { | |
557 | l += snprintf(p + l, left - l, "%s%c=%s", | |
558 | sep, c[ddir], rate_str[ddir]); | |
559 | sep = ","; | |
560 | } | |
73027fb9 | 561 | } |
1582d1ca AD |
562 | l += snprintf(p + l, left - l, "]["); |
563 | sep = ""; | |
564 | for_each_rw_ddir(ddir) { | |
565 | if (has[ddir]) { | |
566 | l += snprintf(p + l, left - l, "%s%c=%s", | |
567 | sep, c[ddir], iops_str[ddir]); | |
568 | sep = ","; | |
569 | } | |
73027fb9 | 570 | } |
1582d1ca | 571 | l += snprintf(p + l, left - l, " IOPS]"); |
73027fb9 JA |
572 | |
573 | return l; | |
574 | } | |
575 | ||
cf451d1e | 576 | void display_thread_status(struct jobs_eta *je) |
b75a394f | 577 | { |
8b6a404c | 578 | static struct timespec disp_eta_new_line; |
e382e661 | 579 | static int eta_new_line_init, eta_new_line_pending; |
b75a394f JA |
580 | static int linelen_last; |
581 | static int eta_good; | |
2b34ccad | 582 | char output[__THREAD_RUNSTR_SZ(REAL_MAX_JOBS) + 512], *p = output; |
b75a394f JA |
583 | char eta_str[128]; |
584 | double perc = 0.0; | |
b75a394f | 585 | |
cf451d1e JA |
586 | if (je->eta_sec != INT_MAX && je->elapsed_sec) { |
587 | perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec); | |
588 | eta_to_str(eta_str, je->eta_sec); | |
b75a394f JA |
589 | } |
590 | ||
e382e661 JA |
591 | if (eta_new_line_pending) { |
592 | eta_new_line_pending = 0; | |
ab1ace62 | 593 | linelen_last = 0; |
e382e661 JA |
594 | p += sprintf(p, "\n"); |
595 | } | |
596 | ||
cf451d1e | 597 | p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open); |
d694a6a7 RE |
598 | |
599 | /* rate limits, if any */ | |
600 | if (je->m_rate[0] || je->m_rate[1] || je->m_rate[2] || | |
601 | je->t_rate[0] || je->t_rate[1] || je->t_rate[2]) { | |
581e7141 JA |
602 | char *tr, *mr; |
603 | ||
d694a6a7 | 604 | mr = num2str(je->m_rate[0] + je->m_rate[1] + je->m_rate[2], |
21cab03c | 605 | je->sig_figs, 1, je->is_pow2, N2S_BYTEPERSEC); |
d694a6a7 | 606 | tr = num2str(je->t_rate[0] + je->t_rate[1] + je->t_rate[2], |
21cab03c | 607 | je->sig_figs, 1, je->is_pow2, N2S_BYTEPERSEC); |
d694a6a7 RE |
608 | |
609 | p += sprintf(p, ", %s-%s", mr, tr); | |
581e7141 JA |
610 | free(tr); |
611 | free(mr); | |
d694a6a7 RE |
612 | } else if (je->m_iops[0] || je->m_iops[1] || je->m_iops[2] || |
613 | je->t_iops[0] || je->t_iops[1] || je->t_iops[2]) { | |
614 | p += sprintf(p, ", %d-%d IOPS", | |
615 | je->m_iops[0] + je->m_iops[1] + je->m_iops[2], | |
616 | je->t_iops[0] + je->t_iops[1] + je->t_iops[2]); | |
3e47bd25 | 617 | } |
d694a6a7 RE |
618 | |
619 | /* current run string, % done, bandwidth, iops, eta */ | |
cf451d1e | 620 | if (je->eta_sec != INT_MAX && je->nr_running) { |
0721d11e | 621 | char perc_str[32]; |
6eaf09d6 SL |
622 | char *iops_str[DDIR_RWDIR_CNT]; |
623 | char *rate_str[DDIR_RWDIR_CNT]; | |
79074e7c | 624 | size_t left; |
adb02ba8 | 625 | int l; |
6eaf09d6 | 626 | int ddir; |
45d41a8b | 627 | int linelen; |
5ec10eaa | 628 | |
263775ad LG |
629 | if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running || |
630 | je->eta_sec == -1) | |
d694a6a7 | 631 | strcpy(perc_str, "-.-%"); |
cac58fd5 | 632 | else { |
714e85f3 JA |
633 | double mult = 100.0; |
634 | ||
635 | if (je->nr_setting_up && je->nr_running) | |
636 | mult *= (1.0 - (double) je->nr_setting_up / (double) je->nr_running); | |
637 | ||
cac58fd5 | 638 | eta_good = 1; |
714e85f3 | 639 | perc *= mult; |
d694a6a7 | 640 | sprintf(perc_str, "%3.1f%%", perc); |
cac58fd5 | 641 | } |
0721d11e | 642 | |
c1f50f76 | 643 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
d694a6a7 | 644 | rate_str[ddir] = num2str(je->rate[ddir], 4, |
ad705bcb | 645 | 1024, je->is_pow2, je->unit_base); |
d694a6a7 | 646 | iops_str[ddir] = num2str(je->iops[ddir], 4, 1, 0, N2S_NONE); |
6eaf09d6 | 647 | } |
adb02ba8 | 648 | |
38aef42d | 649 | left = sizeof(output) - (p - output) - 1; |
73027fb9 JA |
650 | l = snprintf(p, left, ": [%s][%s]", je->run_str, perc_str); |
651 | l += gen_eta_str(je, p + l, left - l, rate_str, iops_str); | |
652 | l += snprintf(p + l, left - l, "[eta %s]", eta_str); | |
79074e7c | 653 | |
38aef42d SW |
654 | /* If truncation occurred adjust l so p is on the null */ |
655 | if (l >= left) | |
656 | l = left - 1; | |
37db14fe | 657 | p += l; |
45d41a8b SW |
658 | linelen = p - output; |
659 | if (l >= 0 && linelen < linelen_last) | |
660 | p += sprintf(p, "%*s", linelen_last - linelen, ""); | |
661 | linelen_last = linelen; | |
d1bd7213 | 662 | |
c1f50f76 | 663 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
6eaf09d6 SL |
664 | free(rate_str[ddir]); |
665 | free(iops_str[ddir]); | |
666 | } | |
263e529f | 667 | } |
1612c4a5 | 668 | sprintf(p, "\r"); |
37db14fe | 669 | |
3e47bd25 | 670 | printf("%s", output); |
e382e661 JA |
671 | |
672 | if (!eta_new_line_init) { | |
673 | fio_gettime(&disp_eta_new_line, NULL); | |
674 | eta_new_line_init = 1; | |
88038bc7 | 675 | } else if (eta_new_line && mtime_since_now(&disp_eta_new_line) > eta_new_line) { |
e382e661 JA |
676 | fio_gettime(&disp_eta_new_line, NULL); |
677 | eta_new_line_pending = 1; | |
678 | } | |
679 | ||
3e47bd25 | 680 | fflush(stdout); |
263e529f JA |
681 | } |
682 | ||
c5103619 | 683 | struct jobs_eta *get_jobs_eta(bool force, size_t *size) |
cf451d1e | 684 | { |
1d1f45ae JA |
685 | struct jobs_eta *je; |
686 | ||
b814fb26 | 687 | if (!thread_number) |
723297c9 | 688 | return NULL; |
cf451d1e | 689 | |
e98e0eb5 | 690 | *size = sizeof(*je) + THREAD_RUNSTR_SZ + 8; |
723297c9 | 691 | je = malloc(*size); |
70034d87 RE |
692 | if (!je) |
693 | return NULL; | |
723297c9 JA |
694 | memset(je, 0, *size); |
695 | ||
256bc54c | 696 | if (!calc_thread_status(je, force)) { |
723297c9 JA |
697 | free(je); |
698 | return NULL; | |
699 | } | |
700 | ||
05bff935 | 701 | *size = sizeof(*je) + strlen((char *) je->run_str) + 1; |
723297c9 JA |
702 | return je; |
703 | } | |
704 | ||
705 | void print_thread_status(void) | |
706 | { | |
707 | struct jobs_eta *je; | |
708 | size_t size; | |
cf451d1e | 709 | |
c5103619 | 710 | je = get_jobs_eta(false, &size); |
0fc3cb4c | 711 | if (je) { |
1d1f45ae | 712 | display_thread_status(je); |
0fc3cb4c DP |
713 | free(je); |
714 | } | |
cf451d1e | 715 | } |
b75a394f | 716 | |
2b13e716 | 717 | void print_status_init(int thr_number) |
263e529f | 718 | { |
dc54b6ca JA |
719 | struct jobs_eta_packed jep; |
720 | ||
721 | compiletime_assert(sizeof(struct jobs_eta) == sizeof(jep), "jobs_eta"); | |
4c515ab4 | 722 | |
4f37732a | 723 | DRD_IGNORE_VAR(__run_str); |
3e2e48a7 JA |
724 | __run_str[thr_number] = 'P'; |
725 | update_condensed_str(__run_str, run_str); | |
263e529f | 726 | } |