From 46aa77c7bd256b3448cc420e02ff59d7cc0270c1 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 8 Aug 2010 16:27:06 +0000 Subject: 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 --- src/backend/postmaster/pgstat.c | 45 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/backend/postmaster/pgstat.c') 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" @@ -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 */ -- cgit v1.2.3