From 91e538700d0a38f25f3f339b1f8d176a5be4b2ef Mon Sep 17 00:00:00 2001 From: Steve ODriscoll Date: Tue, 6 Jan 2015 12:00:27 -0700 Subject: [PATCH] Add timestamp to json output Modified by Jens to add humanly readable time as well. Signed-off-by: Jens Axboe --- stat.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/stat.c b/stat.c index bae33385..3f51f0ce 100644 --- 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); } -- 2.25.1