1 /*-------------------------------------------------------------------------
3 * Definitions related to wait event reporting
5 * Copyright (c) 2001-2023, PostgreSQL Global Development Group
7 * src/include/utils/wait_event.h
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
28 /* enums for wait events */
29 #include "utils/wait_event_types.h"
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);
38 extern PGDLLIMPORT uint32
*my_wait_event_info
;
42 * Wait Events - Extension
44 * Use this category when the server process is waiting for some condition
45 * defined by an extension module.
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.
54 * The ID retrieved can be used with pgstat_report_wait_start() or equivalent.
58 WAIT_EVENT_EXTENSION
= PG_WAIT_EXTENSION
,
59 WAIT_EVENT_EXTENSION_FIRST_USER_DEFINED
62 extern void WaitEventExtensionShmemInit(void);
63 extern Size
WaitEventExtensionShmemSize(void);
65 extern uint32
WaitEventExtensionNew(const char *wait_event_name
);
68 * pgstat_report_wait_start() -
70 * Called from places where server process needs to wait. This is called
71 * to report wait event information. The wait information is stored
72 * as 4-bytes where first byte represents the wait event class (type of
73 * wait, for different types of wait, refer WaitClass) and the next
74 * 3-bytes represent the actual wait event. Currently 2-bytes are used
75 * for wait event which is sufficient for current usage, 1-byte is
76 * reserved for future usage.
78 * Historically we used to make this reporting conditional on
79 * pgstat_track_activities, but the check for that seems to add more cost
82 * my_wait_event_info initially points to local memory, making it safe to
83 * call this before MyProc has been initialized.
87 pgstat_report_wait_start(uint32 wait_event_info
)
90 * Since this is a four-byte field which is always read and written as
91 * four-bytes, updates are atomic.
93 *(volatile uint32
*) my_wait_event_info
= wait_event_info
;
97 * pgstat_report_wait_end() -
99 * Called to report end of a wait.
103 pgstat_report_wait_end(void)
105 /* see pgstat_report_wait_start() */
106 *(volatile uint32
*) my_wait_event_info
= 0;
110 #endif /* WAIT_EVENT_H */