@@ -152,29 +152,26 @@ pg_stat_get_function_calls(PG_FUNCTION_ARGS)
152152 PG_RETURN_INT64 (funcentry -> numcalls );
153153}
154154
155- Datum
156- pg_stat_get_function_total_time (PG_FUNCTION_ARGS )
157- {
158- Oid funcid = PG_GETARG_OID (0 );
159- PgStat_StatFuncEntry * funcentry ;
160-
161- if ((funcentry = pgstat_fetch_stat_funcentry (funcid )) == NULL )
162- PG_RETURN_NULL ();
163- /* convert counter from microsec to millisec for display */
164- PG_RETURN_FLOAT8 (((double ) funcentry -> total_time ) / 1000.0 );
165- }
166-
167- Datum
168- pg_stat_get_function_self_time (PG_FUNCTION_ARGS )
169- {
170- Oid funcid = PG_GETARG_OID (0 );
171- PgStat_StatFuncEntry * funcentry ;
172-
173- if ((funcentry = pgstat_fetch_stat_funcentry (funcid )) == NULL )
174- PG_RETURN_NULL ();
175- /* convert counter from microsec to millisec for display */
176- PG_RETURN_FLOAT8 (((double ) funcentry -> self_time ) / 1000.0 );
177- }
155+ /* convert counter from microsec to millisec for display */
156+ #define PG_STAT_GET_FUNCENTRY_FLOAT8_MS (stat ) \
157+ Datum \
158+ CppConcat(pg_stat_get_function_,stat)(PG_FUNCTION_ARGS) \
159+ { \
160+ Oid funcid = PG_GETARG_OID(0); \
161+ double result; \
162+ PgStat_StatFuncEntry *funcentry; \
163+ \
164+ if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL) \
165+ PG_RETURN_NULL(); \
166+ result = ((double) funcentry->stat) / 1000.0; \
167+ PG_RETURN_FLOAT8(result); \
168+ }
169+
170+ /* pg_stat_get_function_total_time */
171+ PG_STAT_GET_FUNCENTRY_FLOAT8_MS (total_time )
172+
173+ /* pg_stat_get_function_self_time */
174+ PG_STAT_GET_FUNCENTRY_FLOAT8_MS (self_time )
178175
179176Datum
180177pg_stat_get_backend_idset (PG_FUNCTION_ARGS )
@@ -1147,7 +1144,8 @@ pg_stat_get_db_checksum_last_failure(PG_FUNCTION_ARGS)
11471144 PG_RETURN_TIMESTAMPTZ (result );
11481145}
11491146
1150- #define PG_STAT_GET_DBENTRY_FLOAT8 (stat ) \
1147+ /* convert counter from microsec to millisec for display */
1148+ #define PG_STAT_GET_DBENTRY_FLOAT8_MS (stat ) \
11511149Datum \
11521150CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
11531151{ \
@@ -1164,19 +1162,19 @@ CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS) \
11641162}
11651163
11661164/* pg_stat_get_db_active_time */
1167- PG_STAT_GET_DBENTRY_FLOAT8 (active_time )
1165+ PG_STAT_GET_DBENTRY_FLOAT8_MS (active_time )
11681166
11691167/* pg_stat_get_db_blk_read_time */
1170- PG_STAT_GET_DBENTRY_FLOAT8 (blk_read_time )
1168+ PG_STAT_GET_DBENTRY_FLOAT8_MS (blk_read_time )
11711169
11721170/* pg_stat_get_db_blk_write_time */
1173- PG_STAT_GET_DBENTRY_FLOAT8 (blk_write_time )
1171+ PG_STAT_GET_DBENTRY_FLOAT8_MS (blk_write_time )
11741172
11751173/* pg_stat_get_db_idle_in_transaction_time */
1176- PG_STAT_GET_DBENTRY_FLOAT8 (idle_in_transaction_time )
1174+ PG_STAT_GET_DBENTRY_FLOAT8_MS (idle_in_transaction_time )
11771175
11781176/* pg_stat_get_db_session_time */
1179- PG_STAT_GET_DBENTRY_FLOAT8 (session_time )
1177+ PG_STAT_GET_DBENTRY_FLOAT8_MS (session_time )
11801178
11811179Datum
11821180pg_stat_get_bgwriter_timed_checkpoints (PG_FUNCTION_ARGS )
@@ -1609,28 +1607,23 @@ pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
16091607 PG_RETURN_INT64 (funcentry -> numcalls );
16101608}
16111609
1612- Datum
1613- pg_stat_get_xact_function_total_time (PG_FUNCTION_ARGS )
1614- {
1615- Oid funcid = PG_GETARG_OID (0 );
1616- PgStat_FunctionCounts * funcentry ;
1617-
1618- if ((funcentry = find_funcstat_entry (funcid )) == NULL )
1619- PG_RETURN_NULL ();
1620- PG_RETURN_FLOAT8 (INSTR_TIME_GET_MILLISEC (funcentry -> total_time ));
1610+ #define PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS (stat ) \
1611+ Datum \
1612+ CppConcat(pg_stat_get_xact_function_,stat)(PG_FUNCTION_ARGS) \
1613+ { \
1614+ Oid funcid = PG_GETARG_OID(0); \
1615+ PgStat_FunctionCounts *funcentry; \
1616+ \
1617+ if ((funcentry = find_funcstat_entry(funcid)) == NULL) \
1618+ PG_RETURN_NULL(); \
1619+ PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->stat)); \
16211620}
16221621
1623- Datum
1624- pg_stat_get_xact_function_self_time (PG_FUNCTION_ARGS )
1625- {
1626- Oid funcid = PG_GETARG_OID (0 );
1627- PgStat_FunctionCounts * funcentry ;
1628-
1629- if ((funcentry = find_funcstat_entry (funcid )) == NULL )
1630- PG_RETURN_NULL ();
1631- PG_RETURN_FLOAT8 (INSTR_TIME_GET_MILLISEC (funcentry -> self_time ));
1632- }
1622+ /* pg_stat_get_xact_function_total_time */
1623+ PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS (total_time )
16331624
1625+ /* pg_stat_get_xact_function_self_time */
1626+ PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS (self_time )
16341627
16351628/* Get the timestamp of the current statistics snapshot */
16361629Datum
0 commit comments