00001 /*------------------------------------------------------------------------- 00002 * 00003 * instrument.h 00004 * definitions for run-time statistics collection 00005 * 00006 * 00007 * Copyright (c) 2001-2013, PostgreSQL Global Development Group 00008 * 00009 * src/include/executor/instrument.h 00010 * 00011 *------------------------------------------------------------------------- 00012 */ 00013 #ifndef INSTRUMENT_H 00014 #define INSTRUMENT_H 00015 00016 #include "portability/instr_time.h" 00017 00018 00019 typedef struct BufferUsage 00020 { 00021 long shared_blks_hit; /* # of shared buffer hits */ 00022 long shared_blks_read; /* # of shared disk blocks read */ 00023 long shared_blks_dirtied; /* # of shared blocks dirtied */ 00024 long shared_blks_written; /* # of shared disk blocks written */ 00025 long local_blks_hit; /* # of local buffer hits */ 00026 long local_blks_read; /* # of local disk blocks read */ 00027 long local_blks_dirtied; /* # of shared blocks dirtied */ 00028 long local_blks_written; /* # of local disk blocks written */ 00029 long temp_blks_read; /* # of temp blocks read */ 00030 long temp_blks_written; /* # of temp blocks written */ 00031 instr_time blk_read_time; /* time spent reading */ 00032 instr_time blk_write_time; /* time spent writing */ 00033 } BufferUsage; 00034 00035 /* Flag bits included in InstrAlloc's instrument_options bitmask */ 00036 typedef enum InstrumentOption 00037 { 00038 INSTRUMENT_TIMER = 1 << 0, /* needs timer (and row counts) */ 00039 INSTRUMENT_BUFFERS = 1 << 1, /* needs buffer usage */ 00040 INSTRUMENT_ROWS = 1 << 2, /* needs row count */ 00041 INSTRUMENT_ALL = 0x7FFFFFFF 00042 } InstrumentOption; 00043 00044 typedef struct Instrumentation 00045 { 00046 /* Parameters set at node creation: */ 00047 bool need_timer; /* TRUE if we need timer data */ 00048 bool need_bufusage; /* TRUE if we need buffer usage data */ 00049 /* Info about current plan cycle: */ 00050 bool running; /* TRUE if we've completed first tuple */ 00051 instr_time starttime; /* Start time of current iteration of node */ 00052 instr_time counter; /* Accumulated runtime for this node */ 00053 double firsttuple; /* Time for first tuple of this cycle */ 00054 double tuplecount; /* Tuples emitted so far this cycle */ 00055 BufferUsage bufusage_start; /* Buffer usage at start */ 00056 /* Accumulated statistics across all completed cycles: */ 00057 double startup; /* Total startup time (in seconds) */ 00058 double total; /* Total total time (in seconds) */ 00059 double ntuples; /* Total tuples produced */ 00060 double nloops; /* # of run cycles for this node */ 00061 double nfiltered1; /* # tuples removed by scanqual or joinqual */ 00062 double nfiltered2; /* # tuples removed by "other" quals */ 00063 BufferUsage bufusage; /* Total buffer usage */ 00064 } Instrumentation; 00065 00066 extern PGDLLIMPORT BufferUsage pgBufferUsage; 00067 00068 extern Instrumentation *InstrAlloc(int n, int instrument_options); 00069 extern void InstrStartNode(Instrumentation *instr); 00070 extern void InstrStopNode(Instrumentation *instr, double nTuples); 00071 extern void InstrEndLoop(Instrumentation *instr); 00072 00073 #endif /* INSTRUMENT_H */