MCPcopy Create free account
hub / github.com/apache/cloudberry / pgstat_end_function_usage

Function pgstat_end_function_usage

src/backend/postmaster/pgstat.c:1997–2039  ·  view source on GitHub ↗

* Calculate function call usage and update stat counters. * Called by the executor after invoking a function. * * In the case of a set-returning function that runs in value-per-call mode, * we will see multiple pgstat_init_function_usage/pgstat_end_function_usage * calls for what the user considers a single call of the function. The * finalize flag should be TRUE on the last call. */

Source from the content-addressed store, hash-verified

1995 * finalize flag should be TRUE on the last call.
1996 */
1997void
1998pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, bool finalize)
1999{
2000 PgStat_FunctionCounts *fs = fcu->fs;
2001 instr_time f_total;
2002 instr_time f_others;
2003 instr_time f_self;
2004
2005 /* stats not wanted? */
2006 if (fs == NULL)
2007 return;
2008
2009 /* total elapsed time in this function call */
2010 INSTR_TIME_SET_CURRENT(f_total);
2011 INSTR_TIME_SUBTRACT(f_total, fcu->f_start);
2012
2013 /* self usage: elapsed minus anything already charged to other calls */
2014 f_others = total_func_time;
2015 INSTR_TIME_SUBTRACT(f_others, fcu->save_total);
2016 f_self = f_total;
2017 INSTR_TIME_SUBTRACT(f_self, f_others);
2018
2019 /* update backend-wide total time */
2020 INSTR_TIME_ADD(total_func_time, f_self);
2021
2022 /*
2023 * Compute the new f_total_time as the total elapsed time added to the
2024 * pre-call value of f_total_time. This is necessary to avoid
2025 * double-counting any time taken by recursive calls of myself. (We do
2026 * not need any similar kluge for self time, since that already excludes
2027 * any recursive calls.)
2028 */
2029 INSTR_TIME_ADD(f_total, fcu->save_f_total_time);
2030
2031 /* update counters in function stats table */
2032 if (finalize)
2033 fs->f_numcalls++;
2034 fs->f_total_time = f_total;
2035 INSTR_TIME_ADD(fs->f_self_time, f_self);
2036
2037 /* indicate that we have something to send */
2038 have_function_stats = true;
2039}
2040
2041
2042/* ----------

Callers 9

call_pltcl_start_procFunction · 0.85
fmgr_security_definerFunction · 0.85
ExecCallTriggerFuncFunction · 0.85
ExecuteCallStmtFunction · 0.85
EventTriggerInvokeFunction · 0.85
ExecEvalFuncExprFusageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected