1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-06 00:02:13 +03:00

Add stats functions and views to provide access to a transaction's own

statistics counts.  These numbers are being accumulated but haven't yet been
transmitted to the collector (and won't be, until the transaction ends).
For some purposes, though, it's handy to be able to look at them.

Joel Jacobson, reviewed by Itagaki Takahiro
This commit is contained in:
Tom Lane
2010-08-08 16:27:06 +00:00
parent 83f5491c63
commit 46aa77c7bd
8 changed files with 525 additions and 67 deletions

View File

@@ -13,7 +13,7 @@
*
* Copyright (c) 2001-2010, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.204 2010/07/06 19:18:57 momjian Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.205 2010/08/08 16:27:03 tgl Exp $
* ----------
*/
#include "postgres.h"
@@ -1402,6 +1402,23 @@ pgstat_init_function_usage(FunctionCallInfoData *fcinfo,
INSTR_TIME_SET_CURRENT(fcu->f_start);
}
/*
* find_funcstat_entry - find any existing PgStat_BackendFunctionEntry entry
* for specified function
*
* If no entry, return NULL, don't create a new one
*/
PgStat_BackendFunctionEntry *
find_funcstat_entry(Oid func_id)
{
if (pgStatFunctions == NULL)
return NULL;
return (PgStat_BackendFunctionEntry *) hash_search(pgStatFunctions,
(void *) &func_id,
HASH_FIND, NULL);
}
/*
* Calculate function call usage and update stat counters.
* Called by the executor after invoking a function.
@@ -1560,6 +1577,32 @@ get_tabstat_entry(Oid rel_id, bool isshared)
return entry;
}
/*
* find_tabstat_entry - find any existing PgStat_TableStatus entry for rel
*
* If no entry, return NULL, don't create a new one
*/
PgStat_TableStatus *
find_tabstat_entry(Oid rel_id)
{
PgStat_TableStatus *entry;
TabStatusArray *tsa;
int i;
for (tsa = pgStatTabList; tsa != NULL; tsa = tsa->tsa_next)
{
for (i = 0; i < tsa->tsa_used; i++)
{
entry = &tsa->tsa_entries[i];
if (entry->t_id == rel_id)
return entry;
}
}
/* Not present */
return NULL;
}
/*
* get_tabstat_stack_level - add a new (sub)transaction stack entry if needed
*/