diff options
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/catalog/catversion.h | 4 | ||||
-rw-r--r-- | src/include/catalog/pg_proc.h | 9 | ||||
-rw-r--r-- | src/include/fmgr.h | 3 | ||||
-rw-r--r-- | src/include/pgstat.h | 138 | ||||
-rw-r--r-- | src/include/portability/instr_time.h | 23 |
5 files changed, 164 insertions, 13 deletions
diff --git a/src/include/catalog/catversion.h b/src/include/catalog/catversion.h index fcc9c6c2340..e0bd027fdac 100644 --- a/src/include/catalog/catversion.h +++ b/src/include/catalog/catversion.h @@ -37,7 +37,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.458 2008/05/09 23:32:04 tgl Exp $ + * $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.459 2008/05/15 00:17:40 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -53,6 +53,6 @@ */ /* yyyymmddN */ -#define CATALOG_VERSION_NO 200805091 +#define CATALOG_VERSION_NO 200805141 #endif diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h index 685b77aca3f..cc1d5db786b 100644 --- a/src/include/catalog/pg_proc.h +++ b/src/include/catalog/pg_proc.h @@ -7,7 +7,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.498 2008/05/08 08:58:59 mha Exp $ + * $PostgreSQL: pgsql/src/include/catalog/pg_proc.h,v 1.499 2008/05/15 00:17:40 tgl Exp $ * * NOTES * The script catalog/genbki.sh reads this file and generates .bki @@ -2963,6 +2963,13 @@ DESCR("statistics: number of buffers written by backends"); DATA(insert OID = 2859 ( pg_stat_get_buf_alloc PGNSP PGUID 12 1 0 f f t f s 0 20 "" _null_ _null_ _null_ pg_stat_get_buf_alloc - _null_ _null_ )); DESCR("statistics: number of buffer allocations"); +DATA(insert OID = 2978 ( pg_stat_get_function_calls PGNSP PGUID 12 1 0 f f t f s 1 20 "26" _null_ _null_ _null_ pg_stat_get_function_calls - _null_ _null_ )); +DESCR("statistics: number of function calls"); +DATA(insert OID = 2979 ( pg_stat_get_function_time PGNSP PGUID 12 1 0 f f t f s 1 20 "26" _null_ _null_ _null_ pg_stat_get_function_time - _null_ _null_ )); +DESCR("statistics: execution time of function"); +DATA(insert OID = 2980 ( pg_stat_get_function_self_time PGNSP PGUID 12 1 0 f f t f s 1 20 "26" _null_ _null_ _null_ pg_stat_get_function_self_time - _null_ _null_ )); +DESCR("statistics: self execution time of function"); + DATA(insert OID = 2230 ( pg_stat_clear_snapshot PGNSP PGUID 12 1 0 f f f f v 0 2278 "" _null_ _null_ _null_ pg_stat_clear_snapshot - _null_ _null_ )); DESCR("statistics: discard current transaction's statistics snapshot"); DATA(insert OID = 2274 ( pg_stat_reset PGNSP PGUID 12 1 0 f f f f v 0 2278 "" _null_ _null_ _null_ pg_stat_reset - _null_ _null_ )); diff --git a/src/include/fmgr.h b/src/include/fmgr.h index ec3261b081a..f0cc26f5311 100644 --- a/src/include/fmgr.h +++ b/src/include/fmgr.h @@ -11,7 +11,7 @@ * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/include/fmgr.h,v 1.58 2008/04/21 00:26:46 tgl Exp $ + * $PostgreSQL: pgsql/src/include/fmgr.h,v 1.59 2008/05/15 00:17:41 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -49,6 +49,7 @@ typedef struct FmgrInfo * count */ bool fn_strict; /* function is "strict" (NULL in => NULL out) */ bool fn_retset; /* function returns a set */ + unsigned char fn_stats; /* collect stats if track_functions > this */ void *fn_extra; /* extra space for use by handler */ MemoryContext fn_mcxt; /* memory context to store fn_extra in */ fmNodePtr fn_expr; /* expression parse tree for call, or NULL */ diff --git a/src/include/pgstat.h b/src/include/pgstat.h index fc0173c6f33..3cda489b350 100644 --- a/src/include/pgstat.h +++ b/src/include/pgstat.h @@ -5,18 +5,27 @@ * * Copyright (c) 2001-2008, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.74 2008/04/03 16:27:25 tgl Exp $ + * $PostgreSQL: pgsql/src/include/pgstat.h,v 1.75 2008/05/15 00:17:41 tgl Exp $ * ---------- */ #ifndef PGSTAT_H #define PGSTAT_H #include "libpq/pqcomm.h" +#include "portability/instr_time.h" #include "utils/hsearch.h" #include "utils/rel.h" #include "utils/timestamp.h" +/* Values for track_functions GUC variable --- order is significant! */ +typedef enum TrackFunctionsLevel +{ + TRACK_FUNC_OFF, + TRACK_FUNC_PL, + TRACK_FUNC_ALL +} TrackFunctionsLevel; + /* ---------- * The types of backend -> collector messages * ---------- @@ -31,7 +40,9 @@ typedef enum StatMsgType PGSTAT_MTYPE_AUTOVAC_START, PGSTAT_MTYPE_VACUUM, PGSTAT_MTYPE_ANALYZE, - PGSTAT_MTYPE_BGWRITER + PGSTAT_MTYPE_BGWRITER, + PGSTAT_MTYPE_FUNCSTAT, + PGSTAT_MTYPE_FUNCPURGE } StatMsgType; /* ---------- @@ -300,6 +311,80 @@ typedef struct PgStat_MsgBgWriter /* ---------- + * PgStat_FunctionCounts The actual per-function counts kept by a backend + * + * This struct should contain only actual event counters, because we memcmp + * it against zeroes to detect whether there are any counts to transmit. + * + * Note that the time counters are in instr_time format here. We convert to + * microseconds in PgStat_Counter format when transmitting to the collector. + * ---------- + */ +typedef struct PgStat_FunctionCounts +{ + PgStat_Counter f_numcalls; + instr_time f_time; + instr_time f_time_self; +} PgStat_FunctionCounts; + +/* ---------- + * PgStat_BackendFunctionEntry Entry in backend's per-function hash table + * ---------- + */ +typedef struct PgStat_BackendFunctionEntry +{ + Oid f_id; + PgStat_FunctionCounts f_counts; +} PgStat_BackendFunctionEntry; + +/* ---------- + * PgStat_FunctionEntry Per-function info in a MsgFuncstat + * ---------- + */ +typedef struct PgStat_FunctionEntry +{ + Oid f_id; + PgStat_Counter f_numcalls; + PgStat_Counter f_time; /* times in microseconds */ + PgStat_Counter f_time_self; +} PgStat_FunctionEntry; + +/* ---------- + * PgStat_MsgFuncstat Sent by the backend to report function + * usage statistics. + * ---------- + */ +#define PGSTAT_NUM_FUNCENTRIES \ + ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \ + / sizeof(PgStat_FunctionEntry)) + +typedef struct PgStat_MsgFuncstat +{ + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int m_nentries; + PgStat_FunctionEntry m_entry[PGSTAT_NUM_FUNCENTRIES]; +} PgStat_MsgFuncstat; + +/* ---------- + * PgStat_MsgFuncpurge Sent by the backend to tell the collector + * about dead functions. + * ---------- + */ +#define PGSTAT_NUM_FUNCPURGE \ + ((PGSTAT_MSG_PAYLOAD - sizeof(Oid) - sizeof(int)) \ + / sizeof(Oid)) + +typedef struct PgStat_MsgFuncpurge +{ + PgStat_MsgHdr m_hdr; + Oid m_databaseid; + int m_nentries; + Oid m_functionid[PGSTAT_NUM_FUNCPURGE]; +} PgStat_MsgFuncpurge; + + +/* ---------- * PgStat_Msg Union over all possible messages. * ---------- */ @@ -315,6 +400,8 @@ typedef union PgStat_Msg PgStat_MsgVacuum msg_vacuum; PgStat_MsgAnalyze msg_analyze; PgStat_MsgBgWriter msg_bgwriter; + PgStat_MsgFuncstat msg_funcstat; + PgStat_MsgFuncpurge msg_funcpurge; } PgStat_Msg; @@ -347,10 +434,11 @@ typedef struct PgStat_StatDBEntry TimestampTz last_autovac_time; /* - * tables must be last in the struct, because we don't write the pointer - * out to the stats file. + * tables and functions must be last in the struct, because we don't + * write the pointers out to the stats file. */ HTAB *tables; + HTAB *functions; } PgStat_StatDBEntry; @@ -386,6 +474,21 @@ typedef struct PgStat_StatTabEntry } PgStat_StatTabEntry; +/* ---------- + * PgStat_StatFuncEntry The collector's data per function + * ---------- + */ +typedef struct PgStat_StatFuncEntry +{ + Oid functionid; + + PgStat_Counter f_numcalls; + + PgStat_Counter f_time; /* times in microseconds */ + PgStat_Counter f_time_self; +} PgStat_StatFuncEntry; + + /* * Global statistics kept in the stats collector */ @@ -451,6 +554,22 @@ typedef struct PgBackendStatus char st_activity[PGBE_ACTIVITY_SIZE]; } PgBackendStatus; +/* + * Working state needed to accumulate per-function-call timing statistics. + */ +typedef struct PgStat_FunctionCallUsage +{ + /* Link to function's hashtable entry (must still be there at exit!) */ + /* NULL means we are not tracking the current function call */ + PgStat_FunctionCounts *fs; + /* Total time previously charged to function, as of function start */ + instr_time save_f_time; + /* Backend-wide total time as of function start */ + instr_time save_total; + /* system clock as of function start */ + instr_time f_start; +} PgStat_FunctionCallUsage; + /* ---------- * GUC parameters @@ -458,6 +577,7 @@ typedef struct PgBackendStatus */ extern bool pgstat_track_activities; extern bool pgstat_track_counts; +extern int pgstat_track_functions; /* * BgWriter statistics counters are updated directly by bgwriter and bufmgr @@ -487,8 +607,8 @@ extern void PgstatCollectorMain(int argc, char *argv[]); */ extern void pgstat_ping(void); -extern void pgstat_report_tabstat(bool force); -extern void pgstat_vacuum_tabstat(void); +extern void pgstat_report_stat(bool force); +extern void pgstat_vacuum_stat(void); extern void pgstat_drop_database(Oid databaseid); extern void pgstat_clear_snapshot(void); @@ -554,6 +674,11 @@ extern void pgstat_count_heap_update(Relation rel, bool hot); extern void pgstat_count_heap_delete(Relation rel); extern void pgstat_update_heap_dead_tuples(Relation rel, int delta); +extern void pgstat_init_function_usage(FunctionCallInfoData *fcinfo, + PgStat_FunctionCallUsage *fcu); +extern void pgstat_end_function_usage(PgStat_FunctionCallUsage *fcu, + bool finalize); + extern void AtEOXact_PgStat(bool isCommit); extern void AtEOSubXact_PgStat(bool isCommit, int nestDepth); @@ -575,6 +700,7 @@ extern void pgstat_send_bgwriter(void); extern PgStat_StatDBEntry *pgstat_fetch_stat_dbentry(Oid dbid); extern PgStat_StatTabEntry *pgstat_fetch_stat_tabentry(Oid relid); extern PgBackendStatus *pgstat_fetch_stat_beentry(int beid); +extern PgStat_StatFuncEntry *pgstat_fetch_stat_funcentry(Oid funcid); extern int pgstat_fetch_stat_numbackends(void); extern PgStat_GlobalStats *pgstat_fetch_global(void); diff --git a/src/include/portability/instr_time.h b/src/include/portability/instr_time.h index 666d495f203..7f4a0923b69 100644 --- a/src/include/portability/instr_time.h +++ b/src/include/portability/instr_time.h @@ -20,6 +20,8 @@ * * INSTR_TIME_SET_CURRENT(t) set t to current time * + * INSTR_TIME_ADD(x, y) x += y + * * INSTR_TIME_SUBTRACT(x, y) x -= y * * INSTR_TIME_ACCUM_DIFF(x, y, z) x += (y - z) @@ -35,15 +37,15 @@ * only useful on intervals. * * When summing multiple measurements, it's recommended to leave the - * running sum in instr_time form (ie, use INSTR_TIME_ACCUM_DIFF) and - * convert to a result format only at the end. + * running sum in instr_time form (ie, use INSTR_TIME_ADD or + * INSTR_TIME_ACCUM_DIFF) and convert to a result format only at the end. * * Beware of multiple evaluations of the macro arguments. * * * Copyright (c) 2001-2008, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/include/portability/instr_time.h,v 1.1 2008/05/14 19:10:29 tgl Exp $ + * $PostgreSQL: pgsql/src/include/portability/instr_time.h,v 1.2 2008/05/15 00:17:41 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -62,6 +64,18 @@ typedef struct timeval instr_time; #define INSTR_TIME_SET_CURRENT(t) gettimeofday(&(t), NULL) +#define INSTR_TIME_ADD(x,y) \ + do { \ + (x).tv_sec += (y).tv_sec; \ + (x).tv_usec += (y).tv_usec; \ + /* Normalize */ \ + while ((x).tv_usec >= 1000000) \ + { \ + (x).tv_usec -= 1000000; \ + (x).tv_sec++; \ + } \ + } while (0) + #define INSTR_TIME_SUBTRACT(x,y) \ do { \ (x).tv_sec -= (y).tv_sec; \ @@ -110,6 +124,9 @@ typedef LARGE_INTEGER instr_time; #define INSTR_TIME_SET_CURRENT(t) QueryPerformanceCounter(&(t)) +#define INSTR_TIME_ADD(x,y) \ + ((x).QuadPart += (y).QuadPart) + #define INSTR_TIME_SUBTRACT(x,y) \ ((x).QuadPart -= (y).QuadPart) |