mirror of
https://github.com/postgres/postgres.git
synced 2025-09-03 15:22:11 +03:00
Extend framework from commit 53be0b1ad
to report latch waits.
WaitLatch, WaitLatchOrSocket, and WaitEventSetWait now taken an additional wait_event_info parameter; legal values are defined in pgstat.h. This makes it possible to uniquely identify every point in the core code where we are waiting for a latch; extensions can pass WAIT_EXTENSION. Because latches were the major wait primitive not previously covered by this patch, it is now possible to see information in pg_stat_activity on a large number of important wait events not previously addressed, such as ClientRead, ClientWrite, and SyncRep. Unfortunately, many of the wait events added by this patch will fail to appear in pg_stat_activity because they're only used in background processes which don't currently appear in pg_stat_activity. We should fix this either by creating a separate view for such information, or else by deciding to include them in pg_stat_activity after all. Michael Paquier and Robert Haas, reviewed by Alexander Korotkov and Thomas Munro.
This commit is contained in:
@@ -55,6 +55,7 @@
|
||||
#endif
|
||||
|
||||
#include "miscadmin.h"
|
||||
#include "pgstat.h"
|
||||
#include "portability/instr_time.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
#include "storage/barrier.h"
|
||||
@@ -297,9 +298,11 @@ DisownLatch(volatile Latch *latch)
|
||||
* we return all of them in one call, but we will return at least one.
|
||||
*/
|
||||
int
|
||||
WaitLatch(volatile Latch *latch, int wakeEvents, long timeout)
|
||||
WaitLatch(volatile Latch *latch, int wakeEvents, long timeout,
|
||||
uint32 wait_event_info)
|
||||
{
|
||||
return WaitLatchOrSocket(latch, wakeEvents, PGINVALID_SOCKET, timeout);
|
||||
return WaitLatchOrSocket(latch, wakeEvents, PGINVALID_SOCKET, timeout,
|
||||
wait_event_info);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -316,7 +319,7 @@ WaitLatch(volatile Latch *latch, int wakeEvents, long timeout)
|
||||
*/
|
||||
int
|
||||
WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
|
||||
long timeout)
|
||||
long timeout, uint32 wait_event_info)
|
||||
{
|
||||
int ret = 0;
|
||||
int rc;
|
||||
@@ -344,7 +347,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
|
||||
AddWaitEventToSet(set, ev, sock, NULL, NULL);
|
||||
}
|
||||
|
||||
rc = WaitEventSetWait(set, timeout, &event, 1);
|
||||
rc = WaitEventSetWait(set, timeout, &event, 1, wait_event_info);
|
||||
|
||||
if (rc == 0)
|
||||
ret |= WL_TIMEOUT;
|
||||
@@ -863,7 +866,8 @@ WaitEventAdjustWin32(WaitEventSet *set, WaitEvent *event)
|
||||
*/
|
||||
int
|
||||
WaitEventSetWait(WaitEventSet *set, long timeout,
|
||||
WaitEvent *occurred_events, int nevents)
|
||||
WaitEvent *occurred_events, int nevents,
|
||||
uint32 wait_event_info)
|
||||
{
|
||||
int returned_events = 0;
|
||||
instr_time start_time;
|
||||
@@ -883,6 +887,8 @@ WaitEventSetWait(WaitEventSet *set, long timeout,
|
||||
cur_timeout = timeout;
|
||||
}
|
||||
|
||||
pgstat_report_wait_start(wait_event_info);
|
||||
|
||||
#ifndef WIN32
|
||||
waiting = true;
|
||||
#else
|
||||
@@ -960,6 +966,8 @@ WaitEventSetWait(WaitEventSet *set, long timeout,
|
||||
waiting = false;
|
||||
#endif
|
||||
|
||||
pgstat_report_wait_end();
|
||||
|
||||
return returned_events;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user