LCOV - code coverage report
Current view: top level - src/include/utils - wait_event.h (source / functions) Hit Total Coverage
Test: PostgreSQL 15devel Lines: 6 6 100.0 %
Date: 2021-12-09 03:08:47 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-2021, 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_BUFFER_PIN          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             : 
      28             : /* ----------
      29             :  * Wait Events - Activity
      30             :  *
      31             :  * Use this category when a process is waiting because it has no work to do,
      32             :  * unless the "Client" or "Timeout" category describes the situation better.
      33             :  * Typically, this should only be used for background processes.
      34             :  * ----------
      35             :  */
      36             : typedef enum
      37             : {
      38             :     WAIT_EVENT_ARCHIVER_MAIN = PG_WAIT_ACTIVITY,
      39             :     WAIT_EVENT_AUTOVACUUM_MAIN,
      40             :     WAIT_EVENT_BGWRITER_HIBERNATE,
      41             :     WAIT_EVENT_BGWRITER_MAIN,
      42             :     WAIT_EVENT_CHECKPOINTER_MAIN,
      43             :     WAIT_EVENT_LOGICAL_APPLY_MAIN,
      44             :     WAIT_EVENT_LOGICAL_LAUNCHER_MAIN,
      45             :     WAIT_EVENT_PGSTAT_MAIN,
      46             :     WAIT_EVENT_RECOVERY_WAL_STREAM,
      47             :     WAIT_EVENT_SYSLOGGER_MAIN,
      48             :     WAIT_EVENT_WAL_RECEIVER_MAIN,
      49             :     WAIT_EVENT_WAL_SENDER_MAIN,
      50             :     WAIT_EVENT_WAL_WRITER_MAIN
      51             : } WaitEventActivity;
      52             : 
      53             : /* ----------
      54             :  * Wait Events - Client
      55             :  *
      56             :  * Use this category when a process is waiting to send data to or receive data
      57             :  * from the frontend process to which it is connected.  This is never used for
      58             :  * a background process, which has no client connection.
      59             :  * ----------
      60             :  */
      61             : typedef enum
      62             : {
      63             :     WAIT_EVENT_CLIENT_READ = PG_WAIT_CLIENT,
      64             :     WAIT_EVENT_CLIENT_WRITE,
      65             :     WAIT_EVENT_GSS_OPEN_SERVER,
      66             :     WAIT_EVENT_LIBPQWALRECEIVER_CONNECT,
      67             :     WAIT_EVENT_LIBPQWALRECEIVER_RECEIVE,
      68             :     WAIT_EVENT_SSL_OPEN_SERVER,
      69             :     WAIT_EVENT_WAL_SENDER_WAIT_WAL,
      70             :     WAIT_EVENT_WAL_SENDER_WRITE_DATA,
      71             : } WaitEventClient;
      72             : 
      73             : /* ----------
      74             :  * Wait Events - IPC
      75             :  *
      76             :  * Use this category when a process cannot complete the work it is doing because
      77             :  * it is waiting for a notification from another process.
      78             :  * ----------
      79             :  */
      80             : typedef enum
      81             : {
      82             :     WAIT_EVENT_APPEND_READY = PG_WAIT_IPC,
      83             :     WAIT_EVENT_ARCHIVE_CLEANUP_COMMAND,
      84             :     WAIT_EVENT_ARCHIVE_COMMAND,
      85             :     WAIT_EVENT_BACKEND_TERMINATION,
      86             :     WAIT_EVENT_BACKUP_WAIT_WAL_ARCHIVE,
      87             :     WAIT_EVENT_BGWORKER_SHUTDOWN,
      88             :     WAIT_EVENT_BGWORKER_STARTUP,
      89             :     WAIT_EVENT_BTREE_PAGE,
      90             :     WAIT_EVENT_BUFFER_IO,
      91             :     WAIT_EVENT_CHECKPOINT_DONE,
      92             :     WAIT_EVENT_CHECKPOINT_START,
      93             :     WAIT_EVENT_EXECUTE_GATHER,
      94             :     WAIT_EVENT_HASH_BATCH_ALLOCATE,
      95             :     WAIT_EVENT_HASH_BATCH_ELECT,
      96             :     WAIT_EVENT_HASH_BATCH_LOAD,
      97             :     WAIT_EVENT_HASH_BUILD_ALLOCATE,
      98             :     WAIT_EVENT_HASH_BUILD_ELECT,
      99             :     WAIT_EVENT_HASH_BUILD_HASH_INNER,
     100             :     WAIT_EVENT_HASH_BUILD_HASH_OUTER,
     101             :     WAIT_EVENT_HASH_GROW_BATCHES_ALLOCATE,
     102             :     WAIT_EVENT_HASH_GROW_BATCHES_DECIDE,
     103             :     WAIT_EVENT_HASH_GROW_BATCHES_ELECT,
     104             :     WAIT_EVENT_HASH_GROW_BATCHES_FINISH,
     105             :     WAIT_EVENT_HASH_GROW_BATCHES_REPARTITION,
     106             :     WAIT_EVENT_HASH_GROW_BUCKETS_ALLOCATE,
     107             :     WAIT_EVENT_HASH_GROW_BUCKETS_ELECT,
     108             :     WAIT_EVENT_HASH_GROW_BUCKETS_REINSERT,
     109             :     WAIT_EVENT_LOGICAL_SYNC_DATA,
     110             :     WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE,
     111             :     WAIT_EVENT_MQ_INTERNAL,
     112             :     WAIT_EVENT_MQ_PUT_MESSAGE,
     113             :     WAIT_EVENT_MQ_RECEIVE,
     114             :     WAIT_EVENT_MQ_SEND,
     115             :     WAIT_EVENT_PARALLEL_BITMAP_SCAN,
     116             :     WAIT_EVENT_PARALLEL_CREATE_INDEX_SCAN,
     117             :     WAIT_EVENT_PARALLEL_FINISH,
     118             :     WAIT_EVENT_PROCARRAY_GROUP_UPDATE,
     119             :     WAIT_EVENT_PROC_SIGNAL_BARRIER,
     120             :     WAIT_EVENT_PROMOTE,
     121             :     WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT,
     122             :     WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE,
     123             :     WAIT_EVENT_RECOVERY_END_COMMAND,
     124             :     WAIT_EVENT_RECOVERY_PAUSE,
     125             :     WAIT_EVENT_REPLICATION_ORIGIN_DROP,
     126             :     WAIT_EVENT_REPLICATION_SLOT_DROP,
     127             :     WAIT_EVENT_RESTORE_COMMAND,
     128             :     WAIT_EVENT_SAFE_SNAPSHOT,
     129             :     WAIT_EVENT_SYNC_REP,
     130             :     WAIT_EVENT_WAL_RECEIVER_EXIT,
     131             :     WAIT_EVENT_WAL_RECEIVER_WAIT_START,
     132             :     WAIT_EVENT_XACT_GROUP_UPDATE
     133             : } WaitEventIPC;
     134             : 
     135             : /* ----------
     136             :  * Wait Events - Timeout
     137             :  *
     138             :  * Use this category when a process is waiting for a timeout to expire.
     139             :  * ----------
     140             :  */
     141             : typedef enum
     142             : {
     143             :     WAIT_EVENT_BASE_BACKUP_THROTTLE = PG_WAIT_TIMEOUT,
     144             :     WAIT_EVENT_PG_SLEEP,
     145             :     WAIT_EVENT_RECOVERY_APPLY_DELAY,
     146             :     WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL,
     147             :     WAIT_EVENT_VACUUM_DELAY,
     148             :     WAIT_EVENT_VACUUM_TRUNCATE
     149             : } WaitEventTimeout;
     150             : 
     151             : /* ----------
     152             :  * Wait Events - IO
     153             :  *
     154             :  * Use this category when a process is waiting for a IO.
     155             :  * ----------
     156             :  */
     157             : typedef enum
     158             : {
     159             :     WAIT_EVENT_BASEBACKUP_READ = PG_WAIT_IO,
     160             :     WAIT_EVENT_BUFFILE_READ,
     161             :     WAIT_EVENT_BUFFILE_WRITE,
     162             :     WAIT_EVENT_BUFFILE_TRUNCATE,
     163             :     WAIT_EVENT_CONTROL_FILE_READ,
     164             :     WAIT_EVENT_CONTROL_FILE_SYNC,
     165             :     WAIT_EVENT_CONTROL_FILE_SYNC_UPDATE,
     166             :     WAIT_EVENT_CONTROL_FILE_WRITE,
     167             :     WAIT_EVENT_CONTROL_FILE_WRITE_UPDATE,
     168             :     WAIT_EVENT_COPY_FILE_READ,
     169             :     WAIT_EVENT_COPY_FILE_WRITE,
     170             :     WAIT_EVENT_DATA_FILE_EXTEND,
     171             :     WAIT_EVENT_DATA_FILE_FLUSH,
     172             :     WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC,
     173             :     WAIT_EVENT_DATA_FILE_PREFETCH,
     174             :     WAIT_EVENT_DATA_FILE_READ,
     175             :     WAIT_EVENT_DATA_FILE_SYNC,
     176             :     WAIT_EVENT_DATA_FILE_TRUNCATE,
     177             :     WAIT_EVENT_DATA_FILE_WRITE,
     178             :     WAIT_EVENT_DSM_FILL_ZERO_WRITE,
     179             :     WAIT_EVENT_LOCK_FILE_ADDTODATADIR_READ,
     180             :     WAIT_EVENT_LOCK_FILE_ADDTODATADIR_SYNC,
     181             :     WAIT_EVENT_LOCK_FILE_ADDTODATADIR_WRITE,
     182             :     WAIT_EVENT_LOCK_FILE_CREATE_READ,
     183             :     WAIT_EVENT_LOCK_FILE_CREATE_SYNC,
     184             :     WAIT_EVENT_LOCK_FILE_CREATE_WRITE,
     185             :     WAIT_EVENT_LOCK_FILE_RECHECKDATADIR_READ,
     186             :     WAIT_EVENT_LOGICAL_REWRITE_CHECKPOINT_SYNC,
     187             :     WAIT_EVENT_LOGICAL_REWRITE_MAPPING_SYNC,
     188             :     WAIT_EVENT_LOGICAL_REWRITE_MAPPING_WRITE,
     189             :     WAIT_EVENT_LOGICAL_REWRITE_SYNC,
     190             :     WAIT_EVENT_LOGICAL_REWRITE_TRUNCATE,
     191             :     WAIT_EVENT_LOGICAL_REWRITE_WRITE,
     192             :     WAIT_EVENT_RELATION_MAP_READ,
     193             :     WAIT_EVENT_RELATION_MAP_SYNC,
     194             :     WAIT_EVENT_RELATION_MAP_WRITE,
     195             :     WAIT_EVENT_REORDER_BUFFER_READ,
     196             :     WAIT_EVENT_REORDER_BUFFER_WRITE,
     197             :     WAIT_EVENT_REORDER_LOGICAL_MAPPING_READ,
     198             :     WAIT_EVENT_REPLICATION_SLOT_READ,
     199             :     WAIT_EVENT_REPLICATION_SLOT_RESTORE_SYNC,
     200             :     WAIT_EVENT_REPLICATION_SLOT_SYNC,
     201             :     WAIT_EVENT_REPLICATION_SLOT_WRITE,
     202             :     WAIT_EVENT_SLRU_FLUSH_SYNC,
     203             :     WAIT_EVENT_SLRU_READ,
     204             :     WAIT_EVENT_SLRU_SYNC,
     205             :     WAIT_EVENT_SLRU_WRITE,
     206             :     WAIT_EVENT_SNAPBUILD_READ,
     207             :     WAIT_EVENT_SNAPBUILD_SYNC,
     208             :     WAIT_EVENT_SNAPBUILD_WRITE,
     209             :     WAIT_EVENT_TIMELINE_HISTORY_FILE_SYNC,
     210             :     WAIT_EVENT_TIMELINE_HISTORY_FILE_WRITE,
     211             :     WAIT_EVENT_TIMELINE_HISTORY_READ,
     212             :     WAIT_EVENT_TIMELINE_HISTORY_SYNC,
     213             :     WAIT_EVENT_TIMELINE_HISTORY_WRITE,
     214             :     WAIT_EVENT_TWOPHASE_FILE_READ,
     215             :     WAIT_EVENT_TWOPHASE_FILE_SYNC,
     216             :     WAIT_EVENT_TWOPHASE_FILE_WRITE,
     217             :     WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ,
     218             :     WAIT_EVENT_WAL_BOOTSTRAP_SYNC,
     219             :     WAIT_EVENT_WAL_BOOTSTRAP_WRITE,
     220             :     WAIT_EVENT_WAL_COPY_READ,
     221             :     WAIT_EVENT_WAL_COPY_SYNC,
     222             :     WAIT_EVENT_WAL_COPY_WRITE,
     223             :     WAIT_EVENT_WAL_INIT_SYNC,
     224             :     WAIT_EVENT_WAL_INIT_WRITE,
     225             :     WAIT_EVENT_WAL_READ,
     226             :     WAIT_EVENT_WAL_SYNC,
     227             :     WAIT_EVENT_WAL_SYNC_METHOD_ASSIGN,
     228             :     WAIT_EVENT_WAL_WRITE
     229             : } WaitEventIO;
     230             : 
     231             : 
     232             : extern const char *pgstat_get_wait_event(uint32 wait_event_info);
     233             : extern const char *pgstat_get_wait_event_type(uint32 wait_event_info);
     234             : static inline void pgstat_report_wait_start(uint32 wait_event_info);
     235             : static inline void pgstat_report_wait_end(void);
     236             : extern void pgstat_set_wait_event_storage(uint32 *wait_event_info);
     237             : extern void pgstat_reset_wait_event_storage(void);
     238             : 
     239             : extern PGDLLIMPORT uint32 *my_wait_event_info;
     240             : 
     241             : 
     242             : /* ----------
     243             :  * pgstat_report_wait_start() -
     244             :  *
     245             :  *  Called from places where server process needs to wait.  This is called
     246             :  *  to report wait event information.  The wait information is stored
     247             :  *  as 4-bytes where first byte represents the wait event class (type of
     248             :  *  wait, for different types of wait, refer WaitClass) and the next
     249             :  *  3-bytes represent the actual wait event.  Currently 2-bytes are used
     250             :  *  for wait event which is sufficient for current usage, 1-byte is
     251             :  *  reserved for future usage.
     252             :  *
     253             :  *  Historically we used to make this reporting conditional on
     254             :  *  pgstat_track_activities, but the check for that seems to add more cost
     255             :  *  than it saves.
     256             :  *
     257             :  *  my_wait_event_info initially points to local memory, making it safe to
     258             :  *  call this before MyProc has been initialized.
     259             :  * ----------
     260             :  */
     261             : static inline void
     262     9751240 : pgstat_report_wait_start(uint32 wait_event_info)
     263             : {
     264             :     /*
     265             :      * Since this is a four-byte field which is always read and written as
     266             :      * four-bytes, updates are atomic.
     267             :      */
     268     9751240 :     *(volatile uint32 *) my_wait_event_info = wait_event_info;
     269     9751240 : }
     270             : 
     271             : /* ----------
     272             :  * pgstat_report_wait_end() -
     273             :  *
     274             :  *  Called to report end of a wait.
     275             :  * ----------
     276             :  */
     277             : static inline void
     278     9783962 : pgstat_report_wait_end(void)
     279             : {
     280             :     /* see pgstat_report_wait_start() */
     281     9783962 :     *(volatile uint32 *) my_wait_event_info = 0;
     282     9783962 : }
     283             : 
     284             : 
     285             : #endif                          /* WAIT_EVENT_H */

Generated by: LCOV version 1.14