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-2024, 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  */
25 static const struct
26 {
27  const char *type;
28  const char *name;
29  const char *description;
30 }
31 
32  waitEventData[] =
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  */
45 Datum
47 {
48 #define PG_GET_WAIT_EVENTS_COLS 3
49  ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
50  char **waiteventnames;
51  int nbextwaitevents;
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 */
70  waiteventnames = GetWaitEventExtensionNames(&nbextwaitevents);
71 
72  for (int idx = 0; idx < nbextwaitevents; idx++)
73  {
76  bool nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
77 
78 
79  values[0] = CStringGetTextDatum("Extension");
80  values[1] = CStringGetTextDatum(waiteventnames[idx]);
81 
84  "Waiting for custom wait event \"%s\" defined by extension module",
85  waiteventnames[idx]);
86 
87  values[2] = CStringGetTextDatum(buf.data);
88 
89  tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
90  }
91 
92  return (Datum) 0;
93 }
Datum idx(PG_FUNCTION_ARGS)
Definition: _int_op.c:259
static Datum values[MAXATTR]
Definition: bootstrap.c:152
#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:73
uintptr_t Datum
Definition: postgres.h:64
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:97
void initStringInfo(StringInfo str)
Definition: stringinfo.c:59
TupleDesc setDesc
Definition: execnodes.h:340
Tuplestorestate * setResult
Definition: execnodes.h:339
void tuplestore_putvalues(Tuplestorestate *state, TupleDesc tdesc, const Datum *values, const bool *isnull)
Definition: tuplestore.c:750
char ** GetWaitEventExtensionNames(int *nwaitevents)
Definition: wait_event.c:271
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)