LCOV - code coverage report
Current view: top level - src/include/utils - wait_event.h (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 6 6 100.0 %
Date: 2025-01-18 04:15:08 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*-------------------------------------------------------------------------
       2             :  * wait_event.h
       3             :  *    Definitions related to wait event reporting
       4             :  *
       5             :  * Copyright (c) 2001-2025, PostgreSQL Global Development Group
       6             :  *
       7             :  * src/include/utils/wait_event.h
       8             :  * ----------
       9             :  */
      10             : #ifndef WAIT_EVENT_H
      11             : #define WAIT_EVENT_H
      12             : 
      13             : 
      14             : /* ----------
      15             :  * Wait Classes
      16             :  * ----------
      17             :  */
      18             : #define PG_WAIT_LWLOCK              0x01000000U
      19             : #define PG_WAIT_LOCK                0x03000000U
      20             : #define PG_WAIT_BUFFERPIN           0x04000000U
      21             : #define PG_WAIT_ACTIVITY            0x05000000U
      22             : #define PG_WAIT_CLIENT              0x06000000U
      23             : #define PG_WAIT_EXTENSION           0x07000000U
      24             : #define PG_WAIT_IPC                 0x08000000U
      25             : #define PG_WAIT_TIMEOUT             0x09000000U
      26             : #define PG_WAIT_IO                  0x0A000000U
      27             : #define PG_WAIT_INJECTIONPOINT      0x0B000000U
      28             : 
      29             : /* enums for wait events */
      30             : #include "utils/wait_event_types.h"
      31             : 
      32             : extern const char *pgstat_get_wait_event(uint32 wait_event_info);
      33             : extern const char *pgstat_get_wait_event_type(uint32 wait_event_info);
      34             : static inline void pgstat_report_wait_start(uint32 wait_event_info);
      35             : static inline void pgstat_report_wait_end(void);
      36             : extern void pgstat_set_wait_event_storage(uint32 *wait_event_info);
      37             : extern void pgstat_reset_wait_event_storage(void);
      38             : 
      39             : extern PGDLLIMPORT uint32 *my_wait_event_info;
      40             : 
      41             : 
      42             : /*
      43             :  * Wait Events - Extension, InjectionPoint
      44             :  *
      45             :  * Use InjectionPoint when the server process is waiting in an injection
      46             :  * point.  Use Extension for other cases of the server process waiting for
      47             :  * some condition defined by an extension module.
      48             :  *
      49             :  * Extensions can define their own wait events in these categories.  They
      50             :  * should call one of these functions with a wait event string.  If the wait
      51             :  * event associated to a string is already allocated, it returns the wait
      52             :  * event information to use.  If not, it gets one wait event ID allocated from
      53             :  * a shared counter, associates the string to the ID in the shared dynamic
      54             :  * hash and returns the wait event information.
      55             :  *
      56             :  * The ID retrieved can be used with pgstat_report_wait_start() or equivalent.
      57             :  */
      58             : extern uint32 WaitEventExtensionNew(const char *wait_event_name);
      59             : extern uint32 WaitEventInjectionPointNew(const char *wait_event_name);
      60             : 
      61             : extern void WaitEventCustomShmemInit(void);
      62             : extern Size WaitEventCustomShmemSize(void);
      63             : extern char **GetWaitEventCustomNames(uint32 classId, int *nwaitevents);
      64             : 
      65             : /* ----------
      66             :  * pgstat_report_wait_start() -
      67             :  *
      68             :  *  Called from places where server process needs to wait.  This is called
      69             :  *  to report wait event information.  The wait information is stored
      70             :  *  as 4-bytes where first byte represents the wait event class (type of
      71             :  *  wait, for different types of wait, refer WaitClass) and the next
      72             :  *  3-bytes represent the actual wait event.  Currently 2-bytes are used
      73             :  *  for wait event which is sufficient for current usage, 1-byte is
      74             :  *  reserved for future usage.
      75             :  *
      76             :  *  Historically we used to make this reporting conditional on
      77             :  *  pgstat_track_activities, but the check for that seems to add more cost
      78             :  *  than it saves.
      79             :  *
      80             :  *  my_wait_event_info initially points to local memory, making it safe to
      81             :  *  call this before MyProc has been initialized.
      82             :  * ----------
      83             :  */
      84             : static inline void
      85    37251010 : pgstat_report_wait_start(uint32 wait_event_info)
      86             : {
      87             :     /*
      88             :      * Since this is a four-byte field which is always read and written as
      89             :      * four-bytes, updates are atomic.
      90             :      */
      91    37251010 :     *(volatile uint32 *) my_wait_event_info = wait_event_info;
      92    37251010 : }
      93             : 
      94             : /* ----------
      95             :  * pgstat_report_wait_end() -
      96             :  *
      97             :  *  Called to report end of a wait.
      98             :  * ----------
      99             :  */
     100             : static inline void
     101    37311948 : pgstat_report_wait_end(void)
     102             : {
     103             :     /* see pgstat_report_wait_start() */
     104    37311948 :     *(volatile uint32 *) my_wait_event_info = 0;
     105    37311948 : }
     106             : 
     107             : 
     108             : #endif                          /* WAIT_EVENT_H */

Generated by: LCOV version 1.14