]> granicus.if.org Git - postgresql/blob - src/include/executor/instrument.h
Add an EXPLAIN (BUFFERS) option to show buffer-usage statistics.
[postgresql] / src / include / executor / instrument.h
1 /*-------------------------------------------------------------------------
2  *
3  * instrument.h
4  *        definitions for run-time statistics collection
5  *
6  *
7  * Copyright (c) 2001-2009, PostgreSQL Global Development Group
8  *
9  * $PostgreSQL: pgsql/src/include/executor/instrument.h,v 1.21 2009/12/15 04:57:48 rhaas Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef INSTRUMENT_H
14 #define INSTRUMENT_H
15
16 #include "portability/instr_time.h"
17
18
19 typedef struct BufferUsage
20 {
21         long    shared_blks_hit;                /* # of shared buffer hits */
22         long    shared_blks_read;               /* # of shared disk blocks read */
23         long    shared_blks_written;    /* # of shared disk blocks written */
24         long    local_blks_hit;                 /* # of local buffer hits */
25         long    local_blks_read;                /* # of local disk blocks read */
26         long    local_blks_written;             /* # of local disk blocks written */
27         long    temp_blks_read;                 /* # of temp blocks read */
28         long    temp_blks_written;              /* # of temp blocks written */
29 } BufferUsage;
30
31 typedef enum InstrumentOption
32 {
33         INSTRUMENT_TIMER        = 1 << 0,               /* needs timer */
34         INSTRUMENT_BUFFERS      = 1 << 1,               /* needs buffer usage */
35         INSTRUMENT_ALL          = 0x7FFFFFFF
36 } InstrumentOption;
37
38 typedef struct Instrumentation
39 {
40         /* Info about current plan cycle: */
41         bool            running;                /* TRUE if we've completed first tuple */
42         bool            needs_bufusage; /* TRUE if we need buffer usage */
43         instr_time      starttime;              /* Start time of current iteration of node */
44         instr_time      counter;                /* Accumulated runtime for this node */
45         double          firsttuple;             /* Time for first tuple of this cycle */
46         double          tuplecount;             /* Tuples emitted so far this cycle */
47         BufferUsage     bufusage_start; /* Buffer usage at start */
48         /* Accumulated statistics across all completed cycles: */
49         double          startup;                /* Total startup time (in seconds) */
50         double          total;                  /* Total total time (in seconds) */
51         double          ntuples;                /* Total tuples produced */
52         double          nloops;                 /* # of run cycles for this node */
53         BufferUsage     bufusage;               /* Total buffer usage */
54 } Instrumentation;
55
56 extern BufferUsage              pgBufferUsage;
57
58 extern Instrumentation *InstrAlloc(int n, int instrument_options);
59 extern void InstrStartNode(Instrumentation *instr);
60 extern void InstrStopNode(Instrumentation *instr, double nTuples);
61 extern void InstrEndLoop(Instrumentation *instr);
62
63 #endif   /* INSTRUMENT_H */