Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qPSVB-00B5B5-JH for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jul 2023 18:47:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qPSV9-000Njb-UZ for pgsql-hackers@arkaria.postgresql.org; Fri, 28 Jul 2023 18:47:47 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qPSV9-000NjT-LK for pgsql-hackers@lists.postgresql.org; Fri, 28 Jul 2023 18:47:47 +0000 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qPSV2-000vij-OC for pgsql-hackers@postgresql.org; Fri, 28 Jul 2023 18:47:47 +0000 Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bbc7b2133fso15639245ad.1 for ; Fri, 28 Jul 2023 11:47:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690570058; x=1691174858; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=H7JcrrR1G3YP+s6BYIL+cGJwhWBgKPFINYQEqmnG5wE=; b=nqBFSUwMdWG/Bdq8ajDI0UrZyH4KRhLPEYQ0hc/q4XgqbM5i4YuKLlpNbRxm7SnWhM dLCKgwTzNhAi6t20Tf+NEaFeqEOidcyDoedfLIwRZaBfLks7piaCG3+gg+GW2NUV916D dT8Setnp4PZ7W51fq3LlaJpgX4vqc2ix2A6GcG4pIgkrCNCJISmh4rlWlyLTtHRlIVPA qHVQw3RRF5z2njuNQoPASNaNVx57XhHZ3pqpbfsyyne5Oodc7Uz7XQuctKvgRwHyOJZI rzvQ3+0ZMjr0bfTEVQr0FGujqSlubhu0QrPehGBxcIYaMRL87FBL1d904yZ8BelIUrzq QfCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690570058; x=1691174858; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=H7JcrrR1G3YP+s6BYIL+cGJwhWBgKPFINYQEqmnG5wE=; b=fm9Yg8/HgHv51bpc7DqLEu8X1GW6dFOvoDr9Ex5GUCKAtEQt/YA19TiZVS4Cy7lUHA jmvpSlPPI27yC9GGTGCfYvw4FfM/meS65BXExVaT0H0VFGGlCHtLk7ZN1syrqE+kXGQf H+4m3ehCLY7f1z4k8kaWB29y0exOAaIP2xN6qFqnLPUum7XCw2Dmxmf+HWtrj0Qqh+mR hdkSjmDQOW0u9pMDdtQ/ECNZKkq2emMBvnyrIht/NxAmZTarKOyywEpHUkqi017E+nEq 1Bfnp0wdicgHqh5CApgOByXN9igCy2lBRfrYSYlXwzMazOIjNM0efI9ojPXBUotFatkj H8uw== X-Gm-Message-State: ABy/qLbrQQ+WWtW/lKcioSzN5dlRCerwLxZd5jxz1HK0TePBXcKEToNh goUt6Xh3Ci+OEh3jUoxqNwg= X-Google-Smtp-Source: APBJJlHT8LYwGKScaJLz2/+i7aBLKGFne3GOBMXZTIxc9zVwzpfbIYhsJCabyfo0NExZ3cD0UfAbdQ== X-Received: by 2002:a17:902:e543:b0:1bb:8725:f537 with SMTP id n3-20020a170902e54300b001bb8725f537mr2638932plf.66.1690570058215; Fri, 28 Jul 2023 11:47:38 -0700 (PDT) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id ij22-20020a170902ab5600b001bb0b1a93dfsm3965521plb.126.2023.07.28.11.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Jul 2023 11:47:37 -0700 (PDT) Date: Fri, 28 Jul 2023 11:47:35 -0700 From: Nathan Bossart To: Bharath Rupireddy Cc: PostgreSQL-development Subject: Re: add timing information to pg_upgrade Message-ID: <20230728184735.GC3661419@nathanxps13> References: <20230727235134.GA3658499@nathanxps13> <20230728173814.GA3765390@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="vtzGhvizbBRQ85DL" Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230728173814.GA3765390@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --vtzGhvizbBRQ85DL Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit On Fri, Jul 28, 2023 at 10:38:14AM -0700, Nathan Bossart wrote: > I'm okay with simply adding the time. However, I wonder if we want to > switch to seconds, minutes, hours, etc. if the step takes longer. This > would add a bit of complexity, but it would improve human readability. > Alternatively, we could keep the code simple and machine readable by always > using milliseconds. ... or maybe we show both like psql does. Attached іs a new version of the patch in which I've made use of the INSTR_TIME_* macros and enhanced the output formatting (largely borrowed from PrintTiming() in src/bin/psql/common.c). -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --vtzGhvizbBRQ85DL Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-add-timing-information-to-pg_upgrade.patch" From 6a4b836b33c3e18a57438044a10da95ec89dcb65 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Thu, 27 Jul 2023 16:16:45 -0700 Subject: [PATCH v2 1/1] add timing information to pg_upgrade --- src/bin/pg_upgrade/util.c | 55 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_upgrade/util.c b/src/bin/pg_upgrade/util.c index 21ba4c8f12..25e43a593a 100644 --- a/src/bin/pg_upgrade/util.c +++ b/src/bin/pg_upgrade/util.c @@ -9,14 +9,19 @@ #include "postgres_fe.h" +#include #include #include "common/username.h" #include "pg_upgrade.h" +#include "portability/instr_time.h" LogOpts log_opts; +static instr_time step_start; + static void pg_log_v(eLogType type, const char *fmt, va_list ap) pg_attribute_printf(2, 0); +static char *get_time_str(double time_ms); /* @@ -137,6 +142,8 @@ prep_status(const char *fmt,...) /* trim strings */ pg_log(PG_REPORT_NONL, "%-*s", MESSAGE_WIDTH, message); + + INSTR_TIME_SET_CURRENT(step_start); } /* @@ -170,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(step_start); } static void @@ -280,11 +289,55 @@ pg_fatal(const char *fmt,...) } +static char * +get_time_str(double time_ms) +{ + double seconds; + double minutes; + double hours; + double days; + + if (time_ms < 1000.0) + return psprintf("%.3f ms", time_ms); + + seconds = time_ms / 1000.0; + minutes = floor(seconds / 60.0); + seconds -= 60.0 * minutes; + if (minutes < 60.0) + return psprintf("%.3f ms (%02d:%06.3f)", + time_ms, (int) minutes, seconds); + + hours = floor(minutes / 60.0); + minutes -= 60.0 * hours; + if (hours < 24.0) + return psprintf("%.3f ms (%02d:%02d:%06.3f)", + time_ms, (int) hours, (int) minutes, seconds); + + days = floor(hours / 24.0); + hours -= 24.0 * days; + return psprintf("%.3f ms (%.0f d %02d:%02d:%06.3f)", + time_ms, days, (int) hours, (int) minutes, seconds); +} + + void check_ok(void) { + instr_time step_end; + char *step_time; + + Assert(!INSTR_TIME_IS_ZERO(step_start)); + + INSTR_TIME_SET_CURRENT(step_end); + INSTR_TIME_SUBTRACT(step_end, step_start); + step_time = get_time_str(INSTR_TIME_GET_MILLISEC(step_end)); + + /* reset start time */ + INSTR_TIME_SET_ZERO(step_start); + /* all seems well */ - report_status(PG_REPORT, "ok"); + report_status(PG_REPORT, "ok\t%s", step_time); + pfree(step_time); } -- 2.25.1 --vtzGhvizbBRQ85DL--