PostgreSQL Source Code  git master
instrument.h File Reference
Include dependency graph for instrument.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  BufferUsage
 
struct  Instrumentation
 
struct  WorkerInstrumentation
 

Typedefs

typedef struct BufferUsage BufferUsage
 
typedef enum InstrumentOption InstrumentOption
 
typedef struct Instrumentation Instrumentation
 
typedef struct WorkerInstrumentation WorkerInstrumentation
 

Enumerations

enum  InstrumentOption { INSTRUMENT_TIMER = 1 << 0, INSTRUMENT_BUFFERS = 1 << 1, INSTRUMENT_ROWS = 1 << 2, INSTRUMENT_ALL = PG_INT32_MAX }
 

Functions

InstrumentationInstrAlloc (int n, int instrument_options)
 
void InstrInit (Instrumentation *instr, int instrument_options)
 
void InstrStartNode (Instrumentation *instr)
 
void InstrStopNode (Instrumentation *instr, double nTuples)
 
void InstrEndLoop (Instrumentation *instr)
 
void InstrAggNode (Instrumentation *dst, Instrumentation *add)
 
void InstrStartParallelQuery (void)
 
void InstrEndParallelQuery (BufferUsage *result)
 
void InstrAccumParallelQuery (BufferUsage *result)
 

Variables

PGDLLIMPORT BufferUsage pgBufferUsage
 

Typedef Documentation

◆ BufferUsage

◆ Instrumentation

◆ InstrumentOption

◆ WorkerInstrumentation

Enumeration Type Documentation

◆ InstrumentOption

Enumerator
INSTRUMENT_TIMER 
INSTRUMENT_BUFFERS 
INSTRUMENT_ROWS 
INSTRUMENT_ALL 

Definition at line 36 of file instrument.h.

37 {
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 */
InstrumentOption
Definition: instrument.h:36
#define PG_INT32_MAX
Definition: c.h:441

Function Documentation

◆ InstrAccumParallelQuery()

void InstrAccumParallelQuery ( BufferUsage result)

Definition at line 182 of file instrument.c.

References BufferUsageAdd().

Referenced by ExecParallelFinish().

183 {
184  BufferUsageAdd(&pgBufferUsage, result);
185 }
static void BufferUsageAdd(BufferUsage *dst, const BufferUsage *add)
Definition: instrument.c:189
BufferUsage pgBufferUsage
Definition: instrument.c:20

◆ InstrAggNode()

void InstrAggNode ( Instrumentation dst,
Instrumentation add 
)

Definition at line 139 of file instrument.c.

References BufferUsageAdd(), Instrumentation::bufusage, Instrumentation::counter, Instrumentation::firsttuple, INSTR_TIME_ADD, Instrumentation::need_bufusage, Instrumentation::nfiltered1, Instrumentation::nfiltered2, Instrumentation::nloops, Instrumentation::ntuples, Instrumentation::ntuples2, Instrumentation::running, Instrumentation::startup, Instrumentation::total, and Instrumentation::tuplecount.

Referenced by ExecParallelReportInstrumentation(), and ExecParallelRetrieveInstrumentation().

140 {
141  if (!dst->running && add->running)
142  {
143  dst->running = true;
144  dst->firsttuple = add->firsttuple;
145  }
146  else if (dst->running && add->running && dst->firsttuple > add->firsttuple)
147  dst->firsttuple = add->firsttuple;
148 
149  INSTR_TIME_ADD(dst->counter, add->counter);
150 
151  dst->tuplecount += add->tuplecount;
152  dst->startup += add->startup;
153  dst->total += add->total;
154  dst->ntuples += add->ntuples;
155  dst->ntuples2 += add->ntuples2;
156  dst->nloops += add->nloops;
157  dst->nfiltered1 += add->nfiltered1;
158  dst->nfiltered2 += add->nfiltered2;
159 
160  /* Add delta of buffer usage since entry to node's totals */
161  if (dst->need_bufusage)
162  BufferUsageAdd(&dst->bufusage, &add->bufusage);
163 }
double nfiltered1
Definition: instrument.h:62
bool need_bufusage
Definition: instrument.h:48
double startup
Definition: instrument.h:57
double firsttuple
Definition: instrument.h:53
double nfiltered2
Definition: instrument.h:63
#define INSTR_TIME_ADD(x, y)
Definition: instr_time.h:158
double ntuples
Definition: instrument.h:59
double tuplecount
Definition: instrument.h:54
BufferUsage bufusage
Definition: instrument.h:64
instr_time counter
Definition: instrument.h:52
double ntuples2
Definition: instrument.h:60
static void BufferUsageAdd(BufferUsage *dst, const BufferUsage *add)
Definition: instrument.c:189

◆ InstrAlloc()

Instrumentation* InstrAlloc ( int  n,
int  instrument_options 
)

Definition at line 30 of file instrument.c.

References i, INSTRUMENT_BUFFERS, INSTRUMENT_TIMER, Instrumentation::need_bufusage, Instrumentation::need_timer, and palloc0().

Referenced by ExecInitNode(), explain_ExecutorStart(), InitResultRelInfo(), and pgss_ExecutorStart().

31 {
32  Instrumentation *instr;
33 
34  /* initialize all fields to zeroes, then modify as needed */
35  instr = palloc0(n * sizeof(Instrumentation));
36  if (instrument_options & (INSTRUMENT_BUFFERS | INSTRUMENT_TIMER))
37  {
38  bool need_buffers = (instrument_options & INSTRUMENT_BUFFERS) != 0;
39  bool need_timer = (instrument_options & INSTRUMENT_TIMER) != 0;
40  int i;
41 
42  for (i = 0; i < n; i++)
43  {
44  instr[i].need_bufusage = need_buffers;
45  instr[i].need_timer = need_timer;
46  }
47  }
48 
49  return instr;
50 }
bool need_bufusage
Definition: instrument.h:48
void * palloc0(Size size)
Definition: mcxt.c:955
int i

◆ InstrEndLoop()

void InstrEndLoop ( Instrumentation instr)

Definition at line 110 of file instrument.c.

References Instrumentation::counter, elog, ERROR, Instrumentation::firsttuple, INSTR_TIME_GET_DOUBLE, INSTR_TIME_IS_ZERO, INSTR_TIME_SET_ZERO, Instrumentation::nloops, Instrumentation::ntuples, Instrumentation::running, Instrumentation::starttime, Instrumentation::startup, Instrumentation::total, and Instrumentation::tuplecount.

Referenced by ExecParallelReportInstrumentation(), ExecReScan(), explain_ExecutorEnd(), ExplainNode(), pgss_ExecutorEnd(), report_triggers(), and show_modifytable_info().

111 {
112  double totaltime;
113 
114  /* Skip if nothing has happened, or already shut down */
115  if (!instr->running)
116  return;
117 
118  if (!INSTR_TIME_IS_ZERO(instr->starttime))
119  elog(ERROR, "InstrEndLoop called on running node");
120 
121  /* Accumulate per-cycle statistics into totals */
122  totaltime = INSTR_TIME_GET_DOUBLE(instr->counter);
123 
124  instr->startup += instr->firsttuple;
125  instr->total += totaltime;
126  instr->ntuples += instr->tuplecount;
127  instr->nloops += 1;
128 
129  /* Reset for next cycle (if any) */
130  instr->running = false;
133  instr->firsttuple = 0;
134  instr->tuplecount = 0;
135 }
double startup
Definition: instrument.h:57
#define INSTR_TIME_SET_ZERO(t)
Definition: instr_time.h:154
#define INSTR_TIME_GET_DOUBLE(t)
Definition: instr_time.h:199
#define INSTR_TIME_IS_ZERO(t)
Definition: instr_time.h:152
#define ERROR
Definition: elog.h:43
double firsttuple
Definition: instrument.h:53
instr_time starttime
Definition: instrument.h:51
double ntuples
Definition: instrument.h:59
double tuplecount
Definition: instrument.h:54
instr_time counter
Definition: instrument.h:52
#define elog(elevel,...)
Definition: elog.h:226

◆ InstrEndParallelQuery()

void InstrEndParallelQuery ( BufferUsage result)

Definition at line 174 of file instrument.c.

References BufferUsageAccumDiff().

Referenced by ParallelQueryMain().

175 {
176  memset(result, 0, sizeof(BufferUsage));
178 }
static BufferUsage save_pgBufferUsage
Definition: instrument.c:21
static void BufferUsageAccumDiff(BufferUsage *dst, const BufferUsage *add, const BufferUsage *sub)
Definition: instrument.c:207
BufferUsage pgBufferUsage
Definition: instrument.c:20

◆ InstrInit()

void InstrInit ( Instrumentation instr,
int  instrument_options 
)

Definition at line 54 of file instrument.c.

References INSTRUMENT_BUFFERS, INSTRUMENT_TIMER, Instrumentation::need_bufusage, and Instrumentation::need_timer.

Referenced by ExecInitParallelPlan().

55 {
56  memset(instr, 0, sizeof(Instrumentation));
57  instr->need_bufusage = (instrument_options & INSTRUMENT_BUFFERS) != 0;
58  instr->need_timer = (instrument_options & INSTRUMENT_TIMER) != 0;
59 }
bool need_bufusage
Definition: instrument.h:48

◆ InstrStartNode()

void InstrStartNode ( Instrumentation instr)

Definition at line 63 of file instrument.c.

References Instrumentation::bufusage_start, elog, ERROR, INSTR_TIME_SET_CURRENT_LAZY, Instrumentation::need_bufusage, Instrumentation::need_timer, pgBufferUsage, and Instrumentation::starttime.

Referenced by AfterTriggerExecute(), ExecCallTriggerFunc(), ExecProcNodeInstr(), ExecShutdownNode(), MultiExecBitmapAnd(), MultiExecBitmapIndexScan(), MultiExecBitmapOr(), MultiExecHash(), standard_ExecutorFinish(), and standard_ExecutorRun().

64 {
65  if (instr->need_timer &&
67  elog(ERROR, "InstrStartNode called twice in a row");
68 
69  /* save buffer usage totals at node entry, if needed */
70  if (instr->need_bufusage)
72 }
bool need_bufusage
Definition: instrument.h:48
BufferUsage bufusage_start
Definition: instrument.h:55
#define ERROR
Definition: elog.h:43
instr_time starttime
Definition: instrument.h:51
#define INSTR_TIME_SET_CURRENT_LAZY(t)
Definition: instr_time.h:253
#define elog(elevel,...)
Definition: elog.h:226
BufferUsage pgBufferUsage
Definition: instrument.c:20

◆ InstrStartParallelQuery()

void InstrStartParallelQuery ( void  )

Definition at line 167 of file instrument.c.

References pgBufferUsage.

Referenced by ParallelQueryMain().

168 {
170 }
static BufferUsage save_pgBufferUsage
Definition: instrument.c:21
BufferUsage pgBufferUsage
Definition: instrument.c:20

◆ InstrStopNode()

void InstrStopNode ( Instrumentation instr,
double  nTuples 
)

Definition at line 76 of file instrument.c.

References BufferUsageAccumDiff(), Instrumentation::bufusage, Instrumentation::bufusage_start, Instrumentation::counter, elog, ERROR, Instrumentation::firsttuple, INSTR_TIME_ACCUM_DIFF, INSTR_TIME_GET_DOUBLE, INSTR_TIME_IS_ZERO, INSTR_TIME_SET_CURRENT, INSTR_TIME_SET_ZERO, Instrumentation::need_bufusage, Instrumentation::need_timer, Instrumentation::running, Instrumentation::starttime, and Instrumentation::tuplecount.

Referenced by AfterTriggerExecute(), ExecCallTriggerFunc(), ExecProcNodeInstr(), ExecShutdownNode(), MultiExecBitmapAnd(), MultiExecBitmapIndexScan(), MultiExecBitmapOr(), MultiExecHash(), standard_ExecutorFinish(), and standard_ExecutorRun().

77 {
78  instr_time endtime;
79 
80  /* count the returned tuples */
81  instr->tuplecount += nTuples;
82 
83  /* let's update the time only if the timer was requested */
84  if (instr->need_timer)
85  {
86  if (INSTR_TIME_IS_ZERO(instr->starttime))
87  elog(ERROR, "InstrStopNode called without start");
88 
89  INSTR_TIME_SET_CURRENT(endtime);
90  INSTR_TIME_ACCUM_DIFF(instr->counter, endtime, instr->starttime);
91 
93  }
94 
95  /* Add delta of buffer usage since entry to node's totals */
96  if (instr->need_bufusage)
98  &pgBufferUsage, &instr->bufusage_start);
99 
100  /* Is this the first tuple of this cycle? */
101  if (!instr->running)
102  {
103  instr->running = true;
104  instr->firsttuple = INSTR_TIME_GET_DOUBLE(instr->counter);
105  }
106 }
bool need_bufusage
Definition: instrument.h:48
struct timeval instr_time
Definition: instr_time.h:150
#define INSTR_TIME_ACCUM_DIFF(x, y, z)
Definition: instr_time.h:182
#define INSTR_TIME_SET_ZERO(t)
Definition: instr_time.h:154
#define INSTR_TIME_GET_DOUBLE(t)
Definition: instr_time.h:199
#define INSTR_TIME_IS_ZERO(t)
Definition: instr_time.h:152
BufferUsage bufusage_start
Definition: instrument.h:55
#define ERROR
Definition: elog.h:43
double firsttuple
Definition: instrument.h:53
instr_time starttime
Definition: instrument.h:51
static void BufferUsageAccumDiff(BufferUsage *dst, const BufferUsage *add, const BufferUsage *sub)
Definition: instrument.c:207
double tuplecount
Definition: instrument.h:54
BufferUsage bufusage
Definition: instrument.h:64
instr_time counter
Definition: instrument.h:52
#define INSTR_TIME_SET_CURRENT(t)
Definition: instr_time.h:156
#define elog(elevel,...)
Definition: elog.h:226
BufferUsage pgBufferUsage
Definition: instrument.c:20

Variable Documentation

◆ pgBufferUsage