Merge branch 'epoch' of https://github.com/cronburg/fio
authorJens Axboe <axboe@fb.com>
Thu, 18 Aug 2016 20:38:21 +0000 (14:38 -0600)
committerJens Axboe <axboe@fb.com>
Thu, 18 Aug 2016 20:38:21 +0000 (14:38 -0600)
12 files changed:
HOWTO
backend.c
cconv.c
fio.1
fio.h
fio_time.h
libfio.c
options.c
rate-submit.c
stat.c
thread_options.h
time.c

diff --git a/HOWTO b/HOWTO
index c1b768d2841d131073e271930c085f5a6a321e60..07419a12054ed43b991e3300db29a07ca4efbec5 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -1681,6 +1681,10 @@ log_store_compressed=bool        If set, fio will store the log files in a
                the --inflate-log command line parameter. The files will be
                stored with a .fz suffix.
 
+log_unix_epoch=bool    If set, fio will log Unix timestamps to the log
+               files produced by enabling write_type_log for each log type, instead
+               of the default zero-based timestamps.
+
 block_error_percentiles=bool   If set, record errors in trim block-sized
                units from writes and trims and output a histogram of
                how many trims it took to get to errors, and what kind
index b43486dc7b2ff016b6d76d281dc479692e90b231..d98658606d772ed7d31b1355571ee2566b53a213 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1675,7 +1675,7 @@ static void *thread_main(void *data)
        if (rate_submit_init(td, sk_out))
                goto err;
 
-       fio_gettime(&td->epoch, NULL);
+       set_epoch_time(td, o->log_unix_epoch);
        fio_getrusage(&td->ru_start);
        memcpy(&td->bw_sample_time, &td->epoch, sizeof(td->epoch));
        memcpy(&td->iops_sample_time, &td->epoch, sizeof(td->epoch));
diff --git a/cconv.c b/cconv.c
index 8d9a0a8e00e9255bd01e097f39ce38ee28b4d50b..194e342c303f705a4b7f46a51cf504689490b08b 100644 (file)
--- a/cconv.c
+++ b/cconv.c
@@ -187,6 +187,7 @@ void convert_thread_options_to_cpu(struct thread_options *o,
        o->log_offset = le32_to_cpu(top->log_offset);
        o->log_gz = le32_to_cpu(top->log_gz);
        o->log_gz_store = le32_to_cpu(top->log_gz_store);
+       o->log_unix_epoch = le32_to_cpu(top->log_unix_epoch);
        o->norandommap = le32_to_cpu(top->norandommap);
        o->softrandommap = le32_to_cpu(top->softrandommap);
        o->bs_unaligned = le32_to_cpu(top->bs_unaligned);
@@ -379,6 +380,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top,
        top->log_offset = cpu_to_le32(o->log_offset);
        top->log_gz = cpu_to_le32(o->log_gz);
        top->log_gz_store = cpu_to_le32(o->log_gz_store);
+       top->log_unix_epoch = cpu_to_le32(o->log_unix_epoch);
        top->norandommap = cpu_to_le32(o->norandommap);
        top->softrandommap = cpu_to_le32(o->softrandommap);
        top->bs_unaligned = cpu_to_le32(o->bs_unaligned);
diff --git a/fio.1 b/fio.1
index 696664afb0818d40e7d6d217b7af60ee10fefd05..8d596fb19105df2e6b3aabcbda171cf462f3157e 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -1546,6 +1546,11 @@ If set, fio will store the log files in a compressed format. They can be
 decompressed with fio, using the \fB\-\-inflate-log\fR command line parameter.
 The files will be stored with a \fB\.fz\fR suffix.
 .TP
+.BI log_unix_epoch \fR=\fPbool
+If set, fio will log Unix timestamps to the log files produced by enabling
+\fBwrite_type_log\fR for each log type, instead of the default zero-based
+timestamps.
+.TP
 .BI block_error_percentiles \fR=\fPbool
 If set, record errors in trim block-sized units from writes and trims and output
 a histogram of how many trims it took to get to errors, and what kind of error
diff --git a/fio.h b/fio.h
index a62b15594d610285a155300979db0430a24960d3..df4fbb16da9d4ab7dec15870c3e6826d50c329dc 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -311,6 +311,7 @@ struct thread_data {
 
        struct timeval start;   /* start of this loop */
        struct timeval epoch;   /* time job was started */
+       unsigned long long unix_epoch; /* Time job was started, unix epoch based. */
        struct timeval last_issue;
        long time_offset;
        struct timeval tv_cache;
index e31ea0974da5d5168ba4db93b977cb0fd9624a63..b49cc828713e4c67d53e362372760cd510510353 100644 (file)
@@ -20,5 +20,6 @@ extern bool ramp_time_over(struct thread_data *);
 extern bool in_ramp_time(struct thread_data *);
 extern void fio_time_init(void);
 extern void timeval_add_msec(struct timeval *, unsigned int);
+extern void set_epoch_time(struct thread_data *, int);
 
 #endif
index fb7d35ae1ae5bb646f49dc6dc791bbbb74926cbe..d88ed4ed2032ecccfad5435b0de10abc42157973 100644 (file)
--- a/libfio.c
+++ b/libfio.c
@@ -134,7 +134,6 @@ void clear_io_state(struct thread_data *td, int all)
 
 void reset_all_stats(struct thread_data *td)
 {
-       struct timeval tv;
        int i;
 
        reset_io_counters(td, 1);
@@ -148,11 +147,10 @@ void reset_all_stats(struct thread_data *td)
                td->rwmix_issues = 0;
        }
 
-       fio_gettime(&tv, NULL);
-       memcpy(&td->epoch, &tv, sizeof(tv));
-       memcpy(&td->start, &tv, sizeof(tv));
-       memcpy(&td->iops_sample_time, &tv, sizeof(tv));
-       memcpy(&td->bw_sample_time, &tv, sizeof(tv));
+       set_epoch_time(td, td->o.log_unix_epoch);
+       memcpy(&td->start, &td->epoch, sizeof(struct timeval));
+       memcpy(&td->iops_sample_time, &td->epoch, sizeof(struct timeval));
+       memcpy(&td->bw_sample_time, &td->epoch, sizeof(struct timeval));
 
        lat_target_reset(td);
        clear_rusage_stat(td);
index 517ee68abc4d6b017860760173996f27825ec081..50b4d09ec8ba66b1826602b24ea693b68103efaa 100644 (file)
--- a/options.c
+++ b/options.c
@@ -3647,6 +3647,15 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .help   = "Install libz-dev(el) to get compression support",
        },
 #endif
+       {
+               .name = "log_unix_epoch",
+               .lname = "Log epoch unix",
+               .type = FIO_OPT_BOOL,
+               .off1 = offsetof(struct thread_options, log_unix_epoch),
+               .help = "Use Unix time in log files",
+               .category = FIO_OPT_C_LOG,
+               .group = FIO_OPT_G_INVALID,
+       },
        {
                .name   = "block_error_percentiles",
                .lname  = "Block error percentiles",
index 2efbdcba610902dd2c344c45f8a980dbd15c819e..42927ffeaf4125dcefccc8fe964d2bc448197fea 100644 (file)
@@ -123,7 +123,7 @@ static int io_workqueue_init_worker_fn(struct submit_worker *sw)
        if (td_io_init(td))
                goto err_io_init;
 
-       fio_gettime(&td->epoch, NULL);
+       set_epoch_time(td, td->o.log_unix_epoch);
        fio_getrusage(&td->ru_start);
        clear_io_state(td, 1);
 
diff --git a/stat.c b/stat.c
index 5e7c593fc050dcc12420685bffa2855bda0a0b77..552d88dde06797c9098820da224cd0891aab268e 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -2020,7 +2020,7 @@ static void __add_log_sample(struct io_log *iolog, unsigned long val,
                s = get_sample(iolog, cur_log, cur_log->nr_samples);
 
                s->val = val;
-               s->time = t;
+               s->time = t + iolog->td->unix_epoch;
                io_sample_set_ddir(iolog, s, ddir);
                s->bs = bs;
 
index d70fda3f949145ff99dec4026a9e6b137f0f078e..1b4590f751f0c72a7345ee730a52ac6bde360fa3 100644 (file)
@@ -135,6 +135,7 @@ struct thread_options {
        unsigned int log_offset;
        unsigned int log_gz;
        unsigned int log_gz_store;
+       unsigned int log_unix_epoch;
        unsigned int norandommap;
        unsigned int softrandommap;
        unsigned int bs_unaligned;
@@ -393,11 +394,13 @@ struct thread_options_pack {
        uint32_t log_offset;
        uint32_t log_gz;
        uint32_t log_gz_store;
+       uint32_t log_unix_epoch;
        uint32_t norandommap;
        uint32_t softrandommap;
        uint32_t bs_unaligned;
        uint32_t fsync_on_close;
        uint32_t bs_is_seq_rand;
+       uint32_t pad1;
 
        uint32_t random_distribution;
        uint32_t exitall_error;
diff --git a/time.c b/time.c
index f1c5d3fe613e85c4ce0713701aee5c45afdcabdd..f5dc04969f3d47020fb4f61fa3ddf5dcfcdf0e09 100644 (file)
--- a/time.c
+++ b/time.c
@@ -151,6 +151,17 @@ void set_genesis_time(void)
        fio_gettime(&genesis, NULL);
 }
 
+void set_epoch_time(struct thread_data *td, int log_unix_epoch)
+{
+       fio_gettime(&td->epoch, NULL);
+       if (log_unix_epoch) {
+               struct timeval tv;
+               gettimeofday(&tv, NULL);
+               td->unix_epoch = (unsigned long long)(tv.tv_sec) * 1000 +
+                                (unsigned long long)(tv.tv_usec) / 1000;
+       }
+}
+
 void fill_start_time(struct timeval *t)
 {
        memcpy(t, &genesis, sizeof(genesis));