Skip to content

Commit

Permalink
iolog: don't truncate time values
Browse files Browse the repository at this point in the history
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: #1638
Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
  • Loading branch information
vincentkfu committed Oct 2, 2023
1 parent c95b52c commit 6f9cdcf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions iolog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -1024,15 +1024,15 @@ 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);
} else {
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,
Expand Down

0 comments on commit 6f9cdcf

Please sign in to comment.