PostgreSQL Source Code git master
wait_event_funcs.c
Go to the documentation of this file.
1/*------------------------------------------------------------------------
2 *
3 * wait_event_funcs.c
4 * Functions for accessing wait event data.
5 *
6 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
8 *
9 *
10 * IDENTIFICATION
11 * src/backend/utils/activity/wait_event_funcs.c
12 *
13 *------------------------------------------------------------------------
14 */
15#include "postgres.h"
16
17#include "funcapi.h"
18#include "utils/builtins.h"
19#include "utils/wait_event.h"
20
21/*
22 * Each wait event has one corresponding entry in this structure, fed to
23 * the SQL function of this file.
24 */
25static const struct
26{
27 const char *type;
28 const char *name;
29 const char *description;
30}
31
33{
34#include "wait_event_funcs_data.c"
35 /* end of list */
36 {NULL, NULL, NULL}
37};
38
39
40/*
41 * pg_get_wait_events
42 *
43 * List information about wait events (type, name and description).
44 */
47{
48#define PG_GET_WAIT_EVENTS_COLS 3
49 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
50 char **waiteventnames;
51 int nbwaitevents;
52
53 /* Build tuplestore to hold the result rows */
54 InitMaterializedSRF(fcinfo, 0);
55
56 /* Iterate over the list of wait events */
57 for (int idx = 0; waitEventData[idx].type != NULL; idx++)
58 {
60 bool nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
61
65
66 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
67 }
68
69 /* Handle custom wait events for extensions */
71 &nbwaitevents);
72
73 for (int idx = 0; idx < nbwaitevents; idx++)
74 {
77 bool nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
78
79
80 values[0] = CStringGetTextDatum("Extension");
81 values[1] = CStringGetTextDatum(waiteventnames[idx]);
82
85 "Waiting for custom wait event \"%s\" defined by extension module",
86 waiteventnames[idx]);
87
89
90 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
91 }
92
93 /* Likewise for injection points */
95 &nbwaitevents);
96
97 for (int idx = 0; idx < nbwaitevents; idx++)
98 {
101 bool nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
102
103
104 values[0] = CStringGetTextDatum("InjectionPoint");
105 values[1] = CStringGetTextDatum(waiteventnames[idx]);
106
109 "Waiting for injection point \"%s\"",
110 waiteventnames[idx]);
111
112 values[2] = CStringGetTextDatum(buf.data);
113
114 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
115 }
116
117 return (Datum) 0;
118}
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
static Datum values[MAXATTR]
Definition: bootstrap.c:151
#define CStringGetTextDatum(s)
Definition: builtins.h:97
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition: funcapi.c:76
static char * buf
Definition: pg_test_fsync.c:72
uintptr_t Datum
Definition: postgres.h:64
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:145
void initStringInfo(StringInfo str)
Definition: stringinfo.c:97
TupleDesc setDesc
Definition: execnodes.h:343
Tuplestorestate * setResult
Definition: execnodes.h:342
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition: tuplestore.c:784
char ** GetWaitEventCustomNames(uint32 classId, int *nwaitevents)
Definition: wait_event.c:306
#define PG_WAIT_INJECTIONPOINT
Definition: wait_event.h:27
#define PG_WAIT_EXTENSION
Definition: wait_event.h:23
static const struct @21 waitEventData[]
const char * description
const char * type
#define PG_GET_WAIT_EVENTS_COLS
const char * name
Datum pg_get_wait_events(PG_FUNCTION_ARGS)