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 {
146 
147 /* ----------
148  * Wait Events - IO
149  *
150  * Use this category when a process is waiting for a IO.
151  * ----------
152  */
153 typedef enum
154 {
229 } WaitEventIO;
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 */
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:278
#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:262
WaitEventClient
Definition: wait_event.h:61
WaitEventIO
Definition: wait_event.h:153
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