Add timestamp to json output
authorSteve ODriscoll <sodriscoll@nexgenstorage.com>
Tue, 6 Jan 2015 19:00:27 +0000 (12:00 -0700)
committerJens Axboe <axboe@fb.com>
Tue, 6 Jan 2015 19:00:27 +0000 (12:00 -0700)
Modified by Jens to add humanly readable time as well.

Signed-off-by: Jens Axboe <axboe@fb.com>
stat.c

diff --git a/stat.c b/stat.c
index bae33385a23c61fa61c8815c0dcd679c8fdab8a8..3f51f0cefd18a2695bb3df4bac8b90e872e4cf08 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1189,7 +1189,6 @@ void __show_run_stats(void)
        int unit_base_warned = 0;
        struct json_object *root = NULL;
        struct json_array *array = NULL;
-
        runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
 
        for (i = 0; i < groupid + 1; i++)
@@ -1351,8 +1350,18 @@ void __show_run_stats(void)
        if (output_format == FIO_OUTPUT_NORMAL)
                log_info("\n");
        else if (output_format == FIO_OUTPUT_JSON) {
+               char time_buf[64];
+               time_t time_p;
+
+               time(&time_p);
+               os_ctime_r((const time_t *) &time_p, time_buf,
+                               sizeof(time_buf));
+               time_buf[strlen(time_buf) - 1] = '\0';
+
                root = json_create_object();
                json_object_add_value_string(root, "fio version", fio_version_string);
+               json_object_add_value_int(root, "timestamp", time_p);
+               json_object_add_value_string(root, "time", time_buf);
                array = json_create_array();
                json_object_add_value_array(root, "jobs", array);
        }