Re: Adding wait events statistics

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Adding wait events statistics
Date: 2025-07-08 15:25:26
Message-ID: aG04Zk+b3SRN0pBe@ip-10-97-1-34.eu-west-3.compute.internal
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Tue, Jul 08, 2025 at 04:46:28AM +0000, Bertrand Drouvot wrote:
> On Tue, Jul 08, 2025 at 09:36:53AM +0900, Michael Paquier wrote:
> > Yes, you may need some level of meta-data generated for the wait
> > classes generated when the perl script generating this data is run.
> > It would be nice to the footprint of the code generated minimal if we
> > can. It's one of these things where I would try both approaches,

I did some testing and experiments and I think an "hybrid" approach mixing multiple
arrays and one "global" one is the best approach.

So, something like:

"
ClassInfo LWLockClassInfo = {
.numberOfEvents = NB_LWLOCK_WAIT_EVENTS,
.pendingCounts = PendingWaitEventStats.lwlock_counts
};

WaitClassInfo LockClassInfo = {
.numberOfEvents = NB_LOCK_WAIT_EVENTS,
.pendingCounts = PendingWaitEventStats.lock_counts
};
.
.
.
.
"

and then the "global" one:

"
WaitClassInfo *AllWaitClasses[] = {
NULL, /* gap - no class with ID 0 */
&LWLockClassInfo,
NULL, /* gap - no class with ID 2 */
&LockClassInfo,
&BufferPinClassInfo,
&ActivityClassInfo,
&ClientClassInfo,
&ExtensionClassInfo,
&IPCClassInfo,
&TimeoutClassInfo,
&IOClassInfo,
};
"

That way:

- we do not need a mapping between ClassID and "Arrays" and the gaps
in the ClassID are handled. So we can acces directly the class of interest
knowing its classID.
- we can easily iterate (again no mapping needed) over all the pending stats
thanks to AllWaitClasses[]

What do you think? It looks like the most elegant approach to me.

Bonus point, as you can see above, while working on this approach I've been able
to remove storing the className and the array of eventName per wait class (would
have worked in v1 too).

Regards,

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Antonin Houska 2025-07-08 15:50:59 Re: Move the injection_points extension to contrib?
Previous Message Tom Lane 2025-07-08 15:25:01 Re: What is a typical precision of gettimeofday()?