Re: Autogenerate some wait events code and documentation

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: "Drouvot, Bertrand" <bertranddrouvot.pg@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-07-05T01:57:19Z
Lists: pgsql-hackers
On Tue, Jul 04, 2023 at 09:34:33AM +0200, Drouvot, Bertrand wrote:
> Yeah, with "capture" set to "false" then ninja alldocs does not error out
> and wait_event_types.sgml gets generated.
> 
> I'll look at the extra options --code and --docs.

+wait_event_types.sgml: $(top_srcdir)/src/backend/utils/activity/wait_event_names.txt $(top_srcdir)/src/backend/utils/activity/generate-wait_event_types.pl
+   $(PERL) $(top_srcdir)/src/backend/utils/activity/generate-wait_event_types.pl --docs $< > $@

This is doing the same error as meson in v10, there is no need for
the last part doing the redirection because the script outputs
nothing.  Here is the command generated:
make -C doc/src/sgml/ wait_event_types.sgml
'/usr/bin/perl'
../../../src/backend/utils/activity/generate-wait_event_types.pl
--docs ../../../src/backend/utils/activity/wait_event_names.txt >
wait_event_types.sgml

+wait_event_names = custom_target('wait_event_names',
+  input: files('../../backend/utils/activity/wait_event_names.txt'),
+  output: ['wait_event_types.h'],
This one was not completely correct (look at fmgrtab, for example), as
it is missing pgstat_wait_event.c in the output generated.  We could
perhaps be more selective with all that, including fmgrtab, but I have
left that out for now.  Note also the tweak with install_dir to not
install the C file.

+wait_event_names = custom_target('wait_event_names',
+  input: files('./wait_event_names.txt'),
+  output: ['pgstat_wait_event.c'],
+  command: [
+    perl, files('./generate-wait_event_types.pl'),
+    '-o', '@OUTDIR@', '--code',
+    '@INPUT@'
+  ],
+  install: true,
+  install_dir: [false],
+)
[...]
+# these include .c files generated in ../../../include/activity, seems nicer to not
+# add that as an include path for the whole backend
+waitevent_sources = files(
   'wait_event.c',
 )
+
+backend_link_with += static_library('wait_event_names',
+  waitevent_sources,
+  dependencies: [backend_code],
+  include_directories: include_directories('../../../include/utils'),
+  kwargs: internal_lib_args,
+)

"wait_event_names" with the extra command should not be necessary
here, because we feed from the C file generated in src/include/utils/,
included in wait_event.c.  See src/backend/nodes/meson.build for a
similar example

Two of the error messages after rename() in the script were
inconsistent.  So reworded these on the way.

I have added a usage() to the script, while on it.

The VPATH build was broken, because the following line was missing
from src/backend/utils/activity/Makefile to be able to detect
pgstat_wait_event.c from wait_event.c:
override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)

With all that in place, VPATH builds, the CI, meson, configure/make
and the various cleanup targets were working fine, so I have applied
it.  Now let's see what the buildfarm tells.

The final --stat number is like that:
 22 files changed, 757 insertions(+), 2111 deletions(-)
--
Michael

Commits

  1. Add "ABI_compatibility" regions to wait_event_names.txt

  2. Remove column for wait event names in wait_event_names.txt

  3. Use more consistent names for wait event objects and types

  4. Add information about line contents on parsing failure of wait_event_names.txt

  5. Remove double quotes from the second column of wait_event_names.txt

  6. Generate automatically code and documentation related to wait events

  7. Refactor some code related to wait events "BufferPin" and "Extension"

  8. doc: Fix ordering of entries in wait event table for I/O type