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