From fa88928470b538c0ec0289e4d69ee12356c5a8ce Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 5 Jul 2023 10:53:11 +0900 Subject: 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 --- src/tools/msvc/Solution.pm | 19 +++++++++++++++++++ src/tools/msvc/clean.bat | 3 +++ 2 files changed, 22 insertions(+) (limited to 'src/tools') diff --git a/src/tools/msvc/Solution.pm b/src/tools/msvc/Solution.pm index e6d8f9fedc0..133acc09f24 100644 --- a/src/tools/msvc/Solution.pm +++ b/src/tools/msvc/Solution.pm @@ -585,6 +585,25 @@ sub GenerateFiles 'src/include/storage/lwlocknames.h'); } + if (IsNewer( + 'src/include/utils/wait_event_types.h', + 'src/backend/utils/activity/wait_event_names.txt')) + { + print "Generating pgstat_wait_event.c and wait_event_types.h...\n"; + my $activ = 'src/backend/utils/activity'; + system( + "perl $activ/generate-wait_event_types.pl --outdir $activ --code $activ/wait_event_names.txt" + ); + } + if (IsNewer( + 'src/include/utils/wait_event_types.h', + 'src/backend/utils/activity/wait_event_types.h')) + { + copyFile( + 'src/backend/utils/activity/wait_event_types.h', + 'src/include/utils/wait_event_types.h'); + } + if (IsNewer('src/include/utils/probes.h', 'src/backend/utils/probes.d')) { print "Generating probes.h...\n"; diff --git a/src/tools/msvc/clean.bat b/src/tools/msvc/clean.bat index cf357646045..7cb23ea8942 100755 --- a/src/tools/msvc/clean.bat +++ b/src/tools/msvc/clean.bat @@ -46,6 +46,7 @@ if exist src\include\utils\errcodes.h del /q src\include\utils\errcodes.h if exist src\include\utils\fmgroids.h del /q src\include\utils\fmgroids.h if exist src\include\utils\fmgrprotos.h del /q src\include\utils\fmgrprotos.h if exist src\include\storage\lwlocknames.h del /q src\include\storage\lwlocknames.h +if exist src\include\utils\wait_event_types.h del /q src\include\utils\wait_event_types.h if exist src\include\utils\probes.h del /q src\include\utils\probes.h if exist src\include\catalog\schemapg.h del /q src\include\catalog\schemapg.h if exist src\include\catalog\system_fk_info.h del /q src\include\catalog\system_fk_info.h @@ -53,6 +54,8 @@ if exist src\include\catalog\pg_*_d.h del /q src\include\catalog\pg_*_d.h if exist src\include\catalog\header-stamp del /q src\include\catalog\header-stamp if exist doc\src\sgml\version.sgml del /q doc\src\sgml\version.sgml +if %DIST%==1 if exist src\backend\utils\activity\pgstat_wait_event.c del /q src\backend\utils\activity\pgstat_wait_event.c +if %DIST%==1 if exist src\backend\utils\activity\wait_event_types.h del /q src\backend\utils\activity\wait_event_types.h if %DIST%==1 if exist src\backend\utils\fmgroids.h del /q src\backend\utils\fmgroids.h if %DIST%==1 if exist src\backend\utils\fmgrprotos.h del /q src\backend\utils\fmgrprotos.h if %DIST%==1 if exist src\backend\utils\fmgrtab.c del /q src\backend\utils\fmgrtab.c -- cgit v1.2.3