1 /*------------------------------------------------------------------------
4 * Functions for accessing wait event data.
6 * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/utils/activity/wait_event_funcs.c
13 *------------------------------------------------------------------------
18 #include "utils/builtins.h"
19 #include "utils/wait_event.h"
22 * Each wait event has one corresponding entry in this structure, fed to
23 * the SQL function of this file.
29 const char *description
;
34 #include "wait_event_funcs_data.c"
43 * List information about wait events (type, name and description).
46 pg_get_wait_events(PG_FUNCTION_ARGS
)
48 #define PG_GET_WAIT_EVENTS_COLS 3
49 ReturnSetInfo
*rsinfo
= (ReturnSetInfo
*) fcinfo
->resultinfo
;
50 char **waiteventnames
;
53 /* Build tuplestore to hold the result rows */
54 InitMaterializedSRF(fcinfo
, 0);
56 /* Iterate over the list of wait events */
57 for (int idx
= 0; waitEventData
[idx
].type
!= NULL
; idx
++)
59 Datum values
[PG_GET_WAIT_EVENTS_COLS
] = {0};
60 bool nulls
[PG_GET_WAIT_EVENTS_COLS
] = {0};
62 values
[0] = CStringGetTextDatum(waitEventData
[idx
].type
);
63 values
[1] = CStringGetTextDatum(waitEventData
[idx
].name
);
64 values
[2] = CStringGetTextDatum(waitEventData
[idx
].description
);
66 tuplestore_putvalues(rsinfo
->setResult
, rsinfo
->setDesc
, values
, nulls
);
69 /* Handle custom wait events for extensions */
70 waiteventnames
= GetWaitEventCustomNames(PG_WAIT_EXTENSION
,
73 for (int idx
= 0; idx
< nbwaitevents
; idx
++)
76 Datum values
[PG_GET_WAIT_EVENTS_COLS
] = {0};
77 bool nulls
[PG_GET_WAIT_EVENTS_COLS
] = {0};
80 values
[0] = CStringGetTextDatum("Extension");
81 values
[1] = CStringGetTextDatum(waiteventnames
[idx
]);
84 appendStringInfo(&buf
,
85 "Waiting for custom wait event \"%s\" defined by extension module",
88 values
[2] = CStringGetTextDatum(buf
.data
);
90 tuplestore_putvalues(rsinfo
->setResult
, rsinfo
->setDesc
, values
, nulls
);
93 /* Likewise for injection points */
94 waiteventnames
= GetWaitEventCustomNames(PG_WAIT_INJECTIONPOINT
,
97 for (int idx
= 0; idx
< nbwaitevents
; idx
++)
100 Datum values
[PG_GET_WAIT_EVENTS_COLS
] = {0};
101 bool nulls
[PG_GET_WAIT_EVENTS_COLS
] = {0};
104 values
[0] = CStringGetTextDatum("InjectionPoint");
105 values
[1] = CStringGetTextDatum(waiteventnames
[idx
]);
107 initStringInfo(&buf
);
108 appendStringInfo(&buf
,
109 "Waiting for injection point \"%s\"",
110 waiteventnames
[idx
]);
112 values
[2] = CStringGetTextDatum(buf
.data
);
114 tuplestore_putvalues(rsinfo
->setResult
, rsinfo
->setDesc
, values
, nulls
);