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:603
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 245 of file instrument.c.

248{
249 dst->shared_blks_hit += add->shared_blks_hit - sub->shared_blks_hit;
250 dst->shared_blks_read += add->shared_blks_read - sub->shared_blks_read;
251 dst->shared_blks_dirtied += add->shared_blks_dirtied - sub->shared_blks_dirtied;
252 dst->shared_blks_written += add->shared_blks_written - sub->shared_blks_written;
253 dst->local_blks_hit += add->local_blks_hit - sub->local_blks_hit;
254 dst->local_blks_read += add->local_blks_read - sub->local_blks_read;
255 dst->local_blks_dirtied += add->local_blks_dirtied - sub->local_blks_dirtied;
256 dst->local_blks_written += add->local_blks_written - sub->local_blks_written;
257 dst->temp_blks_read += add->temp_blks_read - sub->temp_blks_read;
258 dst->temp_blks_written += add->temp_blks_written - sub->temp_blks_written;
259 INSTR_TIME_ACCUM_DIFF(dst->shared_blk_read_time,
260 add->shared_blk_read_time, sub->shared_blk_read_time);
261 INSTR_TIME_ACCUM_DIFF(dst->shared_blk_write_time,
262 add->shared_blk_write_time, sub->shared_blk_write_time);
263 INSTR_TIME_ACCUM_DIFF(dst->local_blk_read_time,
264 add->local_blk_read_time, sub->local_blk_read_time);
265 INSTR_TIME_ACCUM_DIFF(dst->local_blk_write_time,
266 add->local_blk_write_time, sub->local_blk_write_time);
267 INSTR_TIME_ACCUM_DIFF(dst->temp_blk_read_time,
268 add->temp_blk_read_time, sub->temp_blk_read_time);
269 INSTR_TIME_ACCUM_DIFF(dst->temp_blk_write_time,
270 add->temp_blk_write_time, sub->temp_blk_write_time);
271}
#define INSTR_TIME_ACCUM_DIFF(x, y, z)
Definition instr_time.h:184
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 215 of file instrument.c.

216{
217 BufferUsageAdd(&pgBufferUsage, bufusage);
218 WalUsageAdd(&pgWalUsage, walusage);
219}
static void BufferUsageAdd(BufferUsage *dst, const BufferUsage *add)
Definition instrument.c:223
static void WalUsageAdd(WalUsage *dst, WalUsage *add)
Definition instrument.c:275
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 165 of file instrument.c.

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

References BufferUsageAdd(), fb(), INSTR_TIME_ADD, INSTR_TIME_LT, 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 140 of file instrument.c.

141{
142 /* Skip if nothing has happened, or already shut down */
143 if (!instr->running)
144 return;
145
146 if (!INSTR_TIME_IS_ZERO(instr->starttime))
147 elog(ERROR, "InstrEndLoop called on running node");
148
149 /* Accumulate per-cycle statistics into totals */
150 INSTR_TIME_ADD(instr->startup, instr->firsttuple);
151 INSTR_TIME_ADD(instr->total, instr->counter);
152 instr->ntuples += instr->tuplecount;
153 instr->nloops += 1;
154
155 /* Reset for next cycle (if any) */
156 instr->running = false;
160 instr->tuplecount = 0;
161}
#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:172
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 205 of file instrument.c.

206{
207 memset(bufusage, 0, sizeof(BufferUsage));
209 memset(walusage, 0, sizeof(WalUsage));
211}
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:285
void BufferUsageAccumDiff(BufferUsage *dst, const BufferUsage *add, const BufferUsage *sub)
Definition instrument.c:245

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 84 of file instrument.c.

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

133{
134 /* count the returned tuples */
135 instr->tuplecount += nTuples;
136}

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 285 of file instrument.c.

286{
287 dst->wal_bytes += add->wal_bytes - sub->wal_bytes;
288 dst->wal_records += add->wal_records - sub->wal_records;
289 dst->wal_fpi += add->wal_fpi - sub->wal_fpi;
290 dst->wal_fpi_bytes += add->wal_fpi_bytes - sub->wal_fpi_bytes;
291 dst->wal_buffers_full += add->wal_buffers_full - sub->wal_buffers_full;
292}
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