[PATCH] fio: stats update, make it work for loops and verifies
authorJens Axboe <axboe@suse.de>
Wed, 9 Nov 2005 10:16:59 +0000 (11:16 +0100)
committerJens Axboe <axboe@suse.de>
Wed, 9 Nov 2005 10:16:59 +0000 (11:16 +0100)
fio.c

diff --git a/fio.c b/fio.c
index 39e84e261b88ac33197a0358cf750c17afdc4d92..17db50744d498ebd6a6d15742ed11e76c51d39d6 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -286,8 +286,12 @@ struct thread_data {
        struct io_log *bw_log;
 
        struct timeval start;
+
        struct rusage ru_start;
        struct rusage ru_end;
+       unsigned long usr_time;
+       unsigned long sys_time;
+       unsigned long ctx;
 
        struct list_head io_hist_list;
 };
@@ -1584,6 +1588,21 @@ static void clear_io_state(struct thread_data *td)
                memset(td->file_map, 0, td->num_maps * sizeof(long));
 }
 
+static void update_rusage_stat(struct thread_data *td)
+{
+       if (!td->runtime)
+               return;
+
+       getrusage(RUSAGE_SELF, &td->ru_end);
+
+       td->usr_time += mtime_since(&td->ru_start.ru_utime, &td->ru_end.ru_utime);
+       td->sys_time += mtime_since(&td->ru_start.ru_stime, &td->ru_end.ru_stime);
+       td->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw);
+
+       
+       memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end));
+}
+
 static void *thread_main(int shm_id, int offset, char *argv[])
 {
        struct thread_data *td;
@@ -1630,12 +1649,10 @@ static void *thread_main(int shm_id, int offset, char *argv[])
        if (init_random_state(td))
                goto err;
 
-       gettimeofday(&td->start, NULL);
-
-       getrusage(RUSAGE_SELF, &td->ru_start);
-
        while (td->loops--) {
-               gettimeofday(&td->stat_sample_time, NULL);
+               getrusage(RUSAGE_SELF, &td->ru_start);
+               gettimeofday(&td->start, NULL);
+               memcpy(&td->stat_sample_time, &td->start, sizeof(td->start));
 
                if (td->ratemin)
                        memcpy(&td->lastrate, &td->stat_sample_time, sizeof(td->lastrate));
@@ -1651,6 +1668,9 @@ static void *thread_main(int shm_id, int offset, char *argv[])
                if (td->error)
                        break;
 
+               td->runtime += mtime_since_now(&td->start);
+               update_rusage_stat(td);
+
                if (!td->verify)
                        continue;
 
@@ -1665,8 +1685,6 @@ static void *thread_main(int shm_id, int offset, char *argv[])
                        break;
        }
 
-       td->runtime = mtime_since_now(&td->start);
-       getrusage(RUSAGE_SELF, &td->ru_end);
        ret = 0;
 
        if (td->bw_log)
@@ -1725,7 +1743,7 @@ static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
 static void show_thread_status(struct thread_data *td)
 {
        int prio, prio_class;
-       unsigned long min, max, bw = 0, ctx;
+       unsigned long min, max, bw = 0;
        double mean, dev, usr_cpu, sys_cpu;
 
        if (!td->io_bytes && !td->error)
@@ -1737,7 +1755,7 @@ static void show_thread_status(struct thread_data *td)
        prio = td->ioprio & 0xff;
        prio_class = td->ioprio >> IOPRIO_CLASS_SHIFT;
 
-       printf("Client%d: err=%2d, io=%6luMiB, bw=%6luKiB/s, runt=%6lumsec\n", td->thread_number, td->error, td->io_bytes >> 20, bw, td->runtime);
+       printf("Client%d (g=%d): err=%2d, io=%6luMiB, bw=%6luKiB/s, runt=%6lumsec\n", td->thread_number, td->groupid, td->error, td->io_bytes >> 20, bw, td->runtime);
 
        if (calc_lat(&td->slat_stat, &min, &max, &mean, &dev))
                printf("  slat (msec): min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
@@ -1747,21 +1765,14 @@ static void show_thread_status(struct thread_data *td)
                printf("  bw (KiB/s) : min=%5lu, max=%5lu, avg=%5.02f, dev=%5.02f\n", min, max, mean, dev);
 
        if (td->runtime) {
-               unsigned long t;
-
-               t = mtime_since(&td->ru_start.ru_utime, &td->ru_end.ru_utime);
-               usr_cpu = (double) t * 100 / (double) td->runtime;
-
-               t = mtime_since(&td->ru_start.ru_stime, &td->ru_end.ru_stime);
-               sys_cpu = (double) t * 100 / (double) td->runtime;
+               usr_cpu = (double) td->usr_time * 100 / (double) td->runtime;
+               sys_cpu = (double) td->sys_time * 100 / (double) td->runtime;
        } else {
                usr_cpu = 0;
                sys_cpu = 0;
        }
 
-       ctx = td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw);
-
-       printf("  cpu        : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, ctx);
+       printf("  cpu        : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu\n", usr_cpu, sys_cpu, td->ctx);
 }
 
 static int setup_rate(struct thread_data *td)
@@ -1881,7 +1892,7 @@ static int add_job(struct thread_data *td, const char *jobname, int prioclass,
        if (write_bw_log)
                setup_log(&td->bw_log);
 
-       printf("Client%d: rw=%d, prio=%d/%d, seq=%d, odir=%d, bs=%d-%d, rate=%d, aio=%d, aio_depth=%d\n", td->thread_number, td->ddir, prioclass, prio, td->sequential, td->odirect, td->min_bs, td->max_bs, td->rate, td->use_aio, td->aio_depth);
+       printf("Client%d (g=%d): rw=%d, prio=%d/%d, seq=%d, odir=%d, bs=%d-%d, rate=%d, aio=%d, aio_depth=%d\n", td->thread_number, td->groupid, td->ddir, prioclass, prio, td->sequential, td->odirect, td->min_bs, td->max_bs, td->rate, td->use_aio, td->aio_depth);
 
        /*
         * recurse add identical jobs, clear numjobs and stonewall options
@@ -2601,10 +2612,9 @@ static void show_run_stats(void)
        for (i = 0; i < groupid + 1; i++) {
                rs = &runstats[i];
 
+               memset(rs, 0, sizeof(*rs));
                rs->min_bw[0] = rs->min_run[0] = ~0UL;
                rs->min_bw[1] = rs->min_run[1] = ~0UL;
-               rs->io_mb[0] = rs->io_mb[1] = 0;
-               rs->agg[0] = rs->agg[1] = 0;
        }
 
        for (i = 0; i < thread_number; i++) {