On Sat, Mar 25, 2023 at 11:50:50AM +0900, Michael Paquier wrote: > On Fri, Mar 24, 2023 at 06:58:30AM +0100, Drouvot, Bertrand wrote: >> - Does not include the refactoring for >> pg_stat_get_xact_function_total_time(), >> pg_stat_get_xact_function_self_time(), >> pg_stat_get_function_total_time() and >> pg_stat_get_function_self_time(). I think they can be done in a >> dedicated commit once we agree on the renaming for >> PG_STAT_GET_DBENTRY_FLOAT8 (see Andres's comment up-thread) so that >> the new macros can match the future agreement.
Thanks for the reminder. I have completely missed that this is mentioned in [1], and that it is all about 8018ffb. The suggestion to prefix the macro names with a "_MS" to outline the conversion sounds like a good one seen from here. So please find attached a patch to do this adjustment, completed with a similar switch for the two counters of the function entries. >> - Does include the refactoring of the new >> - pg_stat_get_xact_tuples_newpage_updated() function (added in >> - ae4fdde135) > > Fine by me. One step is better than no steps, and this helps: > 1 file changed, 29 insertions(+), 97 deletions(-) > > I'll go apply that if there are no objections. Just did this part to shave a bit more code. [1]: https://www.postgresql.org/message-id/20230111225907.6el6c5j3hukiz...@awork3.anarazel.de -- Michael
diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index e1dd1e0ad3..ff155e003f 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); +/* 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); \ } -Datum -pg_stat_get_function_self_time(PG_FUNCTION_ARGS) -{ - Oid funcid = PG_GETARG_OID(0); - PgStat_StatFuncEntry *funcentry; +/* pg_stat_get_function_total_time */ +PG_STAT_GET_FUNCENTRY_FLOAT8_MS(total_time) - 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); -} +/* 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)
signature.asc
Description: PGP signature