iolog: don't truncate time values
authorVincent Fu <vincent.fu@samsung.com>
Mon, 2 Oct 2023 13:41:54 +0000 (06:41 -0700)
committerVincent Fu <vincent.fu@samsung.com>
Mon, 2 Oct 2023 14:29:29 +0000 (14:29 +0000)
We store iolog timestamps as 64-bit unsigned integers but when we print
timestamps in the logs we type cast them to unsigned longs. This is fine
on platforms with 64-bit longs but on platforms like Windows with 32-bit
longs this truncates the timestamps. Truncation causes problems
especially when options such as --log_unix_epoch are enabled because the
number of milliseconds since 01-01-1970 does not fit in a 32-bit
unsigned long.

Fix this by getting rid of the type cast and using PRIu64 as the format
specifier.

Fixes: https://github.com/axboe/fio/issues/1638
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
iolog.c

diff --git a/iolog.c b/iolog.c
index 97ba43967f1cd96cb7c33d87d13f4fe75f2cc1d8..5213c60f1a984570a5ee2fe2eceda1f605ed6853 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -1002,14 +1002,14 @@ void flush_samples(FILE *f, void *samples, uint64_t sample_size)
 
        if (log_offset) {
                if (log_prio)
-                       fmt = "%lu, %" PRId64 ", %u, %llu, %llu, 0x%04x\n";
+                       fmt = "%" PRIu64 ", %" PRId64 ", %u, %llu, %llu, 0x%04x\n";
                else
-                       fmt = "%lu, %" PRId64 ", %u, %llu, %llu, %u\n";
+                       fmt = "%" PRIu64 ", %" PRId64 ", %u, %llu, %llu, %u\n";
        } else {
                if (log_prio)
-                       fmt = "%lu, %" PRId64 ", %u, %llu, 0x%04x\n";
+                       fmt = "%" PRIu64 ", %" PRId64 ", %u, %llu, 0x%04x\n";
                else
-                       fmt = "%lu, %" PRId64 ", %u, %llu, %u\n";
+                       fmt = "%" PRIu64 ", %" PRId64 ", %u, %llu, %u\n";
        }
 
        nr_samples = sample_size / __log_entry_sz(log_offset);
@@ -1024,7 +1024,7 @@ void flush_samples(FILE *f, void *samples, uint64_t sample_size)
 
                if (!log_offset) {
                        fprintf(f, fmt,
-                               (unsigned long) s->time,
+                               s->time,
                                s->data.val,
                                io_sample_ddir(s), (unsigned long long) s->bs,
                                prio_val);
@@ -1032,7 +1032,7 @@ void flush_samples(FILE *f, void *samples, uint64_t sample_size)
                        struct io_sample_offset *so = (void *) s;
 
                        fprintf(f, fmt,
-                               (unsigned long) s->time,
+                               s->time,
                                s->data.val,
                                io_sample_ddir(s), (unsigned long long) s->bs,
                                (unsigned long long) so->offset,