PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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/* enums for wait events */
14#include "utils/wait_event_types.h"
15
16extern const char *pgstat_get_wait_event(uint32 wait_event_info);
17extern const char *pgstat_get_wait_event_type(uint32 wait_event_info);
18static inline void pgstat_report_wait_start(uint32 wait_event_info);
19static inline void pgstat_report_wait_end(void);
20extern void pgstat_set_wait_event_storage(uint32 *wait_event_info);
21extern void pgstat_reset_wait_event_storage(void);
22
24
25
26/*
27 * Wait Events - Extension, InjectionPoint
28 *
29 * Use InjectionPoint when the server process is waiting in an injection
30 * point. Use Extension for other cases of the server process waiting for
31 * some condition defined by an extension module.
32 *
33 * Extensions can define their own wait events in these categories. They
34 * should call one of these functions with a wait event string. If the wait
35 * event associated to a string is already allocated, it returns the wait
36 * event information to use. If not, it gets one wait event ID allocated from
37 * a shared counter, associates the string to the ID in the shared dynamic
38 * hash and returns the wait event information.
39 *
40 * The ID retrieved can be used with pgstat_report_wait_start() or equivalent.
41 */
42extern uint32 WaitEventExtensionNew(const char *wait_event_name);
43extern uint32 WaitEventInjectionPointNew(const char *wait_event_name);
44
45extern char **GetWaitEventCustomNames(uint32 classId, int *nwaitevents);
46
47/* ----------
48 * pgstat_report_wait_start() -
49 *
50 * Called from places where server process needs to wait. This is called
51 * to report wait event information. The wait information is stored
52 * as 4-bytes where first byte represents the wait event class (type of
53 * wait, for different types of wait, refer WaitClass) and the next
54 * 3-bytes represent the actual wait event. Currently 2-bytes are used
55 * for wait event which is sufficient for current usage, 1-byte is
56 * reserved for future usage.
57 *
58 * Historically we used to make this reporting conditional on
59 * pgstat_track_activities, but the check for that seems to add more cost
60 * than it saves.
61 *
62 * my_wait_event_info initially points to local memory, making it safe to
63 * call this before MyProc has been initialized.
64 * ----------
65 */
66static inline void
68{
69 /*
70 * Since this is a four-byte field which is always read and written as
71 * four-bytes, updates are atomic.
72 */
73 *(volatile uint32 *) my_wait_event_info = wait_event_info;
74}
75
76/* ----------
77 * pgstat_report_wait_end() -
78 *
79 * Called to report end of a wait.
80 * ----------
81 */
82static inline void
84{
85 /* see pgstat_report_wait_start() */
86 *(volatile uint32 *) my_wait_event_info = 0;
87}
88
89
90#endif /* WAIT_EVENT_H */
#define PGDLLIMPORT
Definition c.h:1421
uint32_t uint32
Definition c.h:624
static int fb(int x)
char ** GetWaitEventCustomNames(uint32 classId, int *nwaitevents)
Definition wait_event.c:292
const char * pgstat_get_wait_event_type(uint32 wait_event_info)
Definition wait_event.c:359
void pgstat_set_wait_event_storage(uint32 *wait_event_info)
Definition wait_event.c:335
const char * pgstat_get_wait_event(uint32 wait_event_info)
Definition wait_event.c:417
PGDLLIMPORT uint32 * my_wait_event_info
Definition wait_event.c:42
uint32 WaitEventInjectionPointNew(const char *wait_event_name)
Definition wait_event.c:155
void pgstat_reset_wait_event_storage(void)
Definition wait_event.c:347
static void pgstat_report_wait_start(uint32 wait_event_info)
Definition wait_event.h:67
uint32 WaitEventExtensionNew(const char *wait_event_name)
Definition wait_event.c:149
static void pgstat_report_wait_end(void)
Definition wait_event.h:83