LCOV - code coverage report
Current view: top level - src/backend/utils/activity - wait_event_funcs.c (source / functions) Hit Total Coverage
Test: PostgreSQL 17devel Lines: 22 22 100.0 %
Date: 2024-05-03 15:12:11 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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
      46           8 : pg_get_wait_events(PG_FUNCTION_ARGS)
      47             : {
      48             : #define PG_GET_WAIT_EVENTS_COLS 3
      49           8 :     ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
      50             :     char      **waiteventnames;
      51             :     int         nbextwaitevents;
      52             : 
      53             :     /* Build tuplestore to hold the result rows */
      54           8 :     InitMaterializedSRF(fcinfo, 0);
      55             : 
      56             :     /* Iterate over the list of wait events */
      57        2120 :     for (int idx = 0; waitEventData[idx].type != NULL; idx++)
      58             :     {
      59        2112 :         Datum       values[PG_GET_WAIT_EVENTS_COLS] = {0};
      60        2112 :         bool        nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
      61             : 
      62        2112 :         values[0] = CStringGetTextDatum(waitEventData[idx].type);
      63        2112 :         values[1] = CStringGetTextDatum(waitEventData[idx].name);
      64        2112 :         values[2] = CStringGetTextDatum(waitEventData[idx].description);
      65             : 
      66        2112 :         tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
      67             :     }
      68             : 
      69             :     /* Handle custom wait events for extensions */
      70           8 :     waiteventnames = GetWaitEventExtensionNames(&nbextwaitevents);
      71             : 
      72          10 :     for (int idx = 0; idx < nbextwaitevents; idx++)
      73             :     {
      74             :         StringInfoData buf;
      75           2 :         Datum       values[PG_GET_WAIT_EVENTS_COLS] = {0};
      76           2 :         bool        nulls[PG_GET_WAIT_EVENTS_COLS] = {0};
      77             : 
      78             : 
      79           2 :         values[0] = CStringGetTextDatum("Extension");
      80           2 :         values[1] = CStringGetTextDatum(waiteventnames[idx]);
      81             : 
      82           2 :         initStringInfo(&buf);
      83           2 :         appendStringInfo(&buf,
      84             :                          "Waiting for custom wait event \"%s\" defined by extension module",
      85           2 :                          waiteventnames[idx]);
      86             : 
      87           2 :         values[2] = CStringGetTextDatum(buf.data);
      88             : 
      89           2 :         tuplestore_putvalues(rsinfo->setResult, rsinfo->setDesc, values, nulls);
      90             :     }
      91             : 
      92           8 :     return (Datum) 0;
      93             : }

Generated by: LCOV version 1.14