Subject: [PATCH v1 1/1] add timing information to pg_upgrade

From: Nathan Bossart <[email-masked]>
Date: Thu, 27 Jul 2023 16:16:45 -0700

---
 src/bin/pg_upgrade/util.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c
index 21ba4c8f12..d1b506a741 100644
--- a/src/bin/pg_upgrade/util.c
+++ b/src/bin/pg_upgrade/util.c
@@ -16,6 +16,8 @@
 
 LogOpts		log_opts;
 
+static struct timeval step_start;
+
 static void pg_log_v(eLogType type, const char *fmt, va_list ap) pg_attribute_printf(2, 0);

@@ -137,6 +139,8 @@ prep_status(const char *fmt,...)
 
 	/* trim strings */
 	pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message);
+
+	gettimeofday(&step_start, NULL);
 }
 
 /*
@@ -170,6 +174,8 @@ prep_status_progress(const char *fmt,...)
 		pg_log(PG_REPORT, "%-*s", MESSAGE_WIDTH, message);
 	else
 		pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message);
+
+	gettimeofday(&step_start, NULL);
 }
 
 static void
@@ -283,8 +289,19 @@ pg_fatal(const char *fmt,...)
 void
 check_ok(void)
 {
+	struct timeval step_end;
+	int64		elapsed_ms;
+	int64		start_ms;
+	int64		end_ms;
+
+	gettimeofday(&step_end, NULL);
+
+	start_ms = (step_start.tv_sec * 1000L) + (step_start.tv_usec / 1000L);
+	end_ms = (step_end.tv_sec * 1000L) + (step_end.tv_usec / 1000L);
+	elapsed_ms = end_ms - start_ms;
+
 	/* all seems well */
-	report_status(PG_REPORT, "ok");
+	report_status(PG_REPORT, "ok (took %ld ms)", elapsed_ms);
 }

-- 
2.25.1

--gBBFr7Ir9EOA20Yy--