1 /*-------------------------------------------------------------------------
4 * definitions for run-time statistics collection
7 * Copyright (c) 2001-2015, PostgreSQL Global Development Group
9 * src/include/executor/instrument.h
11 *-------------------------------------------------------------------------
16 #include "portability/instr_time.h"
19 typedef struct BufferUsage
21 long shared_blks_hit; /* # of shared buffer hits */
22 long shared_blks_read; /* # of shared disk blocks read */
23 long shared_blks_dirtied; /* # of shared blocks dirtied */
24 long shared_blks_written; /* # of shared disk blocks written */
25 long local_blks_hit; /* # of local buffer hits */
26 long local_blks_read; /* # of local disk blocks read */
27 long local_blks_dirtied; /* # of shared blocks dirtied */
28 long local_blks_written; /* # of local disk blocks written */
29 long temp_blks_read; /* # of temp blocks read */
30 long temp_blks_written; /* # of temp blocks written */
31 instr_time blk_read_time; /* time spent reading */
32 instr_time blk_write_time; /* time spent writing */
35 /* Flag bits included in InstrAlloc's instrument_options bitmask */
36 typedef enum InstrumentOption
38 INSTRUMENT_TIMER = 1 << 0, /* needs timer (and row counts) */
39 INSTRUMENT_BUFFERS = 1 << 1, /* needs buffer usage */
40 INSTRUMENT_ROWS = 1 << 2, /* needs row count */
41 INSTRUMENT_ALL = INT32_MAX
44 typedef struct Instrumentation
46 /* Parameters set at node creation: */
47 bool need_timer; /* TRUE if we need timer data */
48 bool need_bufusage; /* TRUE if we need buffer usage data */
49 /* Info about current plan cycle: */
50 bool running; /* TRUE if we've completed first tuple */
51 instr_time starttime; /* Start time of current iteration of node */
52 instr_time counter; /* Accumulated runtime for this node */
53 double firsttuple; /* Time for first tuple of this cycle */
54 double tuplecount; /* Tuples emitted so far this cycle */
55 BufferUsage bufusage_start; /* Buffer usage at start */
56 /* Accumulated statistics across all completed cycles: */
57 double startup; /* Total startup time (in seconds) */
58 double total; /* Total total time (in seconds) */
59 double ntuples; /* Total tuples produced */
60 double nloops; /* # of run cycles for this node */
61 double nfiltered1; /* # tuples removed by scanqual or joinqual */
62 double nfiltered2; /* # tuples removed by "other" quals */
63 BufferUsage bufusage; /* Total buffer usage */
66 extern PGDLLIMPORT BufferUsage pgBufferUsage;
68 extern Instrumentation *InstrAlloc(int n, int instrument_options);
69 extern void InstrStartNode(Instrumentation *instr);
70 extern void InstrStopNode(Instrumentation *instr, double nTuples);
71 extern void InstrEndLoop(Instrumentation *instr);
73 #endif /* INSTRUMENT_H */