X-Git-Url: https://granicus.if.org/sourcecode?a=blobdiff_plain;f=src%2Finclude%2Fexecutor%2Finstrument.h;h=9ecb5445f38edc065b90ab68d1771779bfd8dda6;hb=e126958c2efdfc2d60b978d1fc7a780ff647e8ad;hp=0540fd0da71cab07596e9575968bc7625c5426ff;hpb=adb1a6e95b2087e44c845edc15c28a87f5ba7ac1;p=postgresql diff --git a/src/include/executor/instrument.h b/src/include/executor/instrument.h index 0540fd0da7..9ecb5445f3 100644 --- a/src/include/executor/instrument.h +++ b/src/include/executor/instrument.h @@ -4,75 +4,64 @@ * definitions for run-time statistics collection * * - * Copyright (c) 2001-2005, PostgreSQL Global Development Group + * Copyright (c) 2001-2012, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/include/executor/instrument.h,v 1.10 2005/03/25 21:57:59 tgl Exp $ + * src/include/executor/instrument.h * *------------------------------------------------------------------------- */ #ifndef INSTRUMENT_H #define INSTRUMENT_H -#include +#include "portability/instr_time.h" -/* - * gettimeofday() does not have sufficient resolution on Windows, - * so we must use QueryPerformanceCounter() instead. These macros - * also give some breathing room to use other high-precision-timing APIs - * on yet other platforms. (The macro-ization is not complete, however; - * see subtraction code in instrument.c and explain.c.) - */ -#ifndef WIN32 - -typedef struct timeval instr_time; - -#define INSTR_TIME_IS_ZERO(t) ((t).tv_sec == 0 && (t).tv_usec == 0) -#define INSTR_TIME_SET_ZERO(t) ((t).tv_sec = 0, (t).tv_usec = 0) -#define INSTR_TIME_SET_CURRENT(t) gettimeofday(&(t), NULL) -#define INSTR_TIME_GET_DOUBLE(t) \ - (((double) (t).tv_sec) + ((double) (t).tv_usec) / 1000000.0) - -#else /* WIN32 */ - -typedef LARGE_INTEGER instr_time; - -#define INSTR_TIME_IS_ZERO(t) ((t).QuadPart == 0) -#define INSTR_TIME_SET_ZERO(t) ((t).QuadPart = 0) -#define INSTR_TIME_SET_CURRENT(t) QueryPerformanceCounter(&(t)) -#define INSTR_TIME_GET_DOUBLE(t) \ - (((double) (t).QuadPart) / GetTimerFrequency()) - -static __inline__ double -GetTimerFrequency(void) +typedef struct BufferUsage { - LARGE_INTEGER f; - - QueryPerformanceFrequency(&f); - return (double) f.QuadPart; -} - -#endif /* WIN32 */ + long shared_blks_hit; /* # of shared buffer hits */ + long shared_blks_read; /* # of shared disk blocks read */ + long shared_blks_written; /* # of shared disk blocks written */ + long local_blks_hit; /* # of local buffer hits */ + long local_blks_read; /* # of local disk blocks read */ + long local_blks_written; /* # of local disk blocks written */ + long temp_blks_read; /* # of temp blocks read */ + long temp_blks_written; /* # of temp blocks written */ +} BufferUsage; +/* Flag bits included in InstrAlloc's instrument_options bitmask */ +typedef enum InstrumentOption +{ + INSTRUMENT_TIMER = 1 << 0, /* needs timer */ + INSTRUMENT_BUFFERS = 1 << 1, /* needs buffer usage */ + INSTRUMENT_ALL = 0x7FFFFFFF +} InstrumentOption; typedef struct Instrumentation { + /* Parameters set at node creation: */ + bool need_bufusage; /* TRUE if we need buffer usage data */ /* Info about current plan cycle: */ bool running; /* TRUE if we've completed first tuple */ instr_time starttime; /* Start time of current iteration of node */ - instr_time counter; /* Accumulates runtime for this node */ + instr_time counter; /* Accumulated runtime for this node */ double firsttuple; /* Time for first tuple of this cycle */ - double tuplecount; /* Tuples so far this cycle */ + double tuplecount; /* Tuples emitted so far this cycle */ + BufferUsage bufusage_start; /* Buffer usage at start */ /* Accumulated statistics across all completed cycles: */ double startup; /* Total startup time (in seconds) */ double total; /* Total total time (in seconds) */ double ntuples; /* Total tuples produced */ double nloops; /* # of run cycles for this node */ + double nfiltered1; /* # tuples removed by scanqual or joinqual */ + double nfiltered2; /* # tuples removed by "other" quals */ + BufferUsage bufusage; /* Total buffer usage */ } Instrumentation; -extern Instrumentation *InstrAlloc(int n); +extern PGDLLIMPORT BufferUsage pgBufferUsage; + +extern Instrumentation *InstrAlloc(int n, int instrument_options); extern void InstrStartNode(Instrumentation *instr); -extern void InstrStopNode(Instrumentation *instr, bool returnedTuple); +extern void InstrStopNode(Instrumentation *instr, double nTuples); extern void InstrEndLoop(Instrumentation *instr); #endif /* INSTRUMENT_H */