10 static char __run_str[REAL_MAX_JOBS + 1];
11 static char run_str[__THREAD_RUNSTR_SZ(REAL_MAX_JOBS)];
13 static void update_condensed_str(char *run_str, char *run_str_condensed)
18 len = strlen(run_str);
25 for (i = 0; i < len; i++) {
28 run_str_condensed[ci] = run_str[i];
32 } else if (last == run_str[i]) {
35 ci += sprintf(&run_str_condensed[ci], "(%u),", nr);
41 ci += sprintf(&run_str_condensed[ci], "(%u)", nr);
43 run_str_condensed[ci + 1] = '\0';
47 * Sets the status of the 'td' in the printed status map.
49 static void check_str_update(struct thread_data *td)
51 char c = __run_str[td->thread_number - 1];
53 switch (td->runstate) {
71 if (td->o.rwmix[DDIR_READ] == 100)
73 else if (td->o.rwmix[DDIR_WRITE] == 100)
78 if (td->o.rwmix[DDIR_READ] == 100)
80 else if (td->o.rwmix[DDIR_WRITE] == 100)
85 } else if (td_read(td)) {
90 } else if (td_write(td)) {
125 log_err("state %d\n", td->runstate);
128 __run_str[td->thread_number - 1] = c;
129 update_condensed_str(__run_str, run_str);
133 * Convert seconds to a printable string.
135 void eta_to_str(char *str, unsigned long eta_sec)
137 unsigned int d, h, m, s;
150 str += sprintf(str, "%02ud:", d);
154 str += sprintf(str, "%02uh:", h);
156 str += sprintf(str, "%02um:", m);
157 str += sprintf(str, "%02us", s);
161 * Best effort calculation of the estimated pending runtime of a job.
163 static int thread_eta(struct thread_data *td)
165 unsigned long long bytes_total, bytes_done;
166 unsigned long eta_sec = 0;
167 unsigned long elapsed;
170 elapsed = (mtime_since_now(&td->epoch) + 999) / 1000;
171 timeout = td->o.timeout / 1000000UL;
173 bytes_total = td->total_io_size;
175 if (td->o.fill_device && td->o.size == -1ULL) {
176 if (!td->fill_device_size || td->fill_device_size == -1ULL)
179 bytes_total = td->fill_device_size;
182 if (td->o.zone_size && td->o.zone_skip && bytes_total) {
183 unsigned int nr_zones;
186 zone_bytes = bytes_total + td->o.zone_size + td->o.zone_skip;
187 nr_zones = (zone_bytes - 1) / (td->o.zone_size + td->o.zone_skip);
188 bytes_total -= nr_zones * td->o.zone_skip;
192 * if writing and verifying afterwards, bytes_total will be twice the
193 * size. In a mixed workload, verify phase will be the size of the
194 * first stage writes.
196 if (td->o.do_verify && td->o.verify && td_write(td)) {
198 unsigned int perc = 50;
200 if (td->o.rwmix[DDIR_WRITE])
201 perc = td->o.rwmix[DDIR_WRITE];
203 bytes_total += (bytes_total * perc) / 100;
208 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING) {
211 bytes_done = ddir_rw_sum(td->io_bytes);
214 perc = (double) bytes_done / (double) bytes_total;
220 if (td->o.time_based) {
222 perc_t = (double) elapsed / (double) timeout;
227 * Will never hit, we can't have time_based
228 * without a timeout set.
234 eta_sec = (unsigned long) (elapsed * (1.0 / perc)) - elapsed;
237 eta_sec > (timeout + done_secs - elapsed))
238 eta_sec = timeout + done_secs - elapsed;
239 } else if (td->runstate == TD_NOT_CREATED || td->runstate == TD_CREATED
240 || td->runstate == TD_INITIALIZED
241 || td->runstate == TD_SETTING_UP
242 || td->runstate == TD_RAMP
243 || td->runstate == TD_PRE_READING) {
244 int t_eta = 0, r_eta = 0;
245 unsigned long long rate_bytes;
248 * We can only guess - assume it'll run the full timeout
249 * if given, otherwise assume it'll run at the specified rate.
252 uint64_t timeout = td->o.timeout;
253 uint64_t start_delay = td->o.start_delay;
254 uint64_t ramp_time = td->o.ramp_time;
256 t_eta = timeout + start_delay + ramp_time;
259 if (in_ramp_time(td)) {
260 unsigned long ramp_left;
262 ramp_left = mtime_since_now(&td->epoch);
263 ramp_left = (ramp_left + 999) / 1000;
264 if (ramp_left <= t_eta)
268 rate_bytes = ddir_rw_sum(td->o.rate);
270 r_eta = (bytes_total / 1024) / rate_bytes;
271 r_eta += (td->o.start_delay / 1000000ULL);
275 eta_sec = min(r_eta, t_eta);
284 * thread is already done or waiting for fsync
292 static void calc_rate(int unified_rw_rep, unsigned long mtime,
293 unsigned long long *io_bytes,
294 unsigned long long *prev_io_bytes, unsigned int *rate)
298 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
299 unsigned long long diff;
301 diff = io_bytes[i] - prev_io_bytes[i];
302 if (unified_rw_rep) {
304 rate[0] += ((1000 * diff) / mtime) / 1024;
306 rate[i] = ((1000 * diff) / mtime) / 1024;
308 prev_io_bytes[i] = io_bytes[i];
312 static void calc_iops(int unified_rw_rep, unsigned long mtime,
313 unsigned long long *io_iops,
314 unsigned long long *prev_io_iops, unsigned int *iops)
318 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
319 unsigned long long diff;
321 diff = io_iops[i] - prev_io_iops[i];
322 if (unified_rw_rep) {
324 iops[0] += (diff * 1000) / mtime;
326 iops[i] = (diff * 1000) / mtime;
328 prev_io_iops[i] = io_iops[i];
333 * Print status of the jobs we know about. This includes rate estimates,
334 * ETA, thread state, etc.
336 int calc_thread_status(struct jobs_eta *je, int force)
338 struct thread_data *td;
339 int i, unified_rw_rep;
340 unsigned long rate_time, disp_time, bw_avg_time, *eta_secs;
341 unsigned long long io_bytes[DDIR_RWDIR_CNT];
342 unsigned long long io_iops[DDIR_RWDIR_CNT];
345 static unsigned long long rate_io_bytes[DDIR_RWDIR_CNT];
346 static unsigned long long disp_io_bytes[DDIR_RWDIR_CNT];
347 static unsigned long long disp_io_iops[DDIR_RWDIR_CNT];
348 static struct timeval rate_prev_time, disp_prev_time;
351 if (output_format != FIO_OUTPUT_NORMAL &&
354 if (temp_stall_ts || eta_print == FIO_ETA_NEVER)
357 if (!isatty(STDOUT_FILENO) && (eta_print != FIO_ETA_ALWAYS))
361 if (!ddir_rw_sum(rate_io_bytes))
362 fill_start_time(&rate_prev_time);
363 if (!ddir_rw_sum(disp_io_bytes))
364 fill_start_time(&disp_prev_time);
366 eta_secs = malloc(thread_number * sizeof(unsigned long));
367 memset(eta_secs, 0, thread_number * sizeof(unsigned long));
369 je->elapsed_sec = (mtime_since_genesis() + 999) / 1000;
371 io_bytes[DDIR_READ] = io_bytes[DDIR_WRITE] = io_bytes[DDIR_TRIM] = 0;
372 io_iops[DDIR_READ] = io_iops[DDIR_WRITE] = io_iops[DDIR_TRIM] = 0;
373 bw_avg_time = ULONG_MAX;
376 unified_rw_rep += td->o.unified_rw_rep;
377 if (is_power_of_2(td->o.kb_base))
379 je->unit_base = td->o.unit_base;
380 if (td->o.bw_avg_time < bw_avg_time)
381 bw_avg_time = td->o.bw_avg_time;
382 if (td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING
383 || td->runstate == TD_FSYNCING
384 || td->runstate == TD_PRE_READING
385 || td->runstate == TD_FINISHING) {
388 je->t_rate[0] += td->o.rate[DDIR_READ];
389 je->t_iops[0] += td->o.rate_iops[DDIR_READ];
390 je->m_rate[0] += td->o.ratemin[DDIR_READ];
391 je->m_iops[0] += td->o.rate_iops_min[DDIR_READ];
394 je->t_rate[1] += td->o.rate[DDIR_WRITE];
395 je->t_iops[1] += td->o.rate_iops[DDIR_WRITE];
396 je->m_rate[1] += td->o.ratemin[DDIR_WRITE];
397 je->m_iops[1] += td->o.rate_iops_min[DDIR_WRITE];
400 je->t_rate[2] += td->o.rate[DDIR_TRIM];
401 je->t_iops[2] += td->o.rate_iops[DDIR_TRIM];
402 je->m_rate[2] += td->o.ratemin[DDIR_TRIM];
403 je->m_iops[2] += td->o.rate_iops_min[DDIR_TRIM];
406 je->files_open += td->nr_open_files;
407 } else if (td->runstate == TD_RAMP) {
410 } else if (td->runstate == TD_SETTING_UP) {
413 } else if (td->runstate < TD_RUNNING)
416 if (je->elapsed_sec >= 3)
417 eta_secs[i] = thread_eta(td);
419 eta_secs[i] = INT_MAX;
421 check_str_update(td);
423 if (td->runstate > TD_SETTING_UP) {
426 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
427 if (unified_rw_rep) {
428 io_bytes[0] += td->io_bytes[ddir];
429 io_iops[0] += td->io_blocks[ddir];
431 io_bytes[ddir] += td->io_bytes[ddir];
432 io_iops[ddir] += td->io_blocks[ddir];
438 if (exitall_on_terminate)
439 je->eta_sec = INT_MAX;
444 if (exitall_on_terminate) {
445 if (eta_secs[i] < je->eta_sec)
446 je->eta_sec = eta_secs[i];
448 if (eta_secs[i] > je->eta_sec)
449 je->eta_sec = eta_secs[i];
455 fio_gettime(&now, NULL);
456 rate_time = mtime_since(&rate_prev_time, &now);
458 if (write_bw_log && rate_time > bw_avg_time && !in_ramp_time(td)) {
459 calc_rate(unified_rw_rep, rate_time, io_bytes, rate_io_bytes,
461 memcpy(&rate_prev_time, &now, sizeof(now));
462 add_agg_sample(je->rate[DDIR_READ], DDIR_READ, 0);
463 add_agg_sample(je->rate[DDIR_WRITE], DDIR_WRITE, 0);
464 add_agg_sample(je->rate[DDIR_TRIM], DDIR_TRIM, 0);
467 disp_time = mtime_since(&disp_prev_time, &now);
470 * Allow a little slack, the target is to print it every 1000 msecs
472 if (!force && disp_time < 900)
475 calc_rate(unified_rw_rep, disp_time, io_bytes, disp_io_bytes, je->rate);
476 calc_iops(unified_rw_rep, disp_time, io_iops, disp_io_iops, je->iops);
478 memcpy(&disp_prev_time, &now, sizeof(now));
480 if (!force && !je->nr_running && !je->nr_pending)
483 je->nr_threads = thread_number;
484 update_condensed_str(__run_str, run_str);
485 memcpy(je->run_str, run_str, strlen(run_str));
489 void display_thread_status(struct jobs_eta *je)
491 static struct timeval disp_eta_new_line;
492 static int eta_new_line_init, eta_new_line_pending;
493 static int linelen_last;
495 char output[REAL_MAX_JOBS + 512], *p = output;
499 if (je->eta_sec != INT_MAX && je->elapsed_sec) {
500 perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
501 eta_to_str(eta_str, je->eta_sec);
504 if (eta_new_line_pending) {
505 eta_new_line_pending = 0;
506 p += sprintf(p, "\n");
509 p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open);
510 if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
513 mr = num2str(je->m_rate[0] + je->m_rate[1], 4, 0, je->is_pow2, 8);
514 tr = num2str(je->t_rate[0] + je->t_rate[1], 4, 0, je->is_pow2, 8);
515 p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
518 } else if (je->m_iops[0] || je->m_iops[1] || je->t_iops[0] || je->t_iops[1]) {
519 p += sprintf(p, ", CR=%d/%d IOPS",
520 je->t_iops[0] + je->t_iops[1],
521 je->m_iops[0] + je->m_iops[1]);
523 if (je->eta_sec != INT_MAX && je->nr_running) {
525 char *iops_str[DDIR_RWDIR_CNT];
526 char *rate_str[DDIR_RWDIR_CNT];
531 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
532 strcpy(perc_str, "-.-% done");
536 if (je->nr_setting_up && je->nr_running)
537 mult *= (1.0 - (double) je->nr_setting_up / (double) je->nr_running);
541 sprintf(perc_str, "%3.1f%% done", perc);
544 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
545 rate_str[ddir] = num2str(je->rate[ddir], 5,
546 1024, je->is_pow2, je->unit_base);
547 iops_str[ddir] = num2str(je->iops[ddir], 4, 1, 0, 0);
550 left = sizeof(output) - (p - output) - 1;
552 l = snprintf(p, left, ": [%s] [%s] [%s/%s/%s /s] [%s/%s/%s iops] [eta %s]",
553 je->run_str, perc_str, rate_str[DDIR_READ],
554 rate_str[DDIR_WRITE], rate_str[DDIR_TRIM],
555 iops_str[DDIR_READ], iops_str[DDIR_WRITE],
556 iops_str[DDIR_TRIM], eta_str);
558 if (l >= 0 && l < linelen_last)
559 p += sprintf(p, "%*s", linelen_last - l, "");
562 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
563 free(rate_str[ddir]);
564 free(iops_str[ddir]);
567 p += sprintf(p, "\r");
569 printf("%s", output);
571 if (!eta_new_line_init) {
572 fio_gettime(&disp_eta_new_line, NULL);
573 eta_new_line_init = 1;
574 } else if (eta_new_line &&
575 mtime_since_now(&disp_eta_new_line) > eta_new_line * 1000) {
576 fio_gettime(&disp_eta_new_line, NULL);
577 eta_new_line_pending = 1;
583 struct jobs_eta *get_jobs_eta(int force, size_t *size)
590 *size = sizeof(*je) + THREAD_RUNSTR_SZ;
592 memset(je, 0, *size);
594 if (!calc_thread_status(je, 0)) {
602 void print_thread_status(void)
607 je = get_jobs_eta(0, &size);
609 display_thread_status(je);
614 void print_status_init(int thr_number)
616 __run_str[thr_number] = 'P';
617 update_condensed_str(__run_str, run_str);