PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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  WalUsage
 
struct  Instrumentation
 
struct  WorkerInstrumentation
 

Typedefs

typedef struct BufferUsage BufferUsage
 
typedef struct WalUsage WalUsage
 
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_WAL = 1 << 3 ,
  INSTRUMENT_ALL = PG_INT32_MAX
}
 

Functions

InstrumentationInstrAlloc (int n, int instrument_options, bool async_mode)
 
void InstrInit (Instrumentation *instr, int instrument_options)
 
void InstrStartNode (Instrumentation *instr)
 
void InstrStopNode (Instrumentation *instr, double nTuples)
 
void InstrUpdateTupleCount (Instrumentation *instr, double nTuples)
 
void InstrEndLoop (Instrumentation *instr)
 
void InstrAggNode (Instrumentation *dst, Instrumentation *add)
 
void InstrStartParallelQuery (void)
 
void InstrEndParallelQuery (BufferUsage *bufusage, WalUsage *walusage)
 
void InstrAccumParallelQuery (BufferUsage *bufusage, WalUsage *walusage)
 
void BufferUsageAccumDiff (BufferUsage *dst, const BufferUsage *add, const BufferUsage *sub)
 
void WalUsageAccumDiff (WalUsage *dst, const WalUsage *add, const WalUsage *sub)
 

Variables

PGDLLIMPORT BufferUsage pgBufferUsage
 
PGDLLIMPORT WalUsage pgWalUsage
 

Typedef Documentation

◆ BufferUsage

◆ Instrumentation

◆ InstrumentOption

◆ WalUsage

◆ WorkerInstrumentation

Enumeration Type Documentation

◆ InstrumentOption

Enumerator
INSTRUMENT_TIMER 
INSTRUMENT_BUFFERS 
INSTRUMENT_ROWS 
INSTRUMENT_WAL 
INSTRUMENT_ALL 

Definition at line 61 of file instrument.h.

62{
63 INSTRUMENT_TIMER = 1 << 0, /* needs timer (and row counts) */
64 INSTRUMENT_BUFFERS = 1 << 1, /* needs buffer usage */
65 INSTRUMENT_ROWS = 1 << 2, /* needs row count */
66 INSTRUMENT_WAL = 1 << 3, /* needs WAL usage */
#define PG_INT32_MAX
Definition c.h:615
InstrumentOption
Definition instrument.h:62
@ INSTRUMENT_ALL
Definition instrument.h:67
@ INSTRUMENT_TIMER
Definition instrument.h:63
@ INSTRUMENT_BUFFERS
Definition instrument.h:64
@ INSTRUMENT_WAL
Definition instrument.h:66
@ INSTRUMENT_ROWS
Definition instrument.h:65

Function Documentation

◆ BufferUsageAccumDiff()

void BufferUsageAccumDiff ( BufferUsage dst,
const BufferUsage add,
const BufferUsage sub 
)
extern

Definition at line 249 of file instrument.c.

252{
253 dst->shared_blks_hit += add->shared_blks_hit - sub->shared_blks_hit;
254 dst->shared_blks_read += add->shared_blks_read - sub->shared_blks_read;
255 dst->shared_blks_dirtied += add->shared_blks_dirtied - sub->shared_blks_dirtied;
256 dst->shared_blks_written += add->shared_blks_written - sub->shared_blks_written;
257 dst->local_blks_hit += add->local_blks_hit - sub->local_blks_hit;
258 dst->local_blks_read += add->local_blks_read - sub->local_blks_read;
259 dst->local_blks_dirtied += add->local_blks_dirtied - sub->local_blks_dirtied;
260 dst->local_blks_written += add->local_blks_written - sub->local_blks_written;
261 dst->temp_blks_read += add->temp_blks_read - sub->temp_blks_read;
262 dst->temp_blks_written += add->temp_blks_written - sub->temp_blks_written;
263 INSTR_TIME_ACCUM_DIFF(dst->shared_blk_read_time,
264 add->shared_blk_read_time, sub->shared_blk_read_time);
265 INSTR_TIME_ACCUM_DIFF(dst->shared_blk_write_time,
266 add->shared_blk_write_time, sub->shared_blk_write_time);
267 INSTR_TIME_ACCUM_DIFF(dst->local_blk_read_time,
268 add->local_blk_read_time, sub->local_blk_read_time);
269 INSTR_TIME_ACCUM_DIFF(dst->local_blk_write_time,
270 add->local_blk_write_time, sub->local_blk_write_time);
271 INSTR_TIME_ACCUM_DIFF(dst->temp_blk_read_time,
272 add->temp_blk_read_time, sub->temp_blk_read_time);
273 INSTR_TIME_ACCUM_DIFF(dst->temp_blk_write_time,
274 add->temp_blk_write_time, sub->temp_blk_write_time);
275}
#define INSTR_TIME_ACCUM_DIFF(x, y, z)
Definition instr_time.h:180
static int fb(int x)
instr_time local_blk_read_time
Definition instrument.h:38
int64 shared_blks_dirtied
Definition instrument.h:28
int64 local_blks_hit
Definition instrument.h:30
instr_time temp_blk_write_time
Definition instrument.h:41
instr_time shared_blk_read_time
Definition instrument.h:36
instr_time shared_blk_write_time
Definition instrument.h:37
int64 local_blks_written
Definition instrument.h:33
instr_time temp_blk_read_time
Definition instrument.h:40
instr_time local_blk_write_time
Definition instrument.h:39
int64 temp_blks_read
Definition instrument.h:34
int64 shared_blks_read
Definition instrument.h:27
int64 shared_blks_written
Definition instrument.h:29
int64 temp_blks_written
Definition instrument.h:35
int64 local_blks_read
Definition instrument.h:31
int64 local_blks_dirtied
Definition instrument.h:32
int64 shared_blks_hit
Definition instrument.h:26

References fb(), INSTR_TIME_ACCUM_DIFF, BufferUsage::local_blk_read_time, BufferUsage::local_blk_write_time, BufferUsage::local_blks_dirtied, BufferUsage::local_blks_hit, BufferUsage::local_blks_read, BufferUsage::local_blks_written, BufferUsage::shared_blk_read_time, BufferUsage::shared_blk_write_time, BufferUsage::shared_blks_dirtied, BufferUsage::shared_blks_hit, BufferUsage::shared_blks_read, BufferUsage::shared_blks_written, BufferUsage::temp_blk_read_time, BufferUsage::temp_blk_write_time, BufferUsage::temp_blks_read, and BufferUsage::temp_blks_written.

Referenced by do_analyze_rel(), ExplainExecuteQuery(), heap_vacuum_rel(), InstrEndParallelQuery(), InstrStopNode(), pgss_planner(), pgss_ProcessUtility(), serializeAnalyzeReceive(), and standard_ExplainOneQuery().

◆ InstrAccumParallelQuery()

void InstrAccumParallelQuery ( BufferUsage bufusage,
WalUsage walusage 
)
extern

Definition at line 219 of file instrument.c.

220{
221 BufferUsageAdd(&pgBufferUsage, bufusage);
222 WalUsageAdd(&pgWalUsage, walusage);
223}
static void BufferUsageAdd(BufferUsage *dst, const BufferUsage *add)
Definition instrument.c:227
static void WalUsageAdd(WalUsage *dst, WalUsage *add)
Definition instrument.c:279
WalUsage pgWalUsage
Definition instrument.c:22
BufferUsage pgBufferUsage
Definition instrument.c:20

References BufferUsageAdd(), pgBufferUsage, pgWalUsage, and WalUsageAdd().

Referenced by _brin_end_parallel(), _bt_end_parallel(), _gin_end_parallel(), ExecParallelFinish(), and parallel_vacuum_process_all_indexes().

◆ InstrAggNode()

void InstrAggNode ( Instrumentation dst,
Instrumentation add 
)
extern

Definition at line 169 of file instrument.c.

170{
171 if (!dst->running && add->running)
172 {
173 dst->running = true;
174 dst->firsttuple = add->firsttuple;
175 }
176 else if (dst->running && add->running &&
177 INSTR_TIME_GT(dst->firsttuple, add->firsttuple))
178 dst->firsttuple = add->firsttuple;
179
180 INSTR_TIME_ADD(dst->counter, add->counter);
181
182 dst->tuplecount += add->tuplecount;
183 INSTR_TIME_ADD(dst->startup, add->startup);
184 INSTR_TIME_ADD(dst->total, add->total);
185 dst->ntuples += add->ntuples;
186 dst->ntuples2 += add->ntuples2;
187 dst->nloops += add->nloops;
188 dst->nfiltered1 += add->nfiltered1;
189 dst->nfiltered2 += add->nfiltered2;
190
191 /* Add delta of buffer usage since entry to node's totals */
192 if (dst->need_bufusage)
193 BufferUsageAdd(&dst->bufusage, &add->bufusage);
194
195 if (dst->need_walusage)
196 WalUsageAdd(&dst->walusage, &add->walusage);
197}
#define INSTR_TIME_GT(x, y)
Definition instr_time.h:183
#define INSTR_TIME_ADD(x, y)
Definition instr_time.h:174

References BufferUsageAdd(), fb(), INSTR_TIME_ADD, INSTR_TIME_GT, and WalUsageAdd().

Referenced by ExecParallelReportInstrumentation(), and ExecParallelRetrieveInstrumentation().

◆ InstrAlloc()

Instrumentation * InstrAlloc ( int  n,
int  instrument_options,
bool  async_mode 
)
extern

Definition at line 31 of file instrument.c.

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

References Instrumentation::async_mode, fb(), i, INSTRUMENT_BUFFERS, INSTRUMENT_TIMER, INSTRUMENT_WAL, Instrumentation::need_bufusage, Instrumentation::need_timer, Instrumentation::need_walusage, and palloc0().

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

◆ InstrEndLoop()

void InstrEndLoop ( Instrumentation instr)
extern

Definition at line 144 of file instrument.c.

145{
146 /* Skip if nothing has happened, or already shut down */
147 if (!instr->running)
148 return;
149
150 if (!INSTR_TIME_IS_ZERO(instr->starttime))
151 elog(ERROR, "InstrEndLoop called on running node");
152
153 /* Accumulate per-cycle statistics into totals */
154 INSTR_TIME_ADD(instr->startup, instr->firsttuple);
155 INSTR_TIME_ADD(instr->total, instr->counter);
156 instr->ntuples += instr->tuplecount;
157 instr->nloops += 1;
158
159 /* Reset for next cycle (if any) */
160 instr->running = false;
164 instr->tuplecount = 0;
165}
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
#define INSTR_TIME_IS_ZERO(t)
Definition instr_time.h:169
#define INSTR_TIME_SET_ZERO(t)
Definition instr_time.h:171
instr_time total
Definition instrument.h:87
instr_time starttime
Definition instrument.h:79
instr_time counter
Definition instrument.h:80
instr_time firsttuple
Definition instrument.h:81
double tuplecount
Definition instrument.h:82
instr_time startup
Definition instrument.h:86

References Instrumentation::counter, elog, ERROR, Instrumentation::firsttuple, INSTR_TIME_ADD, 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().

◆ InstrEndParallelQuery()

void InstrEndParallelQuery ( BufferUsage bufusage,
WalUsage walusage 
)
extern

Definition at line 209 of file instrument.c.

210{
211 memset(bufusage, 0, sizeof(BufferUsage));
213 memset(walusage, 0, sizeof(WalUsage));
215}
static BufferUsage save_pgBufferUsage
Definition instrument.c:21
static WalUsage save_pgWalUsage
Definition instrument.c:23
void WalUsageAccumDiff(WalUsage *dst, const WalUsage *add, const WalUsage *sub)
Definition instrument.c:289
void BufferUsageAccumDiff(BufferUsage *dst, const BufferUsage *add, const BufferUsage *sub)
Definition instrument.c:249

References BufferUsageAccumDiff(), fb(), pgBufferUsage, pgWalUsage, save_pgBufferUsage, save_pgWalUsage, and WalUsageAccumDiff().

Referenced by _brin_parallel_build_main(), _bt_parallel_build_main(), _gin_parallel_build_main(), parallel_vacuum_main(), and ParallelQueryMain().

◆ InstrInit()

void InstrInit ( Instrumentation instr,
int  instrument_options 
)
extern

Definition at line 58 of file instrument.c.

59{
60 memset(instr, 0, sizeof(Instrumentation));
61 instr->need_bufusage = (instrument_options & INSTRUMENT_BUFFERS) != 0;
62 instr->need_walusage = (instrument_options & INSTRUMENT_WAL) != 0;
63 instr->need_timer = (instrument_options & INSTRUMENT_TIMER) != 0;
64}

References fb(), INSTRUMENT_BUFFERS, INSTRUMENT_TIMER, INSTRUMENT_WAL, Instrumentation::need_bufusage, Instrumentation::need_timer, and Instrumentation::need_walusage.

Referenced by ExecInitParallelPlan().

◆ InstrStartNode()

◆ InstrStartParallelQuery()

◆ InstrStopNode()

void InstrStopNode ( Instrumentation instr,
double  nTuples 
)
extern

Definition at line 88 of file instrument.c.

89{
90 double save_tuplecount = instr->tuplecount;
92
93 /* count the returned tuples */
94 instr->tuplecount += nTuples;
95
96 /* let's update the time only if the timer was requested */
97 if (instr->need_timer)
98 {
99 if (INSTR_TIME_IS_ZERO(instr->starttime))
100 elog(ERROR, "InstrStopNode called without start");
101
104
106 }
107
108 /* Add delta of buffer usage since entry to node's totals */
109 if (instr->need_bufusage)
111 &pgBufferUsage, &instr->bufusage_start);
112
113 if (instr->need_walusage)
115 &pgWalUsage, &instr->walusage_start);
116
117 /* Is this the first tuple of this cycle? */
118 if (!instr->running)
119 {
120 instr->running = true;
121 instr->firsttuple = instr->counter;
122 }
123 else
124 {
125 /*
126 * In async mode, if the plan node hadn't emitted any tuples before,
127 * this might be the first tuple
128 */
129 if (instr->async_mode && save_tuplecount < 1.0)
130 instr->firsttuple = instr->counter;
131 }
132}
WalUsage walusage
Definition instrument.h:94
BufferUsage bufusage
Definition instrument.h:93

References Instrumentation::async_mode, BufferUsageAccumDiff(), Instrumentation::bufusage, Instrumentation::bufusage_start, Instrumentation::counter, elog, ERROR, fb(), Instrumentation::firsttuple, INSTR_TIME_ACCUM_DIFF, INSTR_TIME_IS_ZERO, INSTR_TIME_SET_CURRENT, INSTR_TIME_SET_ZERO, Instrumentation::need_bufusage, Instrumentation::need_timer, Instrumentation::need_walusage, pgBufferUsage, pgWalUsage, Instrumentation::running, Instrumentation::starttime, Instrumentation::tuplecount, Instrumentation::walusage, Instrumentation::walusage_start, and WalUsageAccumDiff().

Referenced by AfterTriggerExecute(), ExecAsyncConfigureWait(), ExecAsyncNotify(), ExecAsyncRequest(), ExecCallTriggerFunc(), ExecProcNodeInstr(), ExecShutdownNode_walker(), MultiExecBitmapAnd(), MultiExecBitmapIndexScan(), MultiExecBitmapOr(), MultiExecHash(), standard_ExecutorFinish(), and standard_ExecutorRun().

◆ InstrUpdateTupleCount()

void InstrUpdateTupleCount ( Instrumentation instr,
double  nTuples 
)
extern

Definition at line 136 of file instrument.c.

137{
138 /* count the returned tuples */
139 instr->tuplecount += nTuples;
140}

References Instrumentation::tuplecount.

Referenced by complete_pending_request(), and ExecMergeMatched().

◆ WalUsageAccumDiff()

void WalUsageAccumDiff ( WalUsage dst,
const WalUsage add,
const WalUsage sub 
)
extern

Definition at line 289 of file instrument.c.

290{
291 dst->wal_bytes += add->wal_bytes - sub->wal_bytes;
292 dst->wal_records += add->wal_records - sub->wal_records;
293 dst->wal_fpi += add->wal_fpi - sub->wal_fpi;
294 dst->wal_fpi_bytes += add->wal_fpi_bytes - sub->wal_fpi_bytes;
295 dst->wal_buffers_full += add->wal_buffers_full - sub->wal_buffers_full;
296}
int64 wal_buffers_full
Definition instrument.h:57
uint64 wal_bytes
Definition instrument.h:55
int64 wal_fpi
Definition instrument.h:54
uint64 wal_fpi_bytes
Definition instrument.h:56
int64 wal_records
Definition instrument.h:53

References fb(), WalUsage::wal_buffers_full, WalUsage::wal_bytes, WalUsage::wal_fpi, WalUsage::wal_fpi_bytes, and WalUsage::wal_records.

Referenced by do_analyze_rel(), heap_vacuum_rel(), InstrEndParallelQuery(), InstrStopNode(), pgss_planner(), pgss_ProcessUtility(), pgstat_flush_backend_entry_wal(), and pgstat_wal_flush_cb().

Variable Documentation

◆ pgBufferUsage

◆ pgWalUsage