diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c index abdb35764de..a64d1cb5708 100644 --- a/src/bin/pg_upgrade/util.c +++ b/src/bin/pg_upgrade/util.c @@ -14,9 +14,13 @@ #include "common/username.h" #include "lib/stringinfo.h" #include "pg_upgrade.h" +#include "portability/instr_time.h" LogOpts log_opts; +/* start time of the stage most recently announced by prep_status*() */ +static instr_time stage_start; + static void pg_log_v(eLogType type, const char *fmt, va_list ap) pg_attribute_printf(2, 0); @@ -138,6 +142,8 @@ prep_status(const char *fmt, ...) /* trim strings */ pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message); + + INSTR_TIME_SET_CURRENT(stage_start); } /* @@ -171,6 +177,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); + + INSTR_TIME_SET_CURRENT(stage_start); } static void @@ -302,8 +310,39 @@ pg_fatal(const char *fmt, ...) void check_ok(void) { - /* all seems well */ - report_status(PG_REPORT, "ok"); + instr_time duration; + uint64 ms; + int days; + int hours; + int mins; + int secs; + int msecs; + + INSTR_TIME_SET_CURRENT(duration); + INSTR_TIME_SUBTRACT(duration, stage_start); + ms = (uint64) INSTR_TIME_GET_MILLISEC(duration); + + msecs = ms % 1000; + ms /= 1000; + secs = ms % 60; + ms /= 60; + mins = ms % 60; + ms /= 60; + hours = ms % 24; + days = ms / 24; + + /* All seems well. Print time taken, omitting leading zero units */ + if (days > 0) + report_status(PG_REPORT, "ok (%dd %dh %dm %d.%03ds)", + days, hours, mins, secs, msecs); + else if (hours > 0) + report_status(PG_REPORT, "ok (%dh %dm %d.%03ds)", + hours, mins, secs, msecs); + else if (mins > 0) + report_status(PG_REPORT, "ok (%dm %d.%03ds)", + mins, secs, msecs); + else + report_status(PG_REPORT, "ok (%d.%03ds)", secs, msecs); }