From: Vincent Fu Date: Mon, 2 Oct 2023 13:41:54 +0000 (-0700) Subject: iolog: don't truncate time values X-Git-Tag: fio-3.36~6 X-Git-Url: https://git.kernel.dk/?a=commitdiff_plain;h=6f9cdcfcc7598c7d7b19c4a5120a251a80dab183;p=fio.git iolog: don't truncate time values 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 --- diff --git a/iolog.c b/iolog.c index 97ba4396..5213c60f 100644 --- 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,