Autogenerate some wait events code and documentation

Bertrand Drouvot <bertranddrouvot.pg@gmail.com>

From: "Drouvot, Bertrand" <bertranddrouvot.pg@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-03-29T09:44:39Z
Lists: pgsql-hackers

Attachments

Hi hackers,

In another thread [1], Thomas had the idea to $SUBJECT in a similar way
to what is currently done with src/backend/storage/lmgr/lwlocknames.txt.

Doing so, like in the attached patch proposal, would help to avoid:

- wait event without documentation like observed in [2]
- orphaned wait event like observed in [3]

The patch relies on a new src/backend/utils/activity/waiteventnames.txt file that contains on row
per wait event, with this format:

<ENUM NAME> <WAIT EVENT ENUM> <WAIT EVENT NAME> <WAIT EVENT DOC SENTENCE>

Then, a new perl script (src/backend/utils/activity/generate-waiteventnames.pl) generates the new:

- waiteventnames.c
- waiteventnames.h
- waiteventnames.sgml

files.

Remarks:

- The new src/backend/utils/activity/waiteventnames.txt file has been created with (a quickly written, non polished
and not part of the patch) generate_waiteventnames_txt.sh script attached. Then, the proposal for the 2 wait events
missing documentation (non committed yet) done in [2] has been added manually to waiteventnames.txt.

- The patch does take care of wait events that currently are linked to enums, means:
  
  - PG_WAIT_ACTIVITY
  - PG_WAIT_CLIENT
  - PG_WAIT_IPC
  - PG_WAIT_TIMEOUT
  - PG_WAIT_IO

  so that PG_WAIT_LWLOCK, PG_WAIT_LOCK, PG_WAIT_BUFFER_PIN and PG_WAIT_EXTENSION are not autogenerated.

This result to having the wait event part of the documentation "monitoring-stats" not ordered as compared to the "Wait Event Types" Table.

This is due to the fact that the new waiteventnames.sgml that contains the documentation for
the autogenerated ones listed above is "included" into doc/src/sgml/monitoring.sgml and then breaks the alphabetical ordering
with the ones not autogenerated.

To fix this I've in mind to also autogenerate enums for PG_WAIT_BUFFER_PIN and PG_WAIT_EXTENSION and
split the current documentation "Wait Event Types" Table in 2 tables: one for the autogenerated ones and one (then for
PG_WAIT_LWLOCK, PG_WAIT_LOCK) for the non autogenerated "lock" related ones.

Looking forward to your feedback,

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

[1]: https://www.postgresql.org/message-id/CA%2BhUKG%2BewEpxm%3DhPNXyupRUB_SKGh-6tO86viaco0g-P_pm_Cw%40mail.gmail.com
[2]: https://www.postgresql.org/message-id/CA%2BhUKGJixAHc860Ej9Qzd_z96Z6aoajAgJ18bYfV3Lfn6t9%3D%2BQ%40mail.gmail.com
[3]: https://www.postgresql.org/message-id/CA%2BhUKGK6tqm59KuF1z%2Bh5Y8fsWcu5v8%2B84kduSHwRzwjB2aa_A%40mail.gmail.com

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