mirror of
https://github.com/postgres/postgres.git
synced 2025-11-18 02:02:55 +03:00
Add stats_reset to pg_stat_user_functions
It is possible to call pg_stat_reset_single_function_counters() for a single function, but the reset time was missing the system view showing its statistics. Like all the fields of pg_stat_user_functions, the GUC track_functions needs to be enabled to show the statistics about function executions. Bump catalog version. Bump PGSTAT_FILE_FORMAT_ID, as a result of the new field added to PgStat_StatFuncEntry. Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com> Discussion: https://postgr.es/m/aONjnsaJSx-nEdfU@paquier.xyz
This commit is contained in:
@@ -1131,7 +1131,8 @@ CREATE VIEW pg_stat_user_functions AS
|
||||
P.proname AS funcname,
|
||||
pg_stat_get_function_calls(P.oid) AS calls,
|
||||
pg_stat_get_function_total_time(P.oid) AS total_time,
|
||||
pg_stat_get_function_self_time(P.oid) AS self_time
|
||||
pg_stat_get_function_self_time(P.oid) AS self_time,
|
||||
pg_stat_get_function_stat_reset_time(P.oid) AS stats_reset
|
||||
FROM pg_proc P LEFT JOIN pg_namespace N ON (N.oid = P.pronamespace)
|
||||
WHERE P.prolang != 12 -- fast check to eliminate built-in functions
|
||||
AND pg_stat_get_function_calls(P.oid) IS NOT NULL;
|
||||
|
||||
@@ -328,6 +328,7 @@ static const PgStat_KindInfo pgstat_kind_builtin_infos[PGSTAT_KIND_BUILTIN_SIZE]
|
||||
.pending_size = sizeof(PgStat_FunctionCounts),
|
||||
|
||||
.flush_pending_cb = pgstat_function_flush_cb,
|
||||
.reset_timestamp_cb = pgstat_function_reset_timestamp_cb,
|
||||
},
|
||||
|
||||
[PGSTAT_KIND_REPLSLOT] = {
|
||||
|
||||
@@ -214,6 +214,12 @@ pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
pgstat_function_reset_timestamp_cb(PgStatShared_Common *header, TimestampTz ts)
|
||||
{
|
||||
((PgStatShared_Function *) header)->stats.stat_reset_timestamp = ts;
|
||||
}
|
||||
|
||||
/*
|
||||
* find any existing PgStat_FunctionCounts entry for specified function
|
||||
*
|
||||
|
||||
@@ -203,6 +203,24 @@ 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_function_stat_reset_time(PG_FUNCTION_ARGS)
|
||||
{
|
||||
Oid funcid = PG_GETARG_OID(0);
|
||||
TimestampTz result;
|
||||
PgStat_StatFuncEntry *funcentry;
|
||||
|
||||
if ((funcentry = pgstat_fetch_stat_funcentry(funcid)) == NULL)
|
||||
result = 0;
|
||||
else
|
||||
result = funcentry->stat_reset_timestamp;
|
||||
|
||||
if (result == 0)
|
||||
PG_RETURN_NULL();
|
||||
else
|
||||
PG_RETURN_TIMESTAMPTZ(result);
|
||||
}
|
||||
|
||||
Datum
|
||||
pg_stat_get_backend_idset(PG_FUNCTION_ARGS)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user