From: Ryan Hardin Date: Thu, 26 May 2016 20:39:41 +0000 (-0400) Subject: Added millisecond-accurate timestamp to JSON output X-Git-Tag: fio-2.12~17 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=aa7d2ef092d5a8e417fcddaf8808fb0d48f1064b Added millisecond-accurate timestamp to JSON output Kept original value for backward compatibility. --- diff --git a/stat.c b/stat.c index fc1efd40..53848843 100644 --- a/stat.c +++ b/stat.c @@ -1636,16 +1636,21 @@ void __show_run_stats(void) if (output_format & FIO_OUTPUT_JSON) { struct thread_data *global; char time_buf[32]; - time_t time_p; + struct timeval now; + unsigned long long ms_since_epoch; - time(&time_p); - os_ctime_r((const time_t *) &time_p, time_buf, + gettimeofday(&now, NULL); + ms_since_epoch = (unsigned long long)(now.tv_sec) * 1000 + + (unsigned long long)(now.tv_usec) / 1000; + + os_ctime_r((const time_t *) &now.tv_sec, 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_int(root, "timestamp", now.tv_sec); + json_object_add_value_int(root, "timestamp_ms", ms_since_epoch); json_object_add_value_string(root, "time", time_buf); global = get_global_options(); json_add_job_opts(root, "global options", &global->opt_list, false);