Use pgstat_kind_infos to read fixed shared statistics
authorMichael Paquier <[email protected]>
Mon, 1 Jul 2024 05:26:25 +0000 (14:26 +0900)
committerMichael Paquier <[email protected]>
Mon, 1 Jul 2024 05:26:25 +0000 (14:26 +0900)
commit9004abf6206e815d25b7b763c756cf97b457f3cd
treeed21d548352f4c4d29461821538953a7c54c5541
parenta1333ec048fb95ff47a5fc10a9cfde69fdbd2b01
Use pgstat_kind_infos to read fixed shared statistics

Shared statistics with a fixed number of objects are read from the stats
file in pgstat_read_statsfile() using members of PgStat_ShmemControl and
following an order based on their PgStat_Kind value.

Instead of being explicit, this commit changes the stats read to iterate
over the pgstat_kind_infos array to find the memory locations to read
into, based on a new shared_ctl_off in PgStat_KindInfo that can be used
to define the position of this stats kind in shared memory.  This makes
the read logic simpler, and eases the introduction of future
improvements aimed at making this area more pluggable for external
modules.

Original idea suggested by Andres Freund.

Author: Tristan Partin
Reviewed-by: Andres Freund, Michael Paquier
Discussion: https://postgr.es/m/[email protected]
src/backend/utils/activity/pgstat.c
src/include/utils/pgstat_internal.h