diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-08-08 16:27:06 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-08-08 16:27:06 +0000 |
commit | 46aa77c7bd256b3448cc420e02ff59d7cc0270c1 (patch) | |
tree | cdf372525292dbd9290d69f3e94a5de010b4a108 /src/backend/postmaster/pgstat.c | |
parent | 83f5491c63f33cce5b84532cd76602295580809e (diff) |
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
Diffstat (limited to 'src/backend/postmaster/pgstat.c')
-rw-r--r-- | src/backend/postmaster/pgstat.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index 29dd1a7848b..ae8db9e9dea 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -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" @@ -1403,6 +1403,23 @@ pgstat_init_function_usage(FunctionCallInfoData *fcinfo, } /* + * 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. * @@ -1561,6 +1578,32 @@ get_tabstat_entry(Oid rel_id, bool isshared) } /* + * 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 */ static PgStat_SubXactStatus * |