Remove PgStat_BackendFunctionEntry
authorMichael Paquier <michael@paquier.xyz>
Thu, 16 Mar 2023 05:22:34 +0000 (14:22 +0900)
committerMichael Paquier <michael@paquier.xyz>
Thu, 16 Mar 2023 05:22:34 +0000 (14:22 +0900)
This structure included only PgStat_FunctionCounts, and removing it
facilitates some upcoming refactoring for pgstatfuncs.c to use more
macros rather that mostly-duplicated functions.

Author: Bertrand Drouvot
Reviewed-by: Nathan Bossart
Discussion: https://postgr.es/m/11d531fe-52fc-c6ea-7e8e-62f1b6ec626e@gmail.com

src/backend/utils/activity/pgstat.c
src/backend/utils/activity/pgstat_function.c
src/backend/utils/adt/pgstatfuncs.c
src/include/pgstat.h
src/tools/pgindent/typedefs.list

index 60fc4e761f711c9c2c50c81ab18ee86d024dbb3c..b125802b2155f6d90e40234eb665c1801fa9ad21 100644 (file)
@@ -292,7 +292,7 @@ static const PgStat_KindInfo pgstat_kind_infos[PGSTAT_NUM_KINDS] = {
        .shared_size = sizeof(PgStatShared_Function),
        .shared_data_off = offsetof(PgStatShared_Function, stats),
        .shared_data_len = sizeof(((PgStatShared_Function *) 0)->stats),
-       .pending_size = sizeof(PgStat_BackendFunctionEntry),
+       .pending_size = sizeof(PgStat_FunctionCounts),
 
        .flush_pending_cb = pgstat_function_flush_cb,
    },
index 6139a27fee03ae8b9fc6b01b7e554f5391122243..0fdcefb7832467fc29f0ec46549bdd383d0c8cb9 100644 (file)
@@ -73,7 +73,7 @@ pgstat_init_function_usage(FunctionCallInfo fcinfo,
                           PgStat_FunctionCallUsage *fcu)
 {
    PgStat_EntryRef *entry_ref;
-   PgStat_BackendFunctionEntry *pending;
+   PgStat_FunctionCounts *pending;
    bool        created_entry;
 
    if (pgstat_track_functions <= fcinfo->flinfo->fn_stats)
@@ -121,10 +121,10 @@ pgstat_init_function_usage(FunctionCallInfo fcinfo,
 
    pending = entry_ref->pending;
 
-   fcu->fs = &pending->f_counts;
+   fcu->fs = pending;
 
    /* save stats for this function, later used to compensate for recursion */
-   fcu->save_f_total_time = pending->f_counts.f_total_time;
+   fcu->save_f_total_time = pending->f_total_time;
 
    /* save current backend-wide total time */
    fcu->save_total = total_func_time;
@@ -192,10 +192,10 @@ pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
 bool
 pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
 {
-   PgStat_BackendFunctionEntry *localent;
+   PgStat_FunctionCounts *localent;
    PgStatShared_Function *shfuncent;
 
-   localent = (PgStat_BackendFunctionEntry *) entry_ref->pending;
+   localent = (PgStat_FunctionCounts *) entry_ref->pending;
    shfuncent = (PgStatShared_Function *) entry_ref->shared_stats;
 
    /* localent always has non-zero content */
@@ -203,11 +203,11 @@ pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
    if (!pgstat_lock_entry(entry_ref, nowait))
        return false;
 
-   shfuncent->stats.f_numcalls += localent->f_counts.f_numcalls;
+   shfuncent->stats.f_numcalls += localent->f_numcalls;
    shfuncent->stats.f_total_time +=
-       INSTR_TIME_GET_MICROSEC(localent->f_counts.f_total_time);
+       INSTR_TIME_GET_MICROSEC(localent->f_total_time);
    shfuncent->stats.f_self_time +=
-       INSTR_TIME_GET_MICROSEC(localent->f_counts.f_self_time);
+       INSTR_TIME_GET_MICROSEC(localent->f_self_time);
 
    pgstat_unlock_entry(entry_ref);
 
@@ -215,11 +215,11 @@ pgstat_function_flush_cb(PgStat_EntryRef *entry_ref, bool nowait)
 }
 
 /*
- * find any existing PgStat_BackendFunctionEntry entry for specified function
+ * find any existing PgStat_FunctionCounts entry for specified function
  *
  * If no entry, return NULL, don't create a new one
  */
-PgStat_BackendFunctionEntry *
+PgStat_FunctionCounts *
 find_funcstat_entry(Oid func_id)
 {
    PgStat_EntryRef *entry_ref;
index b61a12382b309e5ce1de1ce642ce855b8c9e2cc4..35c6d465553f5293bed95bdb79fdfcfba3c43c78 100644 (file)
@@ -1652,33 +1652,33 @@ Datum
 pg_stat_get_xact_function_calls(PG_FUNCTION_ARGS)
 {
    Oid         funcid = PG_GETARG_OID(0);
-   PgStat_BackendFunctionEntry *funcentry;
+   PgStat_FunctionCounts *funcentry;
 
    if ((funcentry = find_funcstat_entry(funcid)) == NULL)
        PG_RETURN_NULL();
-   PG_RETURN_INT64(funcentry->f_counts.f_numcalls);
+   PG_RETURN_INT64(funcentry->f_numcalls);
 }
 
 Datum
 pg_stat_get_xact_function_total_time(PG_FUNCTION_ARGS)
 {
    Oid         funcid = PG_GETARG_OID(0);
-   PgStat_BackendFunctionEntry *funcentry;
+   PgStat_FunctionCounts *funcentry;
 
    if ((funcentry = find_funcstat_entry(funcid)) == NULL)
        PG_RETURN_NULL();
-   PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->f_counts.f_total_time));
+   PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->f_total_time));
 }
 
 Datum
 pg_stat_get_xact_function_self_time(PG_FUNCTION_ARGS)
 {
    Oid         funcid = PG_GETARG_OID(0);
-   PgStat_BackendFunctionEntry *funcentry;
+   PgStat_FunctionCounts *funcentry;
 
    if ((funcentry = find_funcstat_entry(funcid)) == NULL)
        PG_RETURN_NULL();
-   PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->f_counts.f_self_time));
+   PG_RETURN_FLOAT8(INSTR_TIME_GET_MILLISEC(funcentry->f_self_time));
 }
 
 
index f43fac09ede65d91e4724d321866a0d78432c942..1e418b682b56dab59caf57540e804de533f70357 100644 (file)
@@ -111,15 +111,6 @@ typedef struct PgStat_FunctionCounts
    instr_time  f_self_time;
 } PgStat_FunctionCounts;
 
-/* ----------
- * PgStat_BackendFunctionEntry Non-flushed function stats.
- * ----------
- */
-typedef struct PgStat_BackendFunctionEntry
-{
-   PgStat_FunctionCounts f_counts;
-} PgStat_BackendFunctionEntry;
-
 /*
  * Working state needed to accumulate per-function-call timing statistics.
  */
@@ -556,7 +547,7 @@ extern void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu,
                                      bool finalize);
 
 extern PgStat_StatFuncEntry *pgstat_fetch_stat_funcentry(Oid func_id);
-extern PgStat_BackendFunctionEntry *find_funcstat_entry(Oid func_id);
+extern PgStat_FunctionCounts *find_funcstat_entry(Oid func_id);
 
 
 /*
index 86a9303bf56bc7c0a49c3735202acb65206df0c0..097f42e1b343ec4f47b8fcd1dba38b09c0b106a0 100644 (file)
@@ -2032,7 +2032,6 @@ PgStatShared_SLRU
 PgStatShared_Subscription
 PgStatShared_Wal
 PgStat_ArchiverStats
-PgStat_BackendFunctionEntry
 PgStat_BackendSubEntry
 PgStat_BgWriterStats
 PgStat_BktypeIO