[PATCH] fio: Add bandwidth average and deviation
authorJens Axboe <axboe@suse.de>
Fri, 21 Oct 2005 16:52:14 +0000 (18:52 +0200)
committerJens Axboe <axboe@suse.de>
Fri, 21 Oct 2005 16:52:14 +0000 (18:52 +0200)
Needs some fixing up to pretty the output, but at least it is there now.

fio.c

diff --git a/fio.c b/fio.c
index 6245209a8189168f0cd995bf7e2afc2f2a1b8dd1..af496b12ab5055a330a9abcb9aba13a183f53a94 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -169,7 +169,12 @@ struct thread_data {
         */
        unsigned long stat_time;
        unsigned long stat_time_sq;
-       unsigned long stat_samples;
+       unsigned long stat_time_samples;
+       unsigned long stat_io_blocks;
+       unsigned long stat_bw;
+       unsigned long stat_bw_sq;
+       unsigned long stat_bw_samples;
+       struct timeval stat_sample_time;
 
        struct timeval start;
 };
@@ -283,9 +288,22 @@ static unsigned long get_next_offset(struct thread_data *td)
 
 static void add_stat_sample(struct thread_data *td, unsigned long msec)
 {
+       unsigned long spent;
+
        td->stat_time += msec;
        td->stat_time_sq += msec * msec;
-       td->stat_samples++;
+       td->stat_time_samples++;
+
+       spent = mtime_since_now(&td->stat_sample_time);
+       if (spent >= 500) {
+               unsigned long rate = ((td->io_blocks - td->stat_io_blocks) * td->bs) / spent;
+
+               td->stat_bw += rate;
+               td->stat_bw_sq += rate * rate;
+               gettimeofday(&td->stat_sample_time, NULL);
+               td->stat_io_blocks = td->io_blocks;
+               td->stat_bw_samples++;
+       }
 }
 
 static void usec_sleep(int usec)
@@ -710,6 +728,8 @@ static void *thread_main(int shm_id, int offset, char *argv[])
        if (td->ratemin)
                memcpy(&td->lastrate, &td->start, sizeof(td->start));
 
+       memcpy(&td->stat_sample_time, &td->start, sizeof(td->start));
+
        if (!td->use_aio) {
                ptr = malloc(td->bs + MASK);
                td->buf = ALIGN(ptr);
@@ -749,7 +769,7 @@ static void show_thread_status(struct thread_data *td)
 {
        int prio, prio_class;
        unsigned long bw = 0;
-       double nr, mean, dev;
+       double n_lat, n_bw, m_lat, m_bw, dev_lat, dev_bw;
 
        if (!td->io_blocks && !td->error)
                return;
@@ -760,11 +780,15 @@ static void show_thread_status(struct thread_data *td)
        prio = td->ioprio & 0xff;
        prio_class = td->ioprio >> IOPRIO_CLASS_SHIFT;
 
-       nr = (double) td->stat_samples;
-       mean = (double) td->stat_time / nr;
-       dev = sqrt(((double) td->stat_time_sq - (mean * mean) / nr) / (nr - 1));
+       n_lat = (double) td->stat_time_samples;
+       n_bw = (double) td->stat_bw_samples;
+
+       m_lat = (double) td->stat_time / n_lat;
+       dev_lat = sqrt(((double) td->stat_time_sq - (m_lat * m_lat) / n_lat) / (n_lat - 1));
+       m_bw = (double) td->stat_bw / n_bw;
+       dev_bw = sqrt(((double) td->stat_bw_sq - (m_bw * m_bw) / n_bw) / (n_bw - 1));
 
-       printf("Client%d: err=%2d, io=%6luMiB, bw=%6luKiB/sec, latmax=%5lu, latavg=%5.02f, latdev=%5.02f\n", td->thread_number, td->error, td->io_blocks * td->bs >> 20, bw, td->max_latency, mean, dev);
+       printf("Client%d: err=%2d, io=%6luMiB, bw=%6luKiB/sec, latmax=%5lu, latavg=%5.02f, latdev=%5.02f, m_bw=%5.02f, m_dev=%5.02f\n", td->thread_number, td->error, td->io_blocks * td->bs >> 20, bw, td->max_latency, m_lat, dev_lat, m_bw, dev_bw);
 }
 
 static int setup_rate(struct thread_data *td)