From 643e4039452ee151f27a1407a4277cc864b776f2 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 7 Dec 2005 12:05:36 +0100 Subject: [PATCH] [PATCH] fio: cleanup thread print status and add progress percentage --- fio.c | 67 ++++++++++++++++++++++++++++++++++++----------------------- fio.h | 1 + 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/fio.c b/fio.c index 1ed7b48..1a9f052 100644 --- a/fio.c +++ b/fio.c @@ -54,6 +54,7 @@ static struct itimerval itimer; static void update_io_ticks(void); static void disk_util_timer_arm(void); +static void print_thread_status(void); /* * thread life cycle @@ -93,6 +94,7 @@ static void sig_handler(int sig) case SIGALRM: update_io_ticks(); disk_util_timer_arm(); + print_thread_status(); break; default: printf("\nfio: terminating on signal\n"); @@ -1212,6 +1214,7 @@ static int get_file_size(struct thread_data *td) return 1; } + td->total_io_size = td->io_size * td->loops; return 0; } @@ -1769,16 +1772,7 @@ static void show_thread_status(struct thread_data *td, printf(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, td->ctx); } -static void print_thread_status(int nr_running, int t_rate, int m_rate) -{ - printf("Threads now running: %d", nr_running); - if (m_rate || t_rate) - printf(", commitrate %d/%dKiB/sec", t_rate, m_rate); - printf(" : [%s]\r", run_str); - fflush(stdout); -} - -static void check_str_update(struct thread_data *td, int n, int t, int m) +static void check_str_update(struct thread_data *td) { char c = run_str[td->thread_number - 1]; @@ -1819,10 +1813,46 @@ static void check_str_update(struct thread_data *td, int n, int t, int m) } run_str[td->thread_number - 1] = c; - print_thread_status(n, t, m); td->old_runstate = td->runstate; } +static void print_thread_status(void) +{ + unsigned long long bytes_done, bytes_total; + int i, nr_running, t_rate, m_rate; + double perc; + + bytes_done = bytes_total = 0; + nr_running = t_rate = m_rate = 0; + for (i = 0; i < thread_number; i++) { + struct thread_data *td = &threads[i]; + + if (td->runstate == TD_RUNNING) { + nr_running++; + t_rate += td->rate; + m_rate += td->ratemin; + } + + bytes_total += td->total_io_size; + bytes_done += td->io_bytes; + + check_str_update(td); + } + + perc = 0; + if (bytes_total && bytes_done) { + perc = (double) 100 * bytes_done / (double) bytes_total; + if (perc > 100.0) + perc = 100.0; + } + + printf("Threads now running: %d", nr_running); + if (m_rate || t_rate) + printf(", commitrate %d/%dKiB/sec", t_rate, m_rate); + printf(" : [%s] [%3.2f%% done]\r", run_str, perc); + fflush(stdout); +} + static void reap_threads(int *nr_running, int *t_rate, int *m_rate) { int i; @@ -1833,8 +1863,6 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate) for (i = 0; i < thread_number; i++) { struct thread_data *td = &threads[i]; - check_str_update(td, *nr_running, *t_rate, *m_rate); - if (td->runstate != TD_EXITED) continue; @@ -1851,7 +1879,6 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate) (*nr_running)--; (*m_rate) -= td->ratemin; (*t_rate) -= td->rate; - check_str_update(td, *nr_running, *t_rate, *m_rate); } } @@ -1926,7 +1953,6 @@ static void run_threads(void) break; td_set_runstate(td, TD_CREATED); - check_str_update(td, nr_running, t_rate, m_rate); sem_init(&startup_sem, 0, 1); todo--; nr_started++; @@ -1960,20 +1986,9 @@ static void run_threads(void) nr_started--; m_rate += td->ratemin; t_rate += td->rate; - check_str_update(td, nr_running, t_rate, m_rate); sem_post(&td->mutex); } - for (i = 0; i < thread_number; i++) { - td = &threads[i]; - - if (td->runstate != TD_RUNNING && - td->runstate != TD_VERIFYING) - continue; - - check_str_update(td, nr_running, t_rate, m_rate); - } - reap_threads(&nr_running, &t_rate, &m_rate); if (todo) diff --git a/fio.h b/fio.h index 6fad449..2853c4f 100644 --- a/fio.h +++ b/fio.h @@ -170,6 +170,7 @@ struct thread_data { unsigned long runtime; /* sec */ unsigned long long io_size; + unsigned long long total_io_size; unsigned long io_blocks; unsigned long io_bytes; -- 2.25.1