diff options
author | Michael Paquier <michael@paquier.xyz> | 2023-07-05 10:53:11 +0900 |
---|---|---|
committer | Michael Paquier <michael@paquier.xyz> | 2023-07-05 10:53:11 +0900 |
commit | fa88928470b538c0ec0289e4d69ee12356c5a8ce (patch) | |
tree | 283fe4db54194ce1348c56e27233543864654d24 /src/include | |
parent | 48efb2302bea3b2af8b4bb865edcc70132ee4250 (diff) | |
download | postgresql-fa88928470b538c0ec0289e4d69ee12356c5a8ce.tar.gz postgresql-fa88928470b538c0ec0289e4d69ee12356c5a8ce.zip |
Generate automatically code and documentation related to wait events
The documentation and the code is generated automatically from a new
file called wait_event_names.txt, formatted in sections dedicated to
each wait event class (Timeout, Lock, IO, etc.) with three tab-separated
fields:
- C symbol in enums
- Format in the system views
- Description in the docs
Using this approach has several advantages, as we have proved to be
rather bad in maintaining this area of the tree across the years:
- The order of each item in the documentation and the code, which should
be alphabetical, has become incorrect multiple times, and the script
generating the code and documentation has a few rules to enforce that,
making the maintenance a no-brainer.
- Some wait events were added to the code, but not documented, so this
cannot be missed now.
- The order of the tables for each wait event class is enforced in the
documentation (the input .txt file does so as well for clarity, though
this is not mandatory).
- Less code, shaving 1.2k lines from the tree, with 1/3 of the savings
coming from the code, the rest from the documentation.
The wait event types "Lock" and "LWLock" still have their own code path
for their code, hence only the documentation is created for them. These
classes are listed with a special marker called WAIT_EVENT_DOCONLY in
the input file.
Adding a new wait event now requires only an update of
wait_event_names.txt, with "Lock" and "LWLock" treated as exceptions.
This commit has been tested with configure/Makefile, the CI and VPATH
build. clean, distclean and maintainer-clean were working fine.
Author: Bertrand Drouvot, Michael Paquier
Discussion: https://postgr.es/m/77a86b3a-c4a8-5f5d-69b9-d70bbf2e9b98@gmail.com
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/Makefile | 2 | ||||
-rw-r--r-- | src/include/utils/.gitignore | 1 | ||||
-rw-r--r-- | src/include/utils/meson.build | 19 | ||||
-rw-r--r-- | src/include/utils/wait_event.h | 232 |
4 files changed, 23 insertions, 231 deletions
diff --git a/src/include/Makefile b/src/include/Makefile index 56576dcf5c9..5d213187e24 100644 --- a/src/include/Makefile +++ b/src/include/Makefile @@ -72,7 +72,7 @@ uninstall: clean: rm -f utils/fmgroids.h utils/fmgrprotos.h utils/errcodes.h utils/header-stamp - rm -f storage/lwlocknames.h utils/probes.h + rm -f storage/lwlocknames.h utils/probes.h utils/wait_event_types.h rm -f catalog/schemapg.h catalog/system_fk_info.h rm -f catalog/pg_*_d.h catalog/header-stamp rm -f nodes/nodetags.h nodes/header-stamp diff --git a/src/include/utils/.gitignore b/src/include/utils/.gitignore index 05cfa7a8d6c..c1b4c662139 100644 --- a/src/include/utils/.gitignore +++ b/src/include/utils/.gitignore @@ -3,3 +3,4 @@ /probes.h /errcodes.h /header-stamp +/wait_event_types.h diff --git a/src/include/utils/meson.build b/src/include/utils/meson.build index c212c4091f7..6de5d937991 100644 --- a/src/include/utils/meson.build +++ b/src/include/utils/meson.build @@ -1,5 +1,22 @@ # Copyright (c) 2022-2023, PostgreSQL Global Development Group +wait_event_output = ['wait_event_types.h', 'pgstat_wait_event.c'] +wait_event_target = custom_target('wait_event_names', + input: files('../../backend/utils/activity/wait_event_names.txt'), + output: wait_event_output, + command: [ + perl, files('../../backend/utils/activity/generate-wait_event_types.pl'), + '--outdir', '@OUTDIR@', '--code', + '@INPUT@' + ], + build_by_default: true, + install: true, + install_dir: [dir_include_server / 'utils', false], +) + +wait_event_types_h = wait_event_target[0] +generated_backend_headers += wait_event_types_h + errcodes = custom_target('errcodes', input: files('../../backend/utils/errcodes.txt'), output: ['errcodes.h'], @@ -58,3 +75,5 @@ generated_sources_ac += { 'src/backend/utils': fmgrtab_output + ['errcodes.h', 'probes.h', 'fmgr-stamp'], 'src/include/utils': ['header-stamp'], } + +generated_sources_ac += {'src/backend/utils/activity': ['wait_event_types.h']} diff --git a/src/include/utils/wait_event.h b/src/include/utils/wait_event.h index dc01d4e84df..4517425f84e 100644 --- a/src/include/utils/wait_event.h +++ b/src/include/utils/wait_event.h @@ -25,236 +25,8 @@ #define PG_WAIT_TIMEOUT 0x09000000U #define PG_WAIT_IO 0x0A000000U -/* ---------- - * Wait Events - Activity - * - * Use this category when a process is waiting because it has no work to do, - * unless the "Client" or "Timeout" category describes the situation better. - * Typically, this should only be used for background processes. - * ---------- - */ -typedef enum -{ - WAIT_EVENT_ARCHIVER_MAIN = PG_WAIT_ACTIVITY, - WAIT_EVENT_AUTOVACUUM_MAIN, - WAIT_EVENT_BGWRITER_HIBERNATE, - WAIT_EVENT_BGWRITER_MAIN, - WAIT_EVENT_CHECKPOINTER_MAIN, - WAIT_EVENT_LOGICAL_APPLY_MAIN, - WAIT_EVENT_LOGICAL_LAUNCHER_MAIN, - WAIT_EVENT_LOGICAL_PARALLEL_APPLY_MAIN, - WAIT_EVENT_RECOVERY_WAL_STREAM, - WAIT_EVENT_SYSLOGGER_MAIN, - WAIT_EVENT_WAL_RECEIVER_MAIN, - WAIT_EVENT_WAL_SENDER_MAIN, - WAIT_EVENT_WAL_WRITER_MAIN -} WaitEventActivity; - -/* ---------- - * Wait Events - BUFFERPIN - * ---------- - */ -typedef enum -{ - WAIT_EVENT_BUFFER_PIN = PG_WAIT_BUFFERPIN -} WaitEventBufferPin; - -/* ---------- - * Wait Events - Client - * - * Use this category when a process is waiting to send data to or receive data - * from the frontend process to which it is connected. This is never used for - * a background process, which has no client connection. - * ---------- - */ -typedef enum -{ - WAIT_EVENT_CLIENT_READ = PG_WAIT_CLIENT, - WAIT_EVENT_CLIENT_WRITE, - WAIT_EVENT_GSS_OPEN_SERVER, - WAIT_EVENT_LIBPQWALRECEIVER_CONNECT, - WAIT_EVENT_LIBPQWALRECEIVER_RECEIVE, - WAIT_EVENT_SSL_OPEN_SERVER, - WAIT_EVENT_WAL_SENDER_WAIT_WAL, - WAIT_EVENT_WAL_SENDER_WRITE_DATA, -} WaitEventClient; - -/* ---------- - * Wait Events - EXTENSION - * ---------- - */ -typedef enum -{ - WAIT_EVENT_EXTENSION = PG_WAIT_EXTENSION -} WaitEventExtension; - -/* ---------- - * Wait Events - IPC - * - * Use this category when a process cannot complete the work it is doing because - * it is waiting for a notification from another process. - * ---------- - */ -typedef enum -{ - WAIT_EVENT_APPEND_READY = PG_WAIT_IPC, - WAIT_EVENT_ARCHIVE_CLEANUP_COMMAND, - WAIT_EVENT_ARCHIVE_COMMAND, - WAIT_EVENT_BACKEND_TERMINATION, - WAIT_EVENT_BACKUP_WAIT_WAL_ARCHIVE, - WAIT_EVENT_BGWORKER_SHUTDOWN, - WAIT_EVENT_BGWORKER_STARTUP, - WAIT_EVENT_BTREE_PAGE, - WAIT_EVENT_BUFFER_IO, - WAIT_EVENT_CHECKPOINT_DONE, - WAIT_EVENT_CHECKPOINT_START, - WAIT_EVENT_EXECUTE_GATHER, - WAIT_EVENT_HASH_BATCH_ALLOCATE, - WAIT_EVENT_HASH_BATCH_ELECT, - WAIT_EVENT_HASH_BATCH_LOAD, - WAIT_EVENT_HASH_BUILD_ALLOCATE, - WAIT_EVENT_HASH_BUILD_ELECT, - WAIT_EVENT_HASH_BUILD_HASH_INNER, - WAIT_EVENT_HASH_BUILD_HASH_OUTER, - WAIT_EVENT_HASH_GROW_BATCHES_DECIDE, - WAIT_EVENT_HASH_GROW_BATCHES_ELECT, - WAIT_EVENT_HASH_GROW_BATCHES_FINISH, - WAIT_EVENT_HASH_GROW_BATCHES_REALLOCATE, - WAIT_EVENT_HASH_GROW_BATCHES_REPARTITION, - WAIT_EVENT_HASH_GROW_BUCKETS_ELECT, - WAIT_EVENT_HASH_GROW_BUCKETS_REALLOCATE, - WAIT_EVENT_HASH_GROW_BUCKETS_REINSERT, - WAIT_EVENT_LOGICAL_APPLY_SEND_DATA, - WAIT_EVENT_LOGICAL_PARALLEL_APPLY_STATE_CHANGE, - WAIT_EVENT_LOGICAL_SYNC_DATA, - WAIT_EVENT_LOGICAL_SYNC_STATE_CHANGE, - WAIT_EVENT_MQ_INTERNAL, - WAIT_EVENT_MQ_PUT_MESSAGE, - WAIT_EVENT_MQ_RECEIVE, - WAIT_EVENT_MQ_SEND, - WAIT_EVENT_PARALLEL_BITMAP_SCAN, - WAIT_EVENT_PARALLEL_CREATE_INDEX_SCAN, - WAIT_EVENT_PARALLEL_FINISH, - WAIT_EVENT_PROCARRAY_GROUP_UPDATE, - WAIT_EVENT_PROC_SIGNAL_BARRIER, - WAIT_EVENT_PROMOTE, - WAIT_EVENT_RECOVERY_CONFLICT_SNAPSHOT, - WAIT_EVENT_RECOVERY_CONFLICT_TABLESPACE, - WAIT_EVENT_RECOVERY_END_COMMAND, - WAIT_EVENT_RECOVERY_PAUSE, - WAIT_EVENT_REPLICATION_ORIGIN_DROP, - WAIT_EVENT_REPLICATION_SLOT_DROP, - WAIT_EVENT_RESTORE_COMMAND, - WAIT_EVENT_SAFE_SNAPSHOT, - WAIT_EVENT_SYNC_REP, - WAIT_EVENT_WAL_RECEIVER_EXIT, - WAIT_EVENT_WAL_RECEIVER_WAIT_START, - WAIT_EVENT_XACT_GROUP_UPDATE -} WaitEventIPC; - -/* ---------- - * Wait Events - Timeout - * - * Use this category when a process is waiting for a timeout to expire. - * ---------- - */ -typedef enum -{ - WAIT_EVENT_BASE_BACKUP_THROTTLE = PG_WAIT_TIMEOUT, - WAIT_EVENT_CHECKPOINT_WRITE_DELAY, - WAIT_EVENT_PG_SLEEP, - WAIT_EVENT_RECOVERY_APPLY_DELAY, - WAIT_EVENT_RECOVERY_RETRIEVE_RETRY_INTERVAL, - WAIT_EVENT_REGISTER_SYNC_REQUEST, - WAIT_EVENT_SPIN_DELAY, - WAIT_EVENT_VACUUM_DELAY, - WAIT_EVENT_VACUUM_TRUNCATE -} WaitEventTimeout; - -/* ---------- - * Wait Events - IO - * - * Use this category when a process is waiting for a IO. - * ---------- - */ -typedef enum -{ - WAIT_EVENT_BASEBACKUP_READ = PG_WAIT_IO, - WAIT_EVENT_BASEBACKUP_SYNC, - WAIT_EVENT_BASEBACKUP_WRITE, - WAIT_EVENT_BUFFILE_READ, - WAIT_EVENT_BUFFILE_WRITE, - WAIT_EVENT_BUFFILE_TRUNCATE, - WAIT_EVENT_CONTROL_FILE_READ, - WAIT_EVENT_CONTROL_FILE_SYNC, - WAIT_EVENT_CONTROL_FILE_SYNC_UPDATE, - WAIT_EVENT_CONTROL_FILE_WRITE, - WAIT_EVENT_CONTROL_FILE_WRITE_UPDATE, - WAIT_EVENT_COPY_FILE_READ, - WAIT_EVENT_COPY_FILE_WRITE, - WAIT_EVENT_DATA_FILE_EXTEND, - WAIT_EVENT_DATA_FILE_FLUSH, - WAIT_EVENT_DATA_FILE_IMMEDIATE_SYNC, - WAIT_EVENT_DATA_FILE_PREFETCH, - WAIT_EVENT_DATA_FILE_READ, - WAIT_EVENT_DATA_FILE_SYNC, - WAIT_EVENT_DATA_FILE_TRUNCATE, - WAIT_EVENT_DATA_FILE_WRITE, - WAIT_EVENT_DSM_ALLOCATE, - WAIT_EVENT_DSM_FILL_ZERO_WRITE, - WAIT_EVENT_LOCK_FILE_ADDTODATADIR_READ, - WAIT_EVENT_LOCK_FILE_ADDTODATADIR_SYNC, - WAIT_EVENT_LOCK_FILE_ADDTODATADIR_WRITE, - WAIT_EVENT_LOCK_FILE_CREATE_READ, - WAIT_EVENT_LOCK_FILE_CREATE_SYNC, - WAIT_EVENT_LOCK_FILE_CREATE_WRITE, - WAIT_EVENT_LOCK_FILE_RECHECKDATADIR_READ, - WAIT_EVENT_LOGICAL_REWRITE_CHECKPOINT_SYNC, - WAIT_EVENT_LOGICAL_REWRITE_MAPPING_SYNC, - WAIT_EVENT_LOGICAL_REWRITE_MAPPING_WRITE, - WAIT_EVENT_LOGICAL_REWRITE_SYNC, - WAIT_EVENT_LOGICAL_REWRITE_TRUNCATE, - WAIT_EVENT_LOGICAL_REWRITE_WRITE, - WAIT_EVENT_RELATION_MAP_READ, - WAIT_EVENT_RELATION_MAP_REPLACE, - WAIT_EVENT_RELATION_MAP_WRITE, - WAIT_EVENT_REORDER_BUFFER_READ, - WAIT_EVENT_REORDER_BUFFER_WRITE, - WAIT_EVENT_REORDER_LOGICAL_MAPPING_READ, - WAIT_EVENT_REPLICATION_SLOT_READ, - WAIT_EVENT_REPLICATION_SLOT_RESTORE_SYNC, - WAIT_EVENT_REPLICATION_SLOT_SYNC, - WAIT_EVENT_REPLICATION_SLOT_WRITE, - WAIT_EVENT_SLRU_FLUSH_SYNC, - WAIT_EVENT_SLRU_READ, - WAIT_EVENT_SLRU_SYNC, - WAIT_EVENT_SLRU_WRITE, - WAIT_EVENT_SNAPBUILD_READ, - WAIT_EVENT_SNAPBUILD_SYNC, - WAIT_EVENT_SNAPBUILD_WRITE, - WAIT_EVENT_TIMELINE_HISTORY_FILE_SYNC, - WAIT_EVENT_TIMELINE_HISTORY_FILE_WRITE, - WAIT_EVENT_TIMELINE_HISTORY_READ, - WAIT_EVENT_TIMELINE_HISTORY_SYNC, - WAIT_EVENT_TIMELINE_HISTORY_WRITE, - WAIT_EVENT_TWOPHASE_FILE_READ, - WAIT_EVENT_TWOPHASE_FILE_SYNC, - WAIT_EVENT_TWOPHASE_FILE_WRITE, - WAIT_EVENT_VERSION_FILE_WRITE, - WAIT_EVENT_WALSENDER_TIMELINE_HISTORY_READ, - WAIT_EVENT_WAL_BOOTSTRAP_SYNC, - WAIT_EVENT_WAL_BOOTSTRAP_WRITE, - WAIT_EVENT_WAL_COPY_READ, - WAIT_EVENT_WAL_COPY_SYNC, - WAIT_EVENT_WAL_COPY_WRITE, - WAIT_EVENT_WAL_INIT_SYNC, - WAIT_EVENT_WAL_INIT_WRITE, - WAIT_EVENT_WAL_READ, - WAIT_EVENT_WAL_SYNC, - WAIT_EVENT_WAL_SYNC_METHOD_ASSIGN, - WAIT_EVENT_WAL_WRITE -} WaitEventIO; - +/* enums for wait events */ +#include "utils/wait_event_types.h" extern const char *pgstat_get_wait_event(uint32 wait_event_info); extern const char *pgstat_get_wait_event_type(uint32 wait_event_info); |