[PATCH] fio: cleanup thread print status and add progress percentage
authorJens Axboe <axboe@suse.de>
Wed, 7 Dec 2005 11:05:36 +0000 (12:05 +0100)
committerJens Axboe <axboe@suse.de>
Wed, 7 Dec 2005 11:05:36 +0000 (12:05 +0100)
fio.c
fio.h

diff --git a/fio.c b/fio.c
index 1ed7b489369b9f8e675ab001e0518687598d7f4f..1a9f052b02b5aaf06f740af7694f85002b116b8c 100644 (file)
--- 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 6fad44966be16dec860503f8f5cda8a9d44c4211..2853c4fcd2d26959b906809ba865c9a44f6c784e 100644 (file)
--- 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;