* thus an initdb and we might want to provide this as a
* patch for 7.1.
*
- * - Make the functions from contrib/pgstat_tmp builtin
- * and create the views on initdb.
- *
* Copyright (c) 2001, PostgreSQL Global Development Group
*
- * $Id: pgstat.c,v 1.3 2001/06/30 19:01:27 petere Exp $
+ * $Id: pgstat.c,v 1.4 2001/07/05 15:19:40 wieck Exp $
* ----------
*/
#include "postgres.h"
* Global data
* ----------
*/
-
+bool pgstat_collect_startcollector = true;
+bool pgstat_collect_resetonpmstart = true;
+bool pgstat_collect_querystring = false;
+bool pgstat_collect_tuplelevel = false;
+bool pgstat_collect_blocklevel = false;
/* ----------
* Local data
{
int alen;
+ /*
+ * Force start of collector daemon if something to collect
+ */
+ if (pgstat_collect_querystring || pgstat_collect_tuplelevel ||
+ pgstat_collect_blocklevel)
+ pgstat_collect_startcollector = true;
+
/*
* Initialize the filenames for the status reports.
*/
snprintf(pgStat_fname, MAXPGPATH,
PGSTAT_STAT_FILENAME, DataDir);
+ /*
+ * If we don't have to start a collector or should reset the
+ * collected statistics on postmaster start, simply remove the
+ * file.
+ */
+ if (!pgstat_collect_startcollector || pgstat_collect_resetonpmstart)
+ unlink(pgStat_fname);
+
+ /*
+ * Nothing else required if collector will not get started
+ */
+ if (!pgstat_collect_startcollector)
+ return 0;
+
/*
* Create the UDP socket for receiving statistic messages
*/
int
pgstat_start(void)
{
+ /*
+ * Do nothing if no collector needed
+ */
+ if (!pgstat_collect_startcollector)
+ return 0;
+
/*
* Check that the socket at least is there
*/
{
PgStat_MsgBeterm msg;
+ if (!pgstat_collect_startcollector)
+ return;
+
msg.m_hdr.m_type = PGSTAT_MTYPE_BETERM;
msg.m_hdr.m_backendid = 0;
msg.m_hdr.m_procpid = pid;
{
PgStat_MsgBestart msg;
- if (pgStatSock < 0)
+ if (!pgstat_collect_startcollector || pgStatSock < 0)
return;
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_BESTART);
PgStat_MsgActivity msg;
int len;
- if (pgStatSock < 0)
+ if (!pgstat_collect_querystring || pgStatSock < 0)
return;
len = strlen(what);
int n;
int len;
+ if (!pgstat_collect_querystring && !pgstat_collect_tuplelevel &&
+ !pgstat_collect_blocklevel)
+ return;
+
if (pgStatSock < 0)
return;
stats->heap_scan_counted = FALSE;
stats->index_scan_counted = FALSE;
- if (pgStatSock < 0)
+ if (!pgstat_collect_startcollector || pgStatSock < 0)
{
stats->no_stats = TRUE;
return;
void
pgstat_count_xact_commit(void)
{
+ if (!pgstat_collect_querystring && !pgstat_collect_tuplelevel &&
+ !pgstat_collect_blocklevel)
+ return;
+
pgStatXactCommit++;
/*
void
pgstat_count_xact_rollback(void)
{
+ if (!pgstat_collect_querystring && !pgstat_collect_tuplelevel &&
+ !pgstat_collect_blocklevel)
+ return;
+
pgStatXactRollback++;
/*
* Support for grand unified configuration scheme, including SET
* command, configuration file, and command line options.
*
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.44 2001/06/30 22:03:26 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/guc.c,v 1.45 2001/07/05 15:19:40 wieck Exp $
*
* Copyright 2000 by PostgreSQL Global Development Group
#include "storage/proc.h"
#include "tcop/tcopprot.h"
#include "utils/datetime.h"
+#include "pgstat.h"
/* XXX these should be in other modules' header files */
{"show_btree_build_stats", PGC_SUSET, &Show_btree_build_stats, false, NULL},
#endif
+ {"collect_startcollector", PGC_POSTMASTER, &pgstat_collect_startcollector, true, NULL},
+ {"collect_resetonpmstart", PGC_POSTMASTER, &pgstat_collect_resetonpmstart, true, NULL},
+ {"collect_querystring", PGC_SUSET, &pgstat_collect_querystring, false, NULL},
+ {"collect_tuplelevel", PGC_SUSET, &pgstat_collect_tuplelevel, false, NULL},
+ {"collect_blocklevel", PGC_SUSET, &pgstat_collect_blocklevel, false, NULL},
+
{"trace_notify", PGC_USERSET, &Trace_notify, false, NULL},
#ifdef LOCK_DEBUG
#endif
+#
+# Access statistics collection
+#
+#collect_startcollector = true
+#collect_resetonpmstart = true
+#collect_querystring = false
+#collect_tuplelevel = false
+#collect_blocklevel = false
+
+
#
# Lock Tracing
#
*
* Copyright (c) 2001, PostgreSQL Global Development Group
*
- * $Id: pgstat.h,v 1.3 2001/06/29 23:03:02 tgl Exp $
+ * $Id: pgstat.h,v 1.4 2001/07/05 15:19:40 wieck Exp $
* ----------
*/
#ifndef PGSTAT_H
} PgStat_Msg;
-
+/* ----------
+ * Global variables
+ * ----------
+ */
+extern bool pgstat_collect_startcollector;
+extern bool pgstat_collect_resetonpmstart;
+extern bool pgstat_collect_querystring;
+extern bool pgstat_collect_tuplelevel;
+extern bool pgstat_collect_blocklevel;
/* ----------
* Functions called from postmaster
#define pgstat_reset_heap_scan(s) \
do { \
- if ((s)->tabentry != NULL) \
+ if (pgstat_collect_tuplelevel && (s)->tabentry != NULL) \
(s)->heap_scan_counted = FALSE; \
} while (0)
#define pgstat_count_heap_scan(s) \
do { \
- if ((s)->tabentry != NULL && !(s)->heap_scan_counted) { \
+ if (pgstat_collect_tuplelevel && (s)->tabentry != NULL && \
+ !(s)->heap_scan_counted) { \
((PgStat_TableEntry *)((s)->tabentry))->t_numscans++; \
(s)->heap_scan_counted = TRUE; \
} \
} while (0)
#define pgstat_count_heap_getnext(s) \
do { \
- if ((s)->tabentry != NULL) \
+ if (pgstat_collect_tuplelevel && (s)->tabentry != NULL) \
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_returned++; \
} while (0)
#define pgstat_count_heap_fetch(s) \
do { \
- if ((s)->tabentry != NULL) \
+ if (pgstat_collect_tuplelevel && (s)->tabentry != NULL) \
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_fetched++; \
} while (0)
#define pgstat_count_heap_insert(s) \
do { \
- if ((s)->tabentry != NULL) \
+ if (pgstat_collect_tuplelevel && (s)->tabentry != NULL) \
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_inserted++; \
} while (0)
#define pgstat_count_heap_update(s) \
do { \
- if ((s)->tabentry != NULL) \
+ if (pgstat_collect_tuplelevel && (s)->tabentry != NULL) \
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_updated++; \
} while (0)
#define pgstat_count_heap_delete(s) \
do { \
- if ((s)->tabentry != NULL) \
+ if (pgstat_collect_tuplelevel && (s)->tabentry != NULL) \
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_deleted++; \
} while (0)
#define pgstat_reset_index_scan(s) \
do { \
- if ((s)->tabentry != NULL) \
+ if (pgstat_collect_tuplelevel && (s)->tabentry != NULL) \
(s)->index_scan_counted = FALSE; \
} while (0)
#define pgstat_count_index_scan(s) \
do { \
- if ((s)->tabentry != NULL && !(s)->index_scan_counted) { \
+ if (pgstat_collect_tuplelevel && (s)->tabentry != NULL && \
+ !(s)->index_scan_counted) { \
((PgStat_TableEntry *)((s)->tabentry))->t_numscans++; \
(s)->index_scan_counted = TRUE; \
} \
} while (0)
#define pgstat_count_index_getnext(s) \
do { \
- if ((s)->tabentry != NULL) \
+ if (pgstat_collect_tuplelevel && (s)->tabentry != NULL) \
((PgStat_TableEntry *)((s)->tabentry))->t_tuples_returned++; \
} while (0)
#define pgstat_count_buffer_read(s,r) \
do { \
- if ((s)->tabentry != NULL) \
+ if (pgstat_collect_blocklevel && (s)->tabentry != NULL) \
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_fetched++; \
else { \
- if (!(s)->no_stats) { \
+ if (pgstat_collect_blocklevel && !(s)->no_stats) { \
pgstat_initstats((s), (r)); \
if ((s)->tabentry != NULL) \
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_fetched++; \
} while (0)
#define pgstat_count_buffer_hit(s,r) \
do { \
- if ((s)->tabentry != NULL) \
+ if (pgstat_collect_blocklevel && (s)->tabentry != NULL) \
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_hit++; \
else { \
- if (!(s)->no_stats) { \
+ if (pgstat_collect_blocklevel && !(s)->no_stats) { \
pgstat_initstats((s), (r)); \
if ((s)->tabentry != NULL) \
((PgStat_TableEntry *)((s)->tabentry))->t_blocks_hit++; \