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-2024, 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_BUFFERPIN 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 /* enums for wait events */
29 #include "utils/wait_event_types.h"
30 
31 extern const char *pgstat_get_wait_event(uint32 wait_event_info);
32 extern const char *pgstat_get_wait_event_type(uint32 wait_event_info);
33 static inline void pgstat_report_wait_start(uint32 wait_event_info);
34 static inline void pgstat_report_wait_end(void);
35 extern void pgstat_set_wait_event_storage(uint32 *wait_event_info);
36 extern void pgstat_reset_wait_event_storage(void);
37 
39 
40 
41 /* ----------
42  * Wait Events - Extension
43  *
44  * Use this category when the server process is waiting for some condition
45  * defined by an extension module.
46  *
47  * Extensions can define their own wait events in this category. They should
48  * call WaitEventExtensionNew() with a wait event string. If the wait event
49  * associated to a string is already allocated, it returns the wait event
50  * information to use. If not, it gets one wait event ID allocated from
51  * a shared counter, associates the string to the ID in the shared dynamic
52  * hash and returns the wait event information.
53  *
54  * The ID retrieved can be used with pgstat_report_wait_start() or equivalent.
55  */
56 typedef enum
57 {
61 
62 extern void WaitEventExtensionShmemInit(void);
64 
65 extern uint32 WaitEventExtensionNew(const char *wait_event_name);
66 extern char **GetWaitEventExtensionNames(int *nwaitevents);
67 
68 /* ----------
69  * pgstat_report_wait_start() -
70  *
71  * Called from places where server process needs to wait. This is called
72  * to report wait event information. The wait information is stored
73  * as 4-bytes where first byte represents the wait event class (type of
74  * wait, for different types of wait, refer WaitClass) and the next
75  * 3-bytes represent the actual wait event. Currently 2-bytes are used
76  * for wait event which is sufficient for current usage, 1-byte is
77  * reserved for future usage.
78  *
79  * Historically we used to make this reporting conditional on
80  * pgstat_track_activities, but the check for that seems to add more cost
81  * than it saves.
82  *
83  * my_wait_event_info initially points to local memory, making it safe to
84  * call this before MyProc has been initialized.
85  * ----------
86  */
87 static inline void
89 {
90  /*
91  * Since this is a four-byte field which is always read and written as
92  * four-bytes, updates are atomic.
93  */
94  *(volatile uint32 *) my_wait_event_info = wait_event_info;
95 }
96 
97 /* ----------
98  * pgstat_report_wait_end() -
99  *
100  * Called to report end of a wait.
101  * ----------
102  */
103 static inline void
105 {
106  /* see pgstat_report_wait_start() */
107  *(volatile uint32 *) my_wait_event_info = 0;
108 }
109 
110 
111 #endif /* WAIT_EVENT_H */
unsigned int uint32
Definition: c.h:506
#define PGDLLIMPORT
Definition: c.h:1316
size_t Size
Definition: c.h:605
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition: wait_event.c:393
void pgstat_set_wait_event_storage(uint32 *wait_event_info)
Definition: wait_event.c:314
Size WaitEventExtensionShmemSize(void)
Definition: wait_event.c:104
PGDLLIMPORT uint32 * my_wait_event_info
Definition: wait_event.c:41
#define PG_WAIT_EXTENSION
Definition: wait_event.h:23
WaitEventExtension
Definition: wait_event.h:57
@ WAIT_EVENT_EXTENSION
Definition: wait_event.h:58
@ WAIT_EVENT_EXTENSION_FIRST_USER_DEFINED
Definition: wait_event.h:59
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition: wait_event.c:338
void pgstat_reset_wait_event_storage(void)
Definition: wait_event.c:326
char ** GetWaitEventExtensionNames(int *nwaitevents)
Definition: wait_event.c:271
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition: wait_event.h:88
uint32 WaitEventExtensionNew(const char *wait_event_name)
Definition: wait_event.c:162
void WaitEventExtensionShmemInit(void)
Definition: wait_event.c:120
static void pgstat_report_wait_end(void)
Definition: wait_event.h:104