pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Drouvot, Bertrand <bertranddrouvot.pg@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: Gregory Stark (as CFM) <stark.cfm@gmail.com>
Cc: Andres Freund <andres@anarazel.de>
Cc: Michael Paquier <michael.paquier@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Generate pg_stat_get_xact*() functions with Macros
Date: Mon, 27 Mar 2023 10:11:21 +0200
Message-ID: <6e2efb4f-6fd0-807e-f6bf-94207db8183a@gmail.com> (raw )
In-Reply-To: <ZCFEej4n6qzATmcz@paquier.xyz >
References: <20230113183746.zyncqr2zz3gk6yh6@awork3.anarazel.de >
<CAM-w4HNq0SmbDa1jCtbmtCzWrx6G7qAGxsjzcOdEyceGOAdJmA@mail.gmail.com >
<11744b0e-5f7f-aba8-7d9c-2ff0a0c6e2b2@gmail.com >
<ZBzpDwOMf1ia+M9l@paquier.xyz >
<631e3084-c5d9-8463-7540-fcff4674caa5@gmail.com >
<ZB5hipxlAfZoILgZ@paquier.xyz >
<ZCDvYgd8OthCttam@paquier.xyz >
<e2d94c75-a3c1-bc06-f335-73c7225fe5ec@gmail.com >
<ZCE6X6nsjkaDwz3o@paquier.xyz >
<442ba19a-6e8a-3fe3-d404-e9101dfbfcbb@gmail.com >
<ZCFEej4n6qzATmcz@paquier.xyz >
On 3/27/23 9:23 AM, Michael Paquier wrote:
> On Mon, Mar 27, 2023 at 08:54:13AM +0200, Drouvot, Bertrand wrote:
>> Yes, something like V1 up-thread was doing. I think it can be added with your current proposal.
>
> Sure, I can write that. Or perhaps you'd prefer write something
> yourself?
Please find attached V2 adding pg_stat_get_xact_function_total_time()
and pg_stat_get_xact_function_self_time() to the party.
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
Attachments:
v2-0001-pgstatfuncs-more-macros.patch (text/plain, 4.3K) download
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c
index e1dd1e0ad3..d0bf61cc64 100644
--- a/src/backend/utils/adt/pgstatfuncs.c
+++ b/src/backend/utils/adt/pgstatfuncs.c
@@ -152,29 +152,26 @@ pg_stat_get_function_calls(PG_FUNCTION_ARGS)
PG_RETURN_INT64(funcentry->numcalls);
}
-Datum
-pg_stat_get_function_total_time(PG_FUNCTION_ARGS)
-{
- Oid funcid = PG_GETARG_OID(0);
- PgStat_StatFuncEntry *funcentry;
-
- if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
- PG_RETURN_NULL();
- /* convert counter from microsec to millisec for display */
- PG_RETURN_FLOAT8(((double) funcentry->total_time) / 1000.0);
-}
-
-Datum
-pg_stat_get_function_self_time(PG_FUNCTION_ARGS)
-{
- Oid funcid = PG_GETARG_OID(0);
- PgStat_StatFuncEntry *funcentry;
-
- if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
- PG_RETURN_NULL();
- /* convert counter from microsec to millisec for display */
- PG_RETURN_FLOAT8(((double) funcentry->self_time) / 1000.0);
-}
+/* convert counter from microsec to millisec for display */
+#define PG_STAT_GET_FUNCENTRY_FLOAT8_MS(stat) \
+Datum \
+CppConcat(pg_stat_get_function_,stat)(PG_FUNCTION_ARGS) \
+{ \
+ Oid funcid = PG_GETARG_OID(0); \
+ double result; \
+ PgStat_StatFuncEntry *funcentry; \
+ \
+ if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL) \
+ PG_RETURN_NULL(); \
+ result = ((double) funcentry->stat) / 1000.0; \
+ PG_RETURN_FLOAT8(result); \
+}
+
+/* pg_stat_get_function_total_time */
+PG_STAT_GET_FUNCENTRY_FLOAT8_MS(total_time)
+
+/* pg_stat_get_function_self_time */
+PG_STAT_GET_FUNCENTRY_FLOAT8_MS(self_time)
Datum
pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
@@ -1147,7 +1144,8 @@ pg_stat_get_db_checksum_last_failure(PG_FUNCTION_ARGS)
PG_RETURN_TIMESTAMPTZ(result);
}
-#define PG_STAT_GET_DBENTRY_FLOAT8(stat) \
+/* convert counter from microsec to millisec for display */
+#define PG_STAT_GET_DBENTRY_FLOAT8_MS(stat) \
Datum \
CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
{ \
@@ -1164,19 +1162,19 @@ CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
}
/* pg_stat_get_db_active_time */
-PG_STAT_GET_DBENTRY_FLOAT8(active_time)
+PG_STAT_GET_DBENTRY_FLOAT8_MS(active_time)
/* pg_stat_get_db_blk_read_time */
-PG_STAT_GET_DBENTRY_FLOAT8(blk_read_time)
+PG_STAT_GET_DBENTRY_FLOAT8_MS(blk_read_time)
/* pg_stat_get_db_blk_write_time */
-PG_STAT_GET_DBENTRY_FLOAT8(blk_write_time)
+PG_STAT_GET_DBENTRY_FLOAT8_MS(blk_write_time)
/* pg_stat_get_db_idle_in_transaction_time */
-PG_STAT_GET_DBENTRY_FLOAT8(idle_in_transaction_time)
+PG_STAT_GET_DBENTRY_FLOAT8_MS(idle_in_transaction_time)
/* pg_stat_get_db_session_time */
-PG_STAT_GET_DBENTRY_FLOAT8(session_time)
+PG_STAT_GET_DBENTRY_FLOAT8_MS(session_time)
Datum
pg_stat_get_bgwriter_timed_checkpoints(PG_FUNCTION_ARGS)
@@ -1609,28 +1607,23 @@ pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
PG_RETURN_INT64(funcentry->numcalls);
}
-Datum
-pg_stat_get_xact_function_total_time(PG_FUNCTION_ARGS)
-{
- Oid funcid = PG_GETARG_OID(0);
- PgStat_FunctionCounts *funcentry;
-
- if ((funcentry = find_funcstat_entry(funcid)) == NULL)
- PG_RETURN_NULL();
- PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->total_time));
-}
-
-Datum
-pg_stat_get_xact_function_self_time(PG_FUNCTION_ARGS)
-{
- Oid funcid = PG_GETARG_OID(0);
- PgStat_FunctionCounts *funcentry;
+#define PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS(stat) \
+Datum \
+CppConcat(pg_stat_get_xact_function_,stat)(PG_FUNCTION_ARGS) \
+{ \
+ Oid funcid = PG_GETARG_OID(0); \
+ PgStat_FunctionCounts *funcentry; \
+ \
+ if ((funcentry = find_funcstat_entry(funcid)) == NULL) \
+ PG_RETURN_NULL(); \
+ PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->stat)); \
+} \
- if ((funcentry = find_funcstat_entry(funcid)) == NULL)
- PG_RETURN_NULL();
- PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->self_time));
-}
+/* pg_stat_get_xact_function_total_time */
+PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS(total_time)
+/* pg_stat_get_xact_function_self_time */
+PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS(self_time)
/* Get the timestamp of the current statistics snapshot */
Datum
view thread (24+ messages) latest in thread
Message-ID: <6e2efb4f-6fd0-807e-f6bf-94207db8183a@gmail.com>
Permalink: ../6e2efb4f-6fd0-807e-f6bf-94207db8183a@gmail.com/
Also on: postgresql.org/message-id/6e2efb4f-6fd0-807e-f6bf-94207db8183a@gmail.com
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: bertranddrouvot.pg@gmail.com, michael@paquier.xyz, stark.cfm@gmail.com, andres@anarazel.de, michael.paquier@gmail.com
Subject: Re: Generate pg_stat_get_xact*() functions with Macros
In-Reply-To: <6e2efb4f-6fd0-807e-f6bf-94207db8183a@gmail.com>
References: <20230113183746.zyncqr2zz3gk6yh6@awork3.anarazel.de> <CAM-w4HNq0SmbDa1jCtbmtCzWrx6G7qAGxsjzcOdEyceGOAdJmA@mail.gmail.com> <11744b0e-5f7f-aba8-7d9c-2ff0a0c6e2b2@gmail.com> <ZBzpDwOMf1ia+M9l@paquier.xyz> <631e3084-c5d9-8463-7540-fcff4674caa5@gmail.com> <ZB5hipxlAfZoILgZ@paquier.xyz> <ZCDvYgd8OthCttam@paquier.xyz> <e2d94c75-a3c1-bc06-f335-73c7225fe5ec@gmail.com> <ZCE6X6nsjkaDwz3o@paquier.xyz> <442ba19a-6e8a-3fe3-d404-e9101dfbfcbb@gmail.com> <ZCFEej4n6qzATmcz@paquier.xyz> <6e2efb4f-6fd0-807e-f6bf-94207db8183a@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox