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 {
129 } WaitEventIPC;
130 
131 /* ----------
132  * Wait Events - Timeout
133  *
134  * Use this category when a process is waiting for a timeout to expire.
135  * ----------
136  */
137 typedef enum
138 {
145 
146 /* ----------
147  * Wait Events - IO
148  *
149  * Use this category when a process is waiting for a IO.
150  * ----------
151  */
152 typedef enum
153 {
228 } WaitEventIO;
229 
230 
231 extern const char *pgstat_get_wait_event(uint32 wait_event_info);
232 extern const char *pgstat_get_wait_event_type(uint32 wait_event_info);
233 static inline void pgstat_report_wait_start(uint32 wait_event_info);
234 static inline void pgstat_report_wait_end(void);
235 extern void pgstat_set_wait_event_storage(uint32 *wait_event_info);
236 extern void pgstat_reset_wait_event_storage(void);
237 
239 
240 
241 /* ----------
242  * pgstat_report_wait_start() -
243  *
244  * Called from places where server process needs to wait. This is called
245  * to report wait event information. The wait information is stored
246  * as 4-bytes where first byte represents the wait event class (type of
247  * wait, for different types of wait, refer WaitClass) and the next
248  * 3-bytes represent the actual wait event. Currently 2-bytes are used
249  * for wait event which is sufficient for current usage, 1-byte is
250  * reserved for future usage.
251  *
252  * Historically we used to make this reporting conditional on
253  * pgstat_track_activities, but the check for that seems to add more cost
254  * than it saves.
255  *
256  * my_wait_event_info initially points to local memory, making it safe to
257  * call this before MyProc has been initialized.
258  * ----------
259  */
260 static inline void
262 {
263  /*
264  * Since this is a four-byte field which is always read and written as
265  * four-bytes, updates are atomic.
266  */
267  *(volatile uint32 *) my_wait_event_info = wait_event_info;
268 }
269 
270 /* ----------
271  * pgstat_report_wait_end() -
272  *
273  * Called to report end of a wait.
274  * ----------
275  */
276 static inline void
278 {
279  /* see pgstat_report_wait_start() */
280  *(volatile uint32 *) my_wait_event_info = 0;
281 }
282 
283 
284 #endif /* WAIT_EVENT_H */
void pgstat_reset_wait_event_storage(void)
Definition: wait_event.c:62
#define PG_WAIT_IO
Definition: wait_event.h:26
WaitEventIPC
Definition: wait_event.h:80
static void pgstat_report_wait_end(void)
Definition: wait_event.h:277
#define PG_WAIT_IPC
Definition: wait_event.h:24
#define PG_WAIT_TIMEOUT
Definition: wait_event.h:25
#define PGDLLIMPORT
Definition: c.h:1317
WaitEventTimeout
Definition: wait_event.h:137
#define PG_WAIT_CLIENT
Definition: wait_event.h:22
void pgstat_set_wait_event_storage(uint32 *wait_event_info)
Definition: wait_event.c:50
unsigned int uint32
Definition: c.h:441
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: wait_event.h:261
WaitEventClient
Definition: wait_event.h:61
WaitEventIO
Definition: wait_event.h:152
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: wait_event.c:74
WaitEventActivity
Definition: wait_event.h:36
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: wait_event.c:129
PGDLLIMPORT uint32 * my_wait_event_info
Definition: wait_event.c:38
#define PG_WAIT_ACTIVITY
Definition: wait_event.h:21