From e193672cc7cd5736290af81a1ce8acd2f4237224 Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Thu, 2 Apr 2026 10:29:06 +0800 Subject: [PATCH v3 2/2] pg_test_timing: use int64 for largest observed time delta pg_test_timing obtains timing deltas with INSTR_TIME_GET_NANOSEC(), which returns a nanosecond value that should be stored in int64. Adjust diff and largest_diff to use int64 accordingly. Also fix the corresponding printf format specifiers so these values are printed correctly. Author: Chao Li Reviewed-by: Lukas Fittl Discussion: https://postgr.es/m/F780CEEB-A237-4302-9F55-60E9D8B6533D@gmail.com --- src/bin/pg_test_timing/pg_test_timing.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bin/pg_test_timing/pg_test_timing.c b/src/bin/pg_test_timing/pg_test_timing.c index 944b25df1f2..ce4c54256e3 100644 --- a/src/bin/pg_test_timing/pg_test_timing.c +++ b/src/bin/pg_test_timing/pg_test_timing.c @@ -25,7 +25,7 @@ static long long int histogram[32]; static long long int direct_histogram[NUM_DIRECT]; /* separately record highest observed duration */ -static int32 largest_diff; +static int64 largest_diff; static long long int largest_diff_count; @@ -262,8 +262,8 @@ test_timing(unsigned int duration, TimingClockSourceType source, bool fast_timin while (INSTR_TIME_GT(end_time, cur)) { - int32 diff, - bits; + int64 diff; + int32 bits; instr_time diff_time; prev = cur; @@ -281,13 +281,13 @@ test_timing(unsigned int duration, TimingClockSourceType source, bool fast_timin if (unlikely(diff < 0)) { fprintf(stderr, _("Detected clock going backwards in time.\n")); - fprintf(stderr, _("Time warp: %d ns\n"), diff); + fprintf(stderr, _("Time warp: " INT64_FORMAT " ns\n"), diff); exit(1); } /* What is the highest bit in the time diff? */ if (diff > 0) - bits = pg_leftmost_one_pos32(diff) + 1; + bits = pg_leftmost_one_pos64(diff) + 1; else bits = 0; @@ -409,8 +409,8 @@ output(uint64 loop_count) double prct = (double) largest_diff_count * 100 / loop_count; printf("...\n"); - printf("%*d %*.4f %*.4f %*lld\n", - len1, largest_diff, + printf("%*lld %*.4f %*.4f %*lld\n", + len1, (long long) largest_diff, len2, prct, len3, 100.0, len4, largest_diff_count); -- 2.50.1 (Apple Git-155)