v1-0002-pg_test_timing-use-int64-for-largest-observed-tim.patch

application/octet-stream

Filename: v1-0002-pg_test_timing-use-int64-for-largest-observed-tim.patch
Type: application/octet-stream
Part: 1
Message: pg_test_timing: fix unit typo and widen diff type

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v1-0002
Subject: pg_test_timing: use int64 for largest observed time delta
File+
src/bin/pg_test_timing/pg_test_timing.c 5 5
From e29ff7fef693e830b4929f9b7444cc943fd16516 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Thu, 2 Apr 2026 10:29:06 +0800
Subject: [PATCH v1 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 <lic@highgo.com>
Reviewed-by:
Discussion: https://postgr.es/m/
---
 src/bin/pg_test_timing/pg_test_timing.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/bin/pg_test_timing/pg_test_timing.c b/src/bin/pg_test_timing/pg_test_timing.c
index cbdc5af09d9..07b98a6388d 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;
 
 
@@ -176,8 +176,8 @@ test_timing(unsigned int duration)
 
 	while (INSTR_TIME_GT(end_time, cur))
 	{
-		int32		diff,
-					bits;
+		int64		diff;
+		int32		bits;
 		instr_time	diff_time;
 
 		prev = cur;
@@ -191,7 +191,7 @@ test_timing(unsigned int duration)
 		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: %lld ns\n"), diff);
 			exit(1);
 		}
 
@@ -319,7 +319,7 @@ output(uint64 loop_count)
 		double		prct = (double) largest_diff_count * 100 / loop_count;
 
 		printf("...\n");
-		printf("%*d   %*.4f %*.4f %*lld\n",
+		printf("%*lld   %*.4f %*.4f %*lld\n",
 			   len1, largest_diff,
 			   len2, prct,
 			   len3, 100.0,
-- 
2.50.1 (Apple Git-155)