PostgreSQL Source Code  git master
instrument.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * instrument.h
4  * definitions for run-time statistics collection
5  *
6  *
7  * Copyright (c) 2001-2020, PostgreSQL Global Development Group
8  *
9  * src/include/executor/instrument.h
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef INSTRUMENT_H
14 #define INSTRUMENT_H
15 
16 #include "portability/instr_time.h"
17 
18 
19 typedef struct BufferUsage
20 {
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 */
33 } BufferUsage;
34 
35 typedef struct WalUsage
36 {
37  long wal_records; /* # of WAL records produced */
38  long wal_fpi; /* # of WAL full page images produced */
39  uint64 wal_bytes; /* size of WAL records produced */
40 } WalUsage;
41 
42 /* Flag bits included in InstrAlloc's instrument_options bitmask */
43 typedef enum InstrumentOption
44 {
45  INSTRUMENT_TIMER = 1 << 0, /* needs timer (and row counts) */
46  INSTRUMENT_BUFFERS = 1 << 1, /* needs buffer usage */
47  INSTRUMENT_ROWS = 1 << 2, /* needs row count */
48  INSTRUMENT_WAL = 1 << 3, /* needs WAL usage */
51 
52 typedef struct Instrumentation
53 {
54  /* Parameters set at node creation: */
55  bool need_timer; /* true if we need timer data */
56  bool need_bufusage; /* true if we need buffer usage data */
57  bool need_walusage; /* true if we need WAL usage data */
58  /* Info about current plan cycle: */
59  bool running; /* true if we've completed first tuple */
60  instr_time starttime; /* start time of current iteration of node */
61  instr_time counter; /* accumulated runtime for this node */
62  double firsttuple; /* time for first tuple of this cycle */
63  double tuplecount; /* # of tuples emitted so far this cycle */
64  BufferUsage bufusage_start; /* buffer usage at start */
65  WalUsage walusage_start; /* WAL usage at start */
66  /* Accumulated statistics across all completed cycles: */
67  double startup; /* total startup time (in seconds) */
68  double total; /* total time (in seconds) */
69  double ntuples; /* total tuples produced */
70  double ntuples2; /* secondary node-specific tuple counter */
71  double nloops; /* # of run cycles for this node */
72  double nfiltered1; /* # of tuples removed by scanqual or joinqual */
73  double nfiltered2; /* # of tuples removed by "other" quals */
74  BufferUsage bufusage; /* total buffer usage */
75  WalUsage walusage; /* total WAL usage */
77 
78 typedef struct WorkerInstrumentation
79 {
80  int num_workers; /* # of structures that follow */
83 
86 
87 extern Instrumentation *InstrAlloc(int n, int instrument_options);
88 extern void InstrInit(Instrumentation *instr, int instrument_options);
89 extern void InstrStartNode(Instrumentation *instr);
90 extern void InstrStopNode(Instrumentation *instr, double nTuples);
91 extern void InstrEndLoop(Instrumentation *instr);
92 extern void InstrAggNode(Instrumentation *dst, Instrumentation *add);
93 extern void InstrStartParallelQuery(void);
94 extern void InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage);
95 extern void InstrAccumParallelQuery(BufferUsage *bufusage, WalUsage *walusage);
96 extern void BufferUsageAccumDiff(BufferUsage *dst,
97  const BufferUsage *add, const BufferUsage *sub);
98 extern void WalUsageAccumDiff(WalUsage *dst, const WalUsage *add,
99  const WalUsage *sub);
100 
101 #endif /* INSTRUMENT_H */
double nfiltered1
Definition: instrument.h:72
bool need_bufusage
Definition: instrument.h:56
long local_blks_hit
Definition: instrument.h:25
void InstrEndParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
Definition: instrument.c:189
long local_blks_dirtied
Definition: instrument.h:27
struct WalUsage WalUsage
long local_blks_read
Definition: instrument.h:26
WalUsage walusage
Definition: instrument.h:75
void InstrEndLoop(Instrumentation *instr)
Definition: instrument.c:121
instr_time blk_read_time
Definition: instrument.h:31
void InstrAccumParallelQuery(BufferUsage *bufusage, WalUsage *walusage)
Definition: instrument.c:199
struct timeval instr_time
Definition: instr_time.h:150
long shared_blks_read
Definition: instrument.h:22
double startup
Definition: instrument.h:67
void InstrStartParallelQuery(void)
Definition: instrument.c:181
void InstrInit(Instrumentation *instr, int instrument_options)
Definition: instrument.c:57
void InstrStartNode(Instrumentation *instr)
Definition: instrument.c:67
#define FLEXIBLE_ARRAY_MEMBER
Definition: c.h:276
long temp_blks_written
Definition: instrument.h:30
PGDLLIMPORT BufferUsage pgBufferUsage
Definition: instrument.c:20
#define PGDLLIMPORT
Definition: c.h:1279
long shared_blks_written
Definition: instrument.h:24
BufferUsage bufusage_start
Definition: instrument.h:64
double firsttuple
Definition: instrument.h:62
double nfiltered2
Definition: instrument.h:73
InstrumentOption
Definition: instrument.h:43
long wal_records
Definition: instrument.h:37
struct WorkerInstrumentation WorkerInstrumentation
instr_time starttime
Definition: instrument.h:60
long shared_blks_dirtied
Definition: instrument.h:23
double ntuples
Definition: instrument.h:69
long temp_blks_read
Definition: instrument.h:29
void InstrAggNode(Instrumentation *dst, Instrumentation *add)
Definition: instrument.c:150
WalUsage walusage_start
Definition: instrument.h:65
double tuplecount
Definition: instrument.h:63
struct BufferUsage BufferUsage
PGDLLIMPORT WalUsage pgWalUsage
Definition: instrument.c:22
BufferUsage bufusage
Definition: instrument.h:74
instr_time counter
Definition: instrument.h:61
instr_time blk_write_time
Definition: instrument.h:32
long wal_fpi
Definition: instrument.h:38
double ntuples2
Definition: instrument.h:70
void WalUsageAccumDiff(WalUsage *dst, const WalUsage *add, const WalUsage *sub)
Definition: instrument.c:255
void InstrStopNode(Instrumentation *instr, double nTuples)
Definition: instrument.c:83
struct Instrumentation Instrumentation
Instrumentation * InstrAlloc(int n, int instrument_options)
Definition: instrument.c:31
long shared_blks_hit
Definition: instrument.h:21
#define PG_INT32_MAX
Definition: c.h:450
long local_blks_written
Definition: instrument.h:28
bool need_walusage
Definition: instrument.h:57
void BufferUsageAccumDiff(BufferUsage *dst, const BufferUsage *add, const BufferUsage *sub)
Definition: instrument.c:225
uint64 wal_bytes
Definition: instrument.h:39