PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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-2026, 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/tuplestore.h"
20#include "utils/wait_event.h"
21
22/*
23 * Each wait event has one corresponding entry in this structure, fed to
24 * the SQL function of this file.
25 */
26static const struct
27{
28 const char *type;
29 const char *name;
30 const char *description;
31}
32
34{
35#include "utils/wait_event_funcs_data.c"
36 /* end of list */
37 {NULL, NULL, NULL}
38};
39
40
41/*
42 * pg_get_wait_events
43 *
44 * List information about wait events (type, name and description).
45 */
48{
49#define PG_GET_WAIT_EVENTS_COLS 3
50 ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
51 char **waiteventnames;
52 int nbwaitevents;
53
54 /* Build tuplestore to hold the result rows */
55 InitMaterializedSRF(fcinfo, 0);
56
57 /* Iterate over the list of wait events */
58 for (int idx = 0; waitEventData[idx].type != NULL; idx++)
59 {
61 bool nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
62
66
67 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
68 }
69
70 /* Handle custom wait events for extensions */
73
74 for (int idx = 0; idx < nbwaitevents; idx++)
75 {
78 bool nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
79
80
81 values[0] = CStringGetTextDatum("Extension");
83
86 "Waiting for custom wait event \"%s\" defined by extension module",
88
90
91 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
92 }
93
94 /* Likewise for injection points */
97
98 for (int idx = 0; idx < nbwaitevents; idx++)
99 {
102 bool nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
103
104
105 values[0] = CStringGetTextDatum("InjectionPoint");
107
110 "Waiting for injection point \"%s\"",
112
113 values[2] = CStringGetTextDatum(buf.data);
114
115 tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
116 }
117
118 return (Datum) 0;
119}
Datum idx(PG_FUNCTION_ARGS)
Definition _int_op.c:262
static Datum values[MAXATTR]
Definition bootstrap.c:188
#define CStringGetTextDatum(s)
Definition builtins.h:98
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
void InitMaterializedSRF(FunctionCallInfo fcinfo, bits32 flags)
Definition funcapi.c:76
static char buf[DEFAULT_XLOG_SEG_SIZE]
uint64_t Datum
Definition postgres.h:70
static int fb(int x)
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
void initStringInfo(StringInfo str)
Definition stringinfo.c:97
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition tuplestore.c:785
#define PG_WAIT_INJECTIONPOINT
#define PG_WAIT_EXTENSION
char ** GetWaitEventCustomNames(uint32 classId, int *nwaitevents)
Definition wait_event.c:306
const char * description
const char * type
#define PG_GET_WAIT_EVENTS_COLS
static const struct @23 waitEventData[]
const char * name
Datum pg_get_wait_events(PG_FUNCTION_ARGS)