PostgreSQL Source Code  git master
wait_event.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  * wait_event.h
3  * Definitions related to wait event reporting
4  *
5  * Copyright (c) 2001-2021, PostgreSQL Global Development Group
6  *
7  * src/include/utils/wait_event.h
8  * ----------
9  */
10 #ifndef WAIT_EVENT_H
11 #define WAIT_EVENT_H
12 
13 
14 /* ----------
15  * Wait Classes
16  * ----------
17  */
18 #define PG_WAIT_LWLOCK 0x01000000U
19 #define PG_WAIT_LOCK 0x03000000U
20 #define PG_WAIT_BUFFER_PIN 0x04000000U
21 #define PG_WAIT_ACTIVITY 0x05000000U
22 #define PG_WAIT_CLIENT 0x06000000U
23 #define PG_WAIT_EXTENSION 0x07000000U
24 #define PG_WAIT_IPC 0x08000000U
25 #define PG_WAIT_TIMEOUT 0x09000000U
26 #define PG_WAIT_IO 0x0A000000U
27 
28 /* ----------
29  * Wait Events - Activity
30  *
31  * Use this category when a process is waiting because it has no work to do,
32  * unless the "Client" or "Timeout" category describes the situation better.
33  * Typically, this should only be used for background processes.
34  * ----------
35  */
36 typedef enum
37 {
52 
53 /* ----------
54  * Wait Events - Client
55  *
56  * Use this category when a process is waiting to send data to or receive data
57  * from the frontend process to which it is connected. This is never used for
58  * a background process, which has no client connection.
59  * ----------
60  */
61 typedef enum
62 {
72 
73 /* ----------
74  * Wait Events - IPC
75  *
76  * Use this category when a process cannot complete the work it is doing because
77  * it is waiting for a notification from another process.
78  * ----------
79  */
80 typedef enum
81 {
134 
135 /* ----------
136  * Wait Events - Timeout
137  *
138  * Use this category when a process is waiting for a timeout to expire.
139  * ----------
140  */
141 typedef enum
142 {
150 
151 /* ----------
152  * Wait Events - IO
153  *
154  * Use this category when a process is waiting for a IO.
155  * ----------
156  */
157 typedef enum
158 {
230 
231 
232 extern const char *pgstat_get_wait_event(uint32 wait_event_info);
233 extern const char *pgstat_get_wait_event_type(uint32 wait_event_info);
234 static inline void pgstat_report_wait_start(uint32 wait_event_info);
235 static inline void pgstat_report_wait_end(void);
236 extern void pgstat_set_wait_event_storage(uint32 *wait_event_info);
237 extern void pgstat_reset_wait_event_storage(void);
238 
240 
241 
242 /* ----------
243  * pgstat_report_wait_start() -
244  *
245  * Called from places where server process needs to wait. This is called
246  * to report wait event information. The wait information is stored
247  * as 4-bytes where first byte represents the wait event class (type of
248  * wait, for different types of wait, refer WaitClass) and the next
249  * 3-bytes represent the actual wait event. Currently 2-bytes are used
250  * for wait event which is sufficient for current usage, 1-byte is
251  * reserved for future usage.
252  *
253  * Historically we used to make this reporting conditional on
254  * pgstat_track_activities, but the check for that seems to add more cost
255  * than it saves.
256  *
257  * my_wait_event_info initially points to local memory, making it safe to
258  * call this before MyProc has been initialized.
259  * ----------
260  */
261 static inline void
263 {
264  /*
265  * Since this is a four-byte field which is always read and written as
266  * four-bytes, updates are atomic.
267  */
268  *(volatile uint32 *) my_wait_event_info = wait_event_info;
269 }
270 
271 /* ----------
272  * pgstat_report_wait_end() -
273  *
274  * Called to report end of a wait.
275  * ----------
276  */
277 static inline void
279 {
280  /* see pgstat_report_wait_start() */
281  *(volatile uint32 *) my_wait_event_info = 0;
282 }
283 
284 
285 #endif /* WAIT_EVENT_H */
unsigned int uint32
Definition: c.h:441
#define PGDLLIMPORT
Definition: c.h:1318
#define PG_WAIT_TIMEOUT
Definition: wait_event.h:25
WaitEventActivity
Definition: wait_event.h:37
@ WAIT_EVENT_SYSLOGGER_MAIN
Definition: wait_event.h:47
@ WAIT_EVENT_BGWRITER_MAIN
Definition: wait_event.h:41
@ WAIT_EVENT_WAL_WRITER_MAIN
Definition: wait_event.h:50
@ WAIT_EVENT_WAL_SENDER_MAIN
Definition: wait_event.h:49
@ WAIT_EVENT_LOGICAL_LAUNCHER_MAIN
Definition: wait_event.h:44
@ WAIT_EVENT_CHECKPOINTER_MAIN
Definition: wait_event.h:42
@ WAIT_EVENT_BGWRITER_HIBERNATE
Definition: wait_event.h:40
@ WAIT_EVENT_WAL_RECEIVER_MAIN
Definition: wait_event.h:48
@ WAIT_EVENT_ARCHIVER_MAIN
Definition: wait_event.h:38
@ WAIT_EVENT_LOGICAL_APPLY_MAIN
Definition: wait_event.h:43
@ WAIT_EVENT_RECOVERY_WAL_STREAM
Definition: wait_event.h:46
@ WAIT_EVENT_PGSTAT_MAIN
Definition: wait_event.h:45
@ WAIT_EVENT_AUTOVACUUM_MAIN
Definition: wait_event.h:39
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: wait_event.c:129
WaitEventIO
Definition: wait_event.h:158
@ WAIT_EVENT_LOGICAL_REWRITE_MAPPING_SYNC
Definition: wait_event.h:187
@ WAIT_EVENT_RELATION_MAP_WRITE
Definition: wait_event.h:194
@ WAIT_EVENT_WAL_COPY_SYNC
Definition: wait_event.h:221
@ WAIT_EVENT_LOCK_FILE_ADDTODATADIR_WRITE
Definition: wait_event.h:181
@ WAIT_EVENT_CONTROL_FILE_READ
Definition: wait_event.h:163
@ WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC
Definition: wait_event.h:172
@ WAIT_EVENT_REORDER_BUFFER_READ
Definition: wait_event.h:195
@ WAIT_EVENT_BUFFILE_WRITE
Definition: wait_event.h:161
@ WAIT_EVENT_RELATION_MAP_READ
Definition: wait_event.h:192
@ WAIT_EVENT_CONTROL_FILE_WRITE_UPDATE
Definition: wait_event.h:167
@ WAIT_EVENT_DATA_FILE_READ
Definition: wait_event.h:174
@ WAIT_EVENT_DATA_FILE_WRITE
Definition: wait_event.h:177
@ WAIT_EVENT_COPY_FILE_READ
Definition: wait_event.h:168
@ WAIT_EVENT_LOCK_FILE_CREATE_SYNC
Definition: wait_event.h:183
@ WAIT_EVENT_TIMELINE_HISTORY_FILE_WRITE
Definition: wait_event.h:210
@ WAIT_EVENT_LOCK_FILE_CREATE_READ
Definition: wait_event.h:182
@ WAIT_EVENT_LOGICAL_REWRITE_WRITE
Definition: wait_event.h:191
@ WAIT_EVENT_BASEBACKUP_READ
Definition: wait_event.h:159
@ WAIT_EVENT_WAL_COPY_WRITE
Definition: wait_event.h:222
@ WAIT_EVENT_RELATION_MAP_SYNC
Definition: wait_event.h:193
@ WAIT_EVENT_DSM_FILL_ZERO_WRITE
Definition: wait_event.h:178
@ WAIT_EVENT_TIMELINE_HISTORY_WRITE
Definition: wait_event.h:213
@ WAIT_EVENT_WAL_COPY_READ
Definition: wait_event.h:220
@ WAIT_EVENT_WAL_SYNC_METHOD_ASSIGN
Definition: wait_event.h:227
@ WAIT_EVENT_REPLICATION_SLOT_READ
Definition: wait_event.h:198
@ WAIT_EVENT_SNAPBUILD_SYNC
Definition: wait_event.h:207
@ WAIT_EVENT_DATA_FILE_FLUSH
Definition: wait_event.h:171
@ WAIT_EVENT_LOCK_FILE_CREATE_WRITE
Definition: wait_event.h:184
@ WAIT_EVENT_LOCK_FILE_RECHECKDATADIR_READ
Definition: wait_event.h:185
@ WAIT_EVENT_DATA_FILE_EXTEND
Definition: wait_event.h:170
@ WAIT_EVENT_WAL_SYNC
Definition: wait_event.h:226
@ WAIT_EVENT_CONTROL_FILE_WRITE
Definition: wait_event.h:166
@ WAIT_EVENT_SLRU_SYNC
Definition: wait_event.h:204
@ WAIT_EVENT_TWOPHASE_FILE_READ
Definition: wait_event.h:214
@ WAIT_EVENT_CONTROL_FILE_SYNC
Definition: wait_event.h:164
@ WAIT_EVENT_TWOPHASE_FILE_WRITE
Definition: wait_event.h:216
@ WAIT_EVENT_SLRU_READ
Definition: wait_event.h:203
@ WAIT_EVENT_BUFFILE_TRUNCATE
Definition: wait_event.h:162
@ WAIT_EVENT_WAL_WRITE
Definition: wait_event.h:228
@ WAIT_EVENT_COPY_FILE_WRITE
Definition: wait_event.h:169
@ WAIT_EVENT_REPLICATION_SLOT_WRITE
Definition: wait_event.h:201
@ WAIT_EVENT_WAL_INIT_SYNC
Definition: wait_event.h:223
@ WAIT_EVENT_REORDER_LOGICAL_MAPPING_READ
Definition: wait_event.h:197
@ WAIT_EVENT_REORDER_BUFFER_WRITE
Definition: wait_event.h:196
@ WAIT_EVENT_TIMELINE_HISTORY_FILE_SYNC
Definition: wait_event.h:209
@ WAIT_EVENT_LOGICAL_REWRITE_MAPPING_WRITE
Definition: wait_event.h:188
@ WAIT_EVENT_CONTROL_FILE_SYNC_UPDATE
Definition: wait_event.h:165
@ WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ
Definition: wait_event.h:217
@ WAIT_EVENT_SNAPBUILD_WRITE
Definition: wait_event.h:208
@ WAIT_EVENT_TWOPHASE_FILE_SYNC
Definition: wait_event.h:215
@ WAIT_EVENT_DATA_FILE_TRUNCATE
Definition: wait_event.h:176
@ WAIT_EVENT_SLRU_FLUSH_SYNC
Definition: wait_event.h:202
@ WAIT_EVENT_DATA_FILE_PREFETCH
Definition: wait_event.h:173
@ WAIT_EVENT_TIMELINE_HISTORY_READ
Definition: wait_event.h:211
@ WAIT_EVENT_BUFFILE_READ
Definition: wait_event.h:160
@ WAIT_EVENT_LOCK_FILE_ADDTODATADIR_READ
Definition: wait_event.h:179
@ WAIT_EVENT_TIMELINE_HISTORY_SYNC
Definition: wait_event.h:212
@ WAIT_EVENT_LOCK_FILE_ADDTODATADIR_SYNC
Definition: wait_event.h:180
@ WAIT_EVENT_DATA_FILE_SYNC
Definition: wait_event.h:175
@ WAIT_EVENT_REPLICATION_SLOT_RESTORE_SYNC
Definition: wait_event.h:199
@ WAIT_EVENT_LOGICAL_REWRITE_TRUNCATE
Definition: wait_event.h:190
@ WAIT_EVENT_SLRU_WRITE
Definition: wait_event.h:205
@ WAIT_EVENT_REPLICATION_SLOT_SYNC
Definition: wait_event.h:200
@ WAIT_EVENT_LOGICAL_REWRITE_CHECKPOINT_SYNC
Definition: wait_event.h:186
@ WAIT_EVENT_WAL_INIT_WRITE
Definition: wait_event.h:224
@ WAIT_EVENT_WAL_READ
Definition: wait_event.h:225
@ WAIT_EVENT_SNAPBUILD_READ
Definition: wait_event.h:206
@ WAIT_EVENT_WAL_BOOTSTRAP_SYNC
Definition: wait_event.h:218
@ WAIT_EVENT_LOGICAL_REWRITE_SYNC
Definition: wait_event.h:189
@ WAIT_EVENT_WAL_BOOTSTRAP_WRITE
Definition: wait_event.h:219
WaitEventIPC
Definition: wait_event.h:81
@ WAIT_EVENT_REPLICATION_ORIGIN_DROP
Definition: wait_event.h:125
@ WAIT_EVENT_HASH_GROW_BUCKETS_ALLOCATE
Definition: wait_event.h:106
@ WAIT_EVENT_CHECKPOINT_START
Definition: wait_event.h:92
@ WAIT_EVENT_PROMOTE
Definition: wait_event.h:120
@ WAIT_EVENT_SAFE_SNAPSHOT
Definition: wait_event.h:128
@ WAIT_EVENT_BACKUP_WAIT_WAL_ARCHIVE
Definition: wait_event.h:86
@ WAIT_EVENT_RESTORE_COMMAND
Definition: wait_event.h:127
@ WAIT_EVENT_PARALLEL_BITMAP_SCAN
Definition: wait_event.h:115
@ WAIT_EVENT_MQ_INTERNAL
Definition: wait_event.h:111
@ WAIT_EVENT_MQ_PUT_MESSAGE
Definition: wait_event.h:112
@ WAIT_EVENT_ARCHIVE_COMMAND
Definition: wait_event.h:84
@ WAIT_EVENT_BUFFER_IO
Definition: wait_event.h:90
@ WAIT_EVENT_SYNC_REP
Definition: wait_event.h:129
@ WAIT_EVENT_PARALLEL_CREATE_INDEX_SCAN
Definition: wait_event.h:116
@ WAIT_EVENT_HASH_GROW_BUCKETS_REINSERT
Definition: wait_event.h:108
@ WAIT_EVENT_BGWORKER_STARTUP
Definition: wait_event.h:88
@ WAIT_EVENT_HASH_BUILD_ELECT
Definition: wait_event.h:98
@ WAIT_EVENT_XACT_GROUP_UPDATE
Definition: wait_event.h:132
@ WAIT_EVENT_MQ_SEND
Definition: wait_event.h:114
@ WAIT_EVENT_HASH_BUILD_HASH_INNER
Definition: wait_event.h:99
@ WAIT_EVENT_HASH_BATCH_LOAD
Definition: wait_event.h:96
@ WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE
Definition: wait_event.h:110
@ WAIT_EVENT_APPEND_READY
Definition: wait_event.h:82
@ WAIT_EVENT_BTREE_PAGE
Definition: wait_event.h:89
@ WAIT_EVENT_HASH_GROW_BATCHES_DECIDE
Definition: wait_event.h:102
@ WAIT_EVENT_HASH_GROW_BATCHES_ALLOCATE
Definition: wait_event.h:101
@ WAIT_EVENT_PROCARRAY_GROUP_UPDATE
Definition: wait_event.h:118
@ WAIT_EVENT_BACKEND_TERMINATION
Definition: wait_event.h:85
@ WAIT_EVENT_CHECKPOINT_DONE
Definition: wait_event.h:91
@ WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE
Definition: wait_event.h:122
@ WAIT_EVENT_HASH_GROW_BATCHES_FINISH
Definition: wait_event.h:104
@ WAIT_EVENT_HASH_GROW_BUCKETS_ELECT
Definition: wait_event.h:107
@ WAIT_EVENT_BGWORKER_SHUTDOWN
Definition: wait_event.h:87
@ WAIT_EVENT_REPLICATION_SLOT_DROP
Definition: wait_event.h:126
@ WAIT_EVENT_PARALLEL_FINISH
Definition: wait_event.h:117
@ WAIT_EVENT_ARCHIVE_CLEANUP_COMMAND
Definition: wait_event.h:83
@ WAIT_EVENT_WAL_RECEIVER_WAIT_START
Definition: wait_event.h:131
@ WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT
Definition: wait_event.h:121
@ WAIT_EVENT_HASH_BUILD_HASH_OUTER
Definition: wait_event.h:100
@ WAIT_EVENT_WAL_RECEIVER_EXIT
Definition: wait_event.h:130
@ WAIT_EVENT_HASH_BATCH_ALLOCATE
Definition: wait_event.h:94
@ WAIT_EVENT_HASH_GROW_BATCHES_REPARTITION
Definition: wait_event.h:105
@ WAIT_EVENT_HASH_BATCH_ELECT
Definition: wait_event.h:95
@ WAIT_EVENT_PROC_SIGNAL_BARRIER
Definition: wait_event.h:119
@ WAIT_EVENT_RECOVERY_PAUSE
Definition: wait_event.h:124
@ WAIT_EVENT_RECOVERY_END_COMMAND
Definition: wait_event.h:123
@ WAIT_EVENT_LOGICAL_SYNC_DATA
Definition: wait_event.h:109
@ WAIT_EVENT_HASH_BUILD_ALLOCATE
Definition: wait_event.h:97
@ WAIT_EVENT_EXECUTE_GATHER
Definition: wait_event.h:93
@ WAIT_EVENT_HASH_GROW_BATCHES_ELECT
Definition: wait_event.h:103
@ WAIT_EVENT_MQ_RECEIVE
Definition: wait_event.h:113
void pgstat_set_wait_event_storage(uint32 *wait_event_info)
Definition: wait_event.c:50
#define PG_WAIT_IPC
Definition: wait_event.h:24
#define PG_WAIT_CLIENT
Definition: wait_event.h:22
WaitEventTimeout
Definition: wait_event.h:142
@ WAIT_EVENT_VACUUM_TRUNCATE
Definition: wait_event.h:148
@ WAIT_EVENT_BASE_BACKUP_THROTTLE
Definition: wait_event.h:143
@ WAIT_EVENT_PG_SLEEP
Definition: wait_event.h:144
@ WAIT_EVENT_RECOVERY_APPLY_DELAY
Definition: wait_event.h:145
@ WAIT_EVENT_VACUUM_DELAY
Definition: wait_event.h:147
@ WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL
Definition: wait_event.h:146
PGDLLIMPORT uint32 * my_wait_event_info
Definition: wait_event.c:38
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: wait_event.c:74
WaitEventClient
Definition: wait_event.h:62
@ WAIT_EVENT_CLIENT_READ
Definition: wait_event.h:63
@ WAIT_EVENT_GSS_OPEN_SERVER
Definition: wait_event.h:65
@ WAIT_EVENT_SSL_OPEN_SERVER
Definition: wait_event.h:68
@ WAIT_EVENT_LIBPQWALRECEIVER_RECEIVE
Definition: wait_event.h:67
@ WAIT_EVENT_LIBPQWALRECEIVER_CONNECT
Definition: wait_event.h:66
@ WAIT_EVENT_WAL_SENDER_WRITE_DATA
Definition: wait_event.h:70
@ WAIT_EVENT_CLIENT_WRITE
Definition: wait_event.h:64
@ WAIT_EVENT_WAL_SENDER_WAIT_WAL
Definition: wait_event.h:69
#define PG_WAIT_ACTIVITY
Definition: wait_event.h:21
void pgstat_reset_wait_event_storage(void)
Definition: wait_event.c:62
#define PG_WAIT_IO
Definition: wait_event.h:26
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: wait_event.h:262
static void pgstat_report_wait_end(void)
Definition: wait_event.h:278