@@ -152,29 +152,26 @@ pg_stat_get_function_calls(PG_FUNCTION_ARGS)
152
152
PG_RETURN_INT64 (funcentry -> numcalls );
153
153
}
154
154
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
+ Oidfuncid = PG_GETARG_OID(0);\
161
+ doubleresult;\
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 )
178
175
179
176
Datum
180
177
pg_stat_get_backend_idset (PG_FUNCTION_ARGS )
@@ -1147,7 +1144,8 @@ pg_stat_get_db_checksum_last_failure(PG_FUNCTION_ARGS)
1147
1144
PG_RETURN_TIMESTAMPTZ (result );
1148
1145
}
1149
1146
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 )\
1151
1149
Datum\
1152
1150
CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS)\
1153
1151
{\
@@ -1164,19 +1162,19 @@ CppConcat(pg_stat_get_db_,stat)(PG_FUNCTION_ARGS)\
1164
1162
}
1165
1163
1166
1164
/* pg_stat_get_db_active_time */
1167
- PG_STAT_GET_DBENTRY_FLOAT8 (active_time )
1165
+ PG_STAT_GET_DBENTRY_FLOAT8_MS (active_time )
1168
1166
1169
1167
/* 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 )
1171
1169
1172
1170
/* 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 )
1174
1172
1175
1173
/* 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 )
1177
1175
1178
1176
/* pg_stat_get_db_session_time */
1179
- PG_STAT_GET_DBENTRY_FLOAT8 (session_time )
1177
+ PG_STAT_GET_DBENTRY_FLOAT8_MS (session_time )
1180
1178
1181
1179
Datum
1182
1180
pg_stat_get_bgwriter_timed_checkpoints (PG_FUNCTION_ARGS )
@@ -1609,28 +1607,23 @@ pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
1609
1607
PG_RETURN_INT64 (funcentry -> numcalls );
1610
1608
}
1611
1609
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
+ Oidfuncid = 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));\
1621
1620
}
1622
1621
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 )
1633
1624
1625
+ /* pg_stat_get_xact_function_self_time */
1626
+ PG_STAT_GET_XACT_FUNCENTRY_FLOAT8_MS (self_time )
1634
1627
1635
1628
/* Get the timestamp of the current statistics snapshot */
1636
1629
Datum