10 static char __run_str[REAL_MAX_JOBS + 1];
13 * Worst level condensing would be 1:4, so allow enough room for that
15 static char run_str[(4 * REAL_MAX_JOBS) + 1];
17 static void update_condensed_str(char *run_str, char *run_str_condensed)
22 len = strlen(run_str);
29 for (i = 0; i < len; i++) {
32 run_str_condensed[ci] = run_str[i];
36 } else if (last == run_str[i]) {
41 elen = sprintf(&run_str_condensed[ci], "(%u),", nr);
48 sprintf(&run_str_condensed[ci], "(%u)", nr);
53 * Sets the status of the 'td' in the printed status map.
55 static void check_str_update(struct thread_data *td)
57 char c = __run_str[td->thread_number - 1];
59 switch (td->runstate) {
77 if (td->o.rwmix[DDIR_READ] == 100)
79 else if (td->o.rwmix[DDIR_WRITE] == 100)
84 if (td->o.rwmix[DDIR_READ] == 100)
86 else if (td->o.rwmix[DDIR_WRITE] == 100)
91 } else if (td_read(td)) {
96 } else if (td_write(td)) {
131 log_err("state %d\n", td->runstate);
134 __run_str[td->thread_number - 1] = c;
135 update_condensed_str(__run_str, run_str);
139 * Convert seconds to a printable string.
141 void eta_to_str(char *str, unsigned long eta_sec)
143 unsigned int d, h, m, s;
156 str += sprintf(str, "%02ud:", d);
160 str += sprintf(str, "%02uh:", h);
162 str += sprintf(str, "%02um:", m);
163 str += sprintf(str, "%02us", s);
167 * Best effort calculation of the estimated pending runtime of a job.
169 static int thread_eta(struct thread_data *td)
171 unsigned long long bytes_total, bytes_done;
172 unsigned long eta_sec = 0;
173 unsigned long elapsed;
176 elapsed = (mtime_since_now(&td->epoch) + 999) / 1000;
177 timeout = td->o.timeout / 1000000UL;
179 bytes_total = td->total_io_size;
181 if (td->o.fill_device && td->o.size == -1ULL) {
182 if (!td->fill_device_size || td->fill_device_size == -1ULL)
185 bytes_total = td->fill_device_size;
188 if (td->o.zone_size && td->o.zone_skip && bytes_total) {
189 unsigned int nr_zones;
192 zone_bytes = bytes_total + td->o.zone_size + td->o.zone_skip;
193 nr_zones = (zone_bytes - 1) / (td->o.zone_size + td->o.zone_skip);
194 bytes_total -= nr_zones * td->o.zone_skip;
198 * if writing and verifying afterwards, bytes_total will be twice the
199 * size. In a mixed workload, verify phase will be the size of the
200 * first stage writes.
202 if (td->o.do_verify && td->o.verify && td_write(td)) {
204 unsigned int perc = 50;
206 if (td->o.rwmix[DDIR_WRITE])
207 perc = td->o.rwmix[DDIR_WRITE];
209 bytes_total += (bytes_total * perc) / 100;
214 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
217 bytes_done = ddir_rw_sum(td->io_bytes);
220 perc = (double) bytes_done / (double) bytes_total;
226 if (td->o.time_based) {
228 perc_t = (double) elapsed / (double) timeout;
233 * Will never hit, we can't have time_based
234 * without a timeout set.
240 eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;
243 eta_sec > (timeout + done_secs - elapsed))
244 eta_sec = timeout + done_secs - elapsed;
245 } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
246 || td->runstate == TD_INITIALIZED
247 || td->runstate == TD_SETTING_UP
248 || td->runstate == TD_RAMP
249 || td->runstate == TD_PRE_READING) {
250 int t_eta = 0, r_eta = 0;
251 unsigned long long rate_bytes;
254 * We can only guess - assume it'll run the full timeout
255 * if given, otherwise assume it'll run at the specified rate.
258 uint64_t timeout = td->o.timeout;
259 uint64_t start_delay = td->o.start_delay;
260 uint64_t ramp_time = td->o.ramp_time;
262 t_eta = timeout + start_delay + ramp_time;
265 if (in_ramp_time(td)) {
266 unsigned long ramp_left;
268 ramp_left = mtime_since_now(&td->epoch);
269 ramp_left = (ramp_left + 999) / 1000;
270 if (ramp_left <= t_eta)
274 rate_bytes = ddir_rw_sum(td->o.rate);
276 r_eta = (bytes_total / 1024) / rate_bytes;
277 r_eta += (td->o.start_delay / 1000000ULL);
281 eta_sec = min(r_eta, t_eta);
290 * thread is already done or waiting for fsync
298 static void calc_rate(int unified_rw_rep, unsigned long mtime,
299 unsigned long long *io_bytes,
300 unsigned long long *prev_io_bytes, unsigned int *rate)
304 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
305 unsigned long long diff;
307 diff = io_bytes[i] - prev_io_bytes[i];
308 if (unified_rw_rep) {
310 rate[0] += ((1000 * diff) / mtime) / 1024;
312 rate[i] = ((1000 * diff) / mtime) / 1024;
314 prev_io_bytes[i] = io_bytes[i];
318 static void calc_iops(int unified_rw_rep, unsigned long mtime,
319 unsigned long long *io_iops,
320 unsigned long long *prev_io_iops, unsigned int *iops)
324 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
325 unsigned long long diff;
327 diff = io_iops[i] - prev_io_iops[i];
328 if (unified_rw_rep) {
330 iops[0] += (diff * 1000) / mtime;
332 iops[i] = (diff * 1000) / mtime;
334 prev_io_iops[i] = io_iops[i];
339 * Print status of the jobs we know about. This includes rate estimates,
340 * ETA, thread state, etc.
342 int calc_thread_status(struct jobs_eta *je, int force)
344 struct thread_data *td;
345 int i, unified_rw_rep;
346 unsigned long rate_time, disp_time, bw_avg_time, *eta_secs;
347 unsigned long long io_bytes[DDIR_RWDIR_CNT];
348 unsigned long long io_iops[DDIR_RWDIR_CNT];
351 static unsigned long long rate_io_bytes[DDIR_RWDIR_CNT];
352 static unsigned long long disp_io_bytes[DDIR_RWDIR_CNT];
353 static unsigned long long disp_io_iops[DDIR_RWDIR_CNT];
354 static struct timeval rate_prev_time, disp_prev_time;
357 if (output_format != FIO_OUTPUT_NORMAL &&
360 if (temp_stall_ts || eta_print == FIO_ETA_NEVER)
363 if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
367 if (!ddir_rw_sum(rate_io_bytes))
368 fill_start_time(&rate_prev_time);
369 if (!ddir_rw_sum(disp_io_bytes))
370 fill_start_time(&disp_prev_time);
372 eta_secs = malloc(thread_number * sizeof(unsigned long));
373 memset(eta_secs, 0, thread_number * sizeof(unsigned long));
375 je->elapsed_sec = (mtime_since_genesis() + 999) / 1000;
377 io_bytes[DDIR_READ] = io_bytes[DDIR_WRITE] = io_bytes[DDIR_TRIM] = 0;
378 io_iops[DDIR_READ] = io_iops[DDIR_WRITE] = io_iops[DDIR_TRIM] = 0;
379 bw_avg_time = ULONG_MAX;
382 unified_rw_rep += td->o.unified_rw_rep;
383 if (is_power_of_2(td->o.kb_base))
385 je->unit_base = td->o.unit_base;
386 if (td->o.bw_avg_time < bw_avg_time)
387 bw_avg_time = td->o.bw_avg_time;
388 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
389 || td->runstate == TD_FSYNCING
390 || td->runstate == TD_PRE_READING
391 || td->runstate == TD_FINISHING) {
394 je->t_rate[0] += td->o.rate[DDIR_READ];
395 je->t_iops[0] += td->o.rate_iops[DDIR_READ];
396 je->m_rate[0] += td->o.ratemin[DDIR_READ];
397 je->m_iops[0] += td->o.rate_iops_min[DDIR_READ];
400 je->t_rate[1] += td->o.rate[DDIR_WRITE];
401 je->t_iops[1] += td->o.rate_iops[DDIR_WRITE];
402 je->m_rate[1] += td->o.ratemin[DDIR_WRITE];
403 je->m_iops[1] += td->o.rate_iops_min[DDIR_WRITE];
406 je->t_rate[2] += td->o.rate[DDIR_TRIM];
407 je->t_iops[2] += td->o.rate_iops[DDIR_TRIM];
408 je->m_rate[2] += td->o.ratemin[DDIR_TRIM];
409 je->m_iops[2] += td->o.rate_iops_min[DDIR_TRIM];
412 je->files_open += td->nr_open_files;
413 } else if (td->runstate == TD_RAMP) {
416 } else if (td->runstate == TD_SETTING_UP) {
419 } else if (td->runstate < TD_RUNNING)
422 if (je->elapsed_sec >= 3)
423 eta_secs[i] = thread_eta(td);
425 eta_secs[i] = INT_MAX;
427 check_str_update(td);
429 if (td->runstate > TD_SETTING_UP) {
432 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
433 if (unified_rw_rep) {
434 io_bytes[0] += td->io_bytes[ddir];
435 io_iops[0] += td->io_blocks[ddir];
437 io_bytes[ddir] += td->io_bytes[ddir];
438 io_iops[ddir] += td->io_blocks[ddir];
444 if (exitall_on_terminate)
445 je->eta_sec = INT_MAX;
450 if (exitall_on_terminate) {
451 if (eta_secs[i] < je->eta_sec)
452 je->eta_sec = eta_secs[i];
454 if (eta_secs[i] > je->eta_sec)
455 je->eta_sec = eta_secs[i];
461 fio_gettime(&now, NULL);
462 rate_time = mtime_since(&rate_prev_time, &now);
464 if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
465 calc_rate(unified_rw_rep, rate_time, io_bytes, rate_io_bytes,
467 memcpy(&rate_prev_time, &now, sizeof(now));
468 add_agg_sample(je->rate[DDIR_READ], DDIR_READ, 0);
469 add_agg_sample(je->rate[DDIR_WRITE], DDIR_WRITE, 0);
470 add_agg_sample(je->rate[DDIR_TRIM], DDIR_TRIM, 0);
473 disp_time = mtime_since(&disp_prev_time, &now);
476 * Allow a little slack, the target is to print it every 1000 msecs
478 if (!force && disp_time < 900)
481 calc_rate(unified_rw_rep, disp_time, io_bytes, disp_io_bytes, je->rate);
482 calc_iops(unified_rw_rep, disp_time, io_iops, disp_io_iops, je->iops);
484 memcpy(&disp_prev_time, &now, sizeof(now));
486 if (!force && !je->nr_running && !je->nr_pending)
489 je->nr_threads = thread_number;
490 memcpy(je->run_str, run_str, thread_number * sizeof(char));
494 void display_thread_status(struct jobs_eta *je)
496 static struct timeval disp_eta_new_line;
497 static int eta_new_line_init, eta_new_line_pending;
498 static int linelen_last;
500 char output[REAL_MAX_JOBS + 512], *p = output;
504 if (je->eta_sec != INT_MAX && je->elapsed_sec) {
505 perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
506 eta_to_str(eta_str, je->eta_sec);
509 if (eta_new_line_pending) {
510 eta_new_line_pending = 0;
511 p += sprintf(p, "\n");
514 p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open);
515 if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
518 mr = num2str(je->m_rate[0] + je->m_rate[1], 4, 0, je->is_pow2, 8);
519 tr = num2str(je->t_rate[0] + je->t_rate[1], 4, 0, je->is_pow2, 8);
520 p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
523 } else if (je->m_iops[0] || je->m_iops[1] || je->t_iops[0] || je->t_iops[1]) {
524 p += sprintf(p, ", CR=%d/%d IOPS",
525 je->t_iops[0] + je->t_iops[1],
526 je->m_iops[0] + je->m_iops[1]);
528 if (je->eta_sec != INT_MAX && je->nr_running) {
530 char *iops_str[DDIR_RWDIR_CNT];
531 char *rate_str[DDIR_RWDIR_CNT];
536 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
537 strcpy(perc_str, "-.-% done");
541 if (je->nr_setting_up && je->nr_running)
542 mult *= (1.0 - (double) je->nr_setting_up / (double) je->nr_running);
546 sprintf(perc_str, "%3.1f%% done", perc);
549 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
550 rate_str[ddir] = num2str(je->rate[ddir], 5,
551 1024, je->is_pow2, je->unit_base);
552 iops_str[ddir] = num2str(je->iops[ddir], 4, 1, 0, 0);
555 left = sizeof(output) - (p - output) - 1;
557 l = snprintf(p, left, ": [%s] [%s] [%s/%s/%s /s] [%s/%s/%s iops] [eta %s]",
558 je->run_str, perc_str, rate_str[DDIR_READ],
559 rate_str[DDIR_WRITE], rate_str[DDIR_TRIM],
560 iops_str[DDIR_READ], iops_str[DDIR_WRITE],
561 iops_str[DDIR_TRIM], eta_str);
563 if (l >= 0 && l < linelen_last)
564 p += sprintf(p, "%*s", linelen_last - l, "");
567 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
568 free(rate_str[ddir]);
569 free(iops_str[ddir]);
572 p += sprintf(p, "\r");
574 printf("%s", output);
576 if (!eta_new_line_init) {
577 fio_gettime(&disp_eta_new_line, NULL);
578 eta_new_line_init = 1;
579 } else if (eta_new_line &&
580 mtime_since_now(&disp_eta_new_line) > eta_new_line * 1000) {
581 fio_gettime(&disp_eta_new_line, NULL);
582 eta_new_line_pending = 1;
588 void print_thread_status(void)
596 size = sizeof(*je) + thread_number * sizeof(char) + 1;
600 if (calc_thread_status(je, 0))
601 display_thread_status(je);
606 void print_status_init(int thr_number)
608 __run_str[thr_number] = 'P';
609 update_condensed_str(__run_str, run_str);