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  NodeInstrumentation
 
struct  WorkerNodeInstrumentation
 
struct  TriggerInstrumentation
 

Typedefs

typedef struct BufferUsage BufferUsage
 
typedef struct WalUsage WalUsage
 
typedef enum InstrumentOption InstrumentOption
 
typedef struct Instrumentation Instrumentation
 
typedef struct NodeInstrumentation NodeInstrumentation
 
typedef struct WorkerNodeInstrumentation WorkerNodeInstrumentation
 
typedef struct TriggerInstrumentation TriggerInstrumentation
 

Enumerations

enum  InstrumentOption {
  INSTRUMENT_TIMER = 1 << 0 , INSTRUMENT_BUFFERS = 1 << 1 , INSTRUMENT_ROWS = 1 << 2 , INSTRUMENT_WAL = 1 << 3 ,
  INSTRUMENT_IO = 1 << 4 , INSTRUMENT_ALL = PG_INT32_MAX
}
 

Functions

InstrumentationInstrAlloc (int instrument_options)
 
void InstrInitOptions (Instrumentation *instr, int instrument_options)
 
void InstrStart (Instrumentation *instr)
 
void InstrStop (Instrumentation *instr)
 
NodeInstrumentationInstrAllocNode (int instrument_options, bool async_mode)
 
void InstrInitNode (NodeInstrumentation *instr, int instrument_options, bool async_mode)
 
void InstrStartNode (NodeInstrumentation *instr)
 
void InstrStopNode (NodeInstrumentation *instr, double nTuples)
 
void InstrUpdateTupleCount (NodeInstrumentation *instr, double nTuples)
 
void InstrEndLoop (NodeInstrumentation *instr)
 
void InstrAggNode (NodeInstrumentation *dst, NodeInstrumentation *add)
 
TriggerInstrumentationInstrAllocTrigger (int n, int instrument_options)
 
void InstrStartTrigger (TriggerInstrumentation *tginstr)
 
void InstrStopTrigger (TriggerInstrumentation *tginstr, int64 firings)
 
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

◆ NodeInstrumentation

◆ TriggerInstrumentation

◆ WalUsage

◆ WorkerNodeInstrumentation

Enumeration Type Documentation

◆ InstrumentOption

Enumerator
INSTRUMENT_TIMER 
INSTRUMENT_BUFFERS 
INSTRUMENT_ROWS 
INSTRUMENT_WAL 
INSTRUMENT_IO 
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 */
67 INSTRUMENT_IO = 1 << 4, /* needs IO usage */
#define PG_INT32_MAX
Definition c.h:673
InstrumentOption
Definition instrument.h:62
@ INSTRUMENT_ALL
Definition instrument.h:68
@ INSTRUMENT_TIMER
Definition instrument.h:63
@ INSTRUMENT_IO
Definition instrument.h:67
@ 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 
)
externinline

Definition at line 327 of file instrument.c.

330{
331 dst->shared_blks_hit += add->shared_blks_hit - sub->shared_blks_hit;
332 dst->shared_blks_read += add->shared_blks_read - sub->shared_blks_read;
333 dst->shared_blks_dirtied += add->shared_blks_dirtied - sub->shared_blks_dirtied;
334 dst->shared_blks_written += add->shared_blks_written - sub->shared_blks_written;
335 dst->local_blks_hit += add->local_blks_hit - sub->local_blks_hit;
336 dst->local_blks_read += add->local_blks_read - sub->local_blks_read;
337 dst->local_blks_dirtied += add->local_blks_dirtied - sub->local_blks_dirtied;
338 dst->local_blks_written += add->local_blks_written - sub->local_blks_written;
339 dst->temp_blks_read += add->temp_blks_read - sub->temp_blks_read;
340 dst->temp_blks_written += add->temp_blks_written - sub->temp_blks_written;
341 INSTR_TIME_ACCUM_DIFF(dst->shared_blk_read_time,
342 add->shared_blk_read_time, sub->shared_blk_read_time);
343 INSTR_TIME_ACCUM_DIFF(dst->shared_blk_write_time,
344 add->shared_blk_write_time, sub->shared_blk_write_time);
345 INSTR_TIME_ACCUM_DIFF(dst->local_blk_read_time,
346 add->local_blk_read_time, sub->local_blk_read_time);
347 INSTR_TIME_ACCUM_DIFF(dst->local_blk_write_time,
348 add->local_blk_write_time, sub->local_blk_write_time);
349 INSTR_TIME_ACCUM_DIFF(dst->temp_blk_read_time,
350 add->temp_blk_read_time, sub->temp_blk_read_time);
351 INSTR_TIME_ACCUM_DIFF(dst->temp_blk_write_time,
352 add->temp_blk_write_time, sub->temp_blk_write_time);
353}
#define INSTR_TIME_ACCUM_DIFF(x, y, z)
Definition instr_time.h:439
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(), InstrStopCommon(), pgss_planner(), pgss_ProcessUtility(), serializeAnalyzeReceive(), and standard_ExplainOneQuery().

◆ InstrAccumParallelQuery()

void InstrAccumParallelQuery ( BufferUsage bufusage,
WalUsage walusage 
)
extern

Definition at line 297 of file instrument.c.

298{
299 BufferUsageAdd(&pgBufferUsage, bufusage);
300 WalUsageAdd(&pgWalUsage, walusage);
301}
static void BufferUsageAdd(BufferUsage *dst, const BufferUsage *add)
Definition instrument.c:305
static void WalUsageAdd(WalUsage *dst, WalUsage *add)
Definition instrument.c:357
WalUsage pgWalUsage
Definition instrument.c:27
BufferUsage pgBufferUsage
Definition instrument.c:25

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 ( NodeInstrumentation dst,
NodeInstrumentation add 
)
extern

Definition at line 232 of file instrument.c.

233{
234 Assert(!add->running);
235
236 INSTR_TIME_ADD(dst->startup, add->startup);
237 INSTR_TIME_ADD(dst->instr.total, add->instr.total);
238 dst->ntuples += add->ntuples;
239 dst->ntuples2 += add->ntuples2;
240 dst->nloops += add->nloops;
241 dst->nfiltered1 += add->nfiltered1;
242 dst->nfiltered2 += add->nfiltered2;
243
244 if (dst->instr.need_bufusage)
245 BufferUsageAdd(&dst->instr.bufusage, &add->instr.bufusage);
246
247 if (dst->instr.need_walusage)
248 WalUsageAdd(&dst->instr.walusage, &add->instr.walusage);
249}
#define Assert(condition)
Definition c.h:943
#define INSTR_TIME_ADD(x, y)
Definition instr_time.h:430

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

Referenced by ExecParallelReportInstrumentation(), and ExecParallelRetrieveInstrumentation().

◆ InstrAlloc()

Instrumentation * InstrAlloc ( int  instrument_options)
extern

Definition at line 36 of file instrument.c.

37{
39
40 InstrInitOptions(instr, instrument_options);
41 return instr;
42}
#define palloc0_object(type)
Definition fe_memutils.h:75
void InstrInitOptions(Instrumentation *instr, int instrument_options)
Definition instrument.c:45

References InstrInitOptions(), and palloc0_object.

Referenced by standard_ExecutorStart().

◆ InstrAllocNode()

NodeInstrumentation * InstrAllocNode ( int  instrument_options,
bool  async_mode 
)
extern

Definition at line 112 of file instrument.c.

113{
115
116 InstrInitNode(instr, instrument_options, async_mode);
117
118 return instr;
119}
#define palloc_object(type)
Definition fe_memutils.h:74
void InstrInitNode(NodeInstrumentation *instr, int instrument_options, bool async_mode)
Definition instrument.c:123

References InstrInitNode(), and palloc_object.

Referenced by ExecInitNode().

◆ InstrAllocTrigger()

TriggerInstrumentation * InstrAllocTrigger ( int  n,
int  instrument_options 
)
extern

Definition at line 253 of file instrument.c.

254{
256 int i;
257
258 for (i = 0; i < n; i++)
259 InstrInitOptions(&tginstr[i].instr, instrument_options);
260
261 return tginstr;
262}
#define palloc0_array(type, count)
Definition fe_memutils.h:77
int i
Definition isn.c:77

References fb(), i, InstrInitOptions(), and palloc0_array.

Referenced by InitResultRelInfo().

◆ InstrEndLoop()

void InstrEndLoop ( NodeInstrumentation instr)
extern

Definition at line 204 of file instrument.c.

205{
206 /* Skip if nothing has happened, or already shut down */
207 if (!instr->running)
208 return;
209
211 elog(ERROR, "InstrEndLoop called on running node");
212
213 /* Accumulate per-cycle statistics into totals */
214 INSTR_TIME_ADD(instr->startup, instr->firsttuple);
215 INSTR_TIME_ADD(instr->instr.total, instr->counter);
216 instr->ntuples += instr->tuplecount;
217 instr->nloops += 1;
218
219 /* Reset for next cycle (if any) */
220 instr->running = false;
224 instr->tuplecount = 0;
225}
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define INSTR_TIME_IS_ZERO(t)
Definition instr_time.h:419
#define INSTR_TIME_SET_ZERO(t)
Definition instr_time.h:421
instr_time total
Definition instrument.h:88
instr_time starttime
Definition instrument.h:84
Instrumentation instr
Definition instrument.h:98
instr_time firsttuple
Definition instrument.h:104

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

Referenced by ExecParallelReportInstrumentation(), ExecReScan(), ExplainNode(), and show_modifytable_info().

◆ InstrEndParallelQuery()

void InstrEndParallelQuery ( BufferUsage bufusage,
WalUsage walusage 
)
extern

Definition at line 287 of file instrument.c.

288{
289 memset(bufusage, 0, sizeof(BufferUsage));
291 memset(walusage, 0, sizeof(WalUsage));
293}
static BufferUsage save_pgBufferUsage
Definition instrument.c:26
static WalUsage save_pgWalUsage
Definition instrument.c:28
void WalUsageAccumDiff(WalUsage *dst, const WalUsage *add, const WalUsage *sub)
Definition instrument.c:367
void BufferUsageAccumDiff(BufferUsage *dst, const BufferUsage *add, const BufferUsage *sub)
Definition instrument.c:327

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().

◆ InstrInitNode()

void InstrInitNode ( NodeInstrumentation instr,
int  instrument_options,
bool  async_mode 
)
extern

Definition at line 123 of file instrument.c.

124{
125 memset(instr, 0, sizeof(NodeInstrumentation));
126 InstrInitOptions(&instr->instr, instrument_options);
127 instr->async_mode = async_mode;
128}

References NodeInstrumentation::async_mode, fb(), NodeInstrumentation::instr, and InstrInitOptions().

Referenced by ExecInitParallelPlan(), and InstrAllocNode().

◆ InstrInitOptions()

void InstrInitOptions ( Instrumentation instr,
int  instrument_options 
)
extern

Definition at line 45 of file instrument.c.

46{
47 instr->need_bufusage = (instrument_options & INSTRUMENT_BUFFERS) != 0;
48 instr->need_walusage = (instrument_options & INSTRUMENT_WAL) != 0;
49 instr->need_timer = (instrument_options & INSTRUMENT_TIMER) != 0;
50}

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

Referenced by InstrAlloc(), InstrAllocTrigger(), and InstrInitNode().

◆ InstrStart()

void InstrStart ( Instrumentation instr)
externinline

Definition at line 53 of file instrument.c.

54{
55 if (instr->need_timer)
56 {
57 if (!INSTR_TIME_IS_ZERO(instr->starttime))
58 elog(ERROR, "InstrStart called twice in a row");
59 else
61 }
62
63 /* save buffer usage totals at start, if needed */
64 if (instr->need_bufusage)
66
67 if (instr->need_walusage)
69}
#define INSTR_TIME_SET_CURRENT_FAST(t)
Definition instr_time.h:423
BufferUsage bufusage_start
Definition instrument.h:85
WalUsage walusage_start
Definition instrument.h:86

References Instrumentation::bufusage_start, elog, ERROR, INSTR_TIME_IS_ZERO, INSTR_TIME_SET_CURRENT_FAST, Instrumentation::need_bufusage, Instrumentation::need_timer, Instrumentation::need_walusage, pgBufferUsage, pgWalUsage, Instrumentation::starttime, and Instrumentation::walusage_start.

Referenced by InstrStartNode(), InstrStartTrigger(), standard_ExecutorFinish(), and standard_ExecutorRun().

◆ InstrStartNode()

void InstrStartNode ( NodeInstrumentation instr)
externinline

◆ InstrStartParallelQuery()

◆ InstrStartTrigger()

void InstrStartTrigger ( TriggerInstrumentation tginstr)
extern

Definition at line 265 of file instrument.c.

266{
267 InstrStart(&tginstr->instr);
268}

References fb(), and InstrStart().

Referenced by AfterTriggerExecute(), and ExecCallTriggerFunc().

◆ InstrStop()

void InstrStop ( Instrumentation instr)
extern

Definition at line 103 of file instrument.c.

104{
105 InstrStopCommon(instr, &instr->total);
106}
static void InstrStopCommon(Instrumentation *instr, instr_time *accum_time)
Definition instrument.c:76

References InstrStopCommon(), and Instrumentation::total.

Referenced by InstrStopTrigger(), standard_ExecutorFinish(), and standard_ExecutorRun().

◆ InstrStopNode()

void InstrStopNode ( NodeInstrumentation instr,
double  nTuples 
)
externinline

Definition at line 139 of file instrument.c.

140{
141 double save_tuplecount = instr->tuplecount;
142
143 /* count the returned tuples */
144 instr->tuplecount += nTuples;
145
146 /*
147 * Note that in contrast to InstrStop() the time is accumulated into
148 * NodeInstrumentation->counter, with total only getting updated in
149 * InstrEndLoop. We need the separate counter variable because we need to
150 * calculate start-up time for the first tuple in each cycle, and then
151 * accumulate it together.
152 */
153 InstrStopCommon(&instr->instr, &instr->counter);
154
155 /* Is this the first tuple of this cycle? */
156 if (!instr->running)
157 {
158 instr->running = true;
159 instr->firsttuple = instr->counter;
160 }
161 else
162 {
163 /*
164 * In async mode, if the plan node hadn't emitted any tuples before,
165 * this might be the first tuple
166 */
167 if (instr->async_mode && save_tuplecount < 1.0)
168 instr->firsttuple = instr->counter;
169 }
170}

References NodeInstrumentation::async_mode, NodeInstrumentation::counter, fb(), NodeInstrumentation::firsttuple, NodeInstrumentation::instr, InstrStopCommon(), NodeInstrumentation::running, and NodeInstrumentation::tuplecount.

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

◆ InstrStopTrigger()

void InstrStopTrigger ( TriggerInstrumentation tginstr,
int64  firings 
)
extern

Definition at line 271 of file instrument.c.

272{
273 InstrStop(&tginstr->instr);
274 tginstr->firings += firings;
275}
void InstrStop(Instrumentation *instr)
Definition instrument.c:103

References fb(), and InstrStop().

Referenced by AfterTriggerExecute(), and ExecCallTriggerFunc().

◆ InstrUpdateTupleCount()

void InstrUpdateTupleCount ( NodeInstrumentation instr,
double  nTuples 
)
extern

Definition at line 196 of file instrument.c.

197{
198 /* count the returned tuples */
199 instr->tuplecount += nTuples;
200}

References NodeInstrumentation::tuplecount.

Referenced by complete_pending_request(), and ExecMergeMatched().

◆ WalUsageAccumDiff()

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

Definition at line 367 of file instrument.c.

368{
369 dst->wal_bytes += add->wal_bytes - sub->wal_bytes;
370 dst->wal_records += add->wal_records - sub->wal_records;
371 dst->wal_fpi += add->wal_fpi - sub->wal_fpi;
372 dst->wal_fpi_bytes += add->wal_fpi_bytes - sub->wal_fpi_bytes;
373 dst->wal_buffers_full += add->wal_buffers_full - sub->wal_buffers_full;
374}
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(), InstrStopCommon(), pgss_planner(), pgss_ProcessUtility(), pgstat_flush_backend_entry_wal(), and pgstat_wal_flush_cb().

Variable Documentation

◆ pgBufferUsage

◆ pgWalUsage