1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-11 10:01:57 +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:
Robert Haas
2016-10-04 10:50:13 -04:00
parent 490ed1ebb9
commit 6f3bd98ebf
35 changed files with 585 additions and 84 deletions

View File

@ -715,15 +715,91 @@ typedef enum BackendState
* Wait Classes
* ----------
*/
typedef enum WaitClass
{
WAIT_UNDEFINED,
WAIT_LWLOCK_NAMED,
WAIT_LWLOCK_TRANCHE,
WAIT_LOCK,
WAIT_BUFFER_PIN
} WaitClass;
#define WAIT_LWLOCK_NAMED 0x01000000U
#define WAIT_LWLOCK_TRANCHE 0x02000000U
#define WAIT_LOCK 0x03000000U
#define WAIT_BUFFER_PIN 0x04000000U
#define WAIT_ACTIVITY 0x05000000U
#define WAIT_CLIENT 0x06000000U
#define WAIT_EXTENSION 0x07000000U
#define WAIT_IPC 0x08000000U
#define WAIT_TIMEOUT 0x09000000U
/* ----------
* Wait Events - Activity
*
* Use this category when a process is waiting because it has no work to do,
* unless the "Client" or "Timeout" category describes the situation better.
* Typically, this should only be used for background processes.
* ----------
*/
typedef enum
{
WAIT_EVENT_ARCHIVER_MAIN = WAIT_ACTIVITY,
WAIT_EVENT_AUTOVACUUM_MAIN,
WAIT_EVENT_BGWRITER_HIBERNATE,
WAIT_EVENT_BGWRITER_MAIN,
WAIT_EVENT_CHECKPOINTER_MAIN,
WAIT_EVENT_PGSTAT_MAIN,
WAIT_EVENT_RECOVERY_WAL_ALL,
WAIT_EVENT_RECOVERY_WAL_STREAM,
WAIT_EVENT_SYSLOGGER_MAIN,
WAIT_EVENT_WAL_RECEIVER_MAIN,
WAIT_EVENT_WAL_SENDER_MAIN,
WAIT_EVENT_WAL_WRITER_MAIN,
} WaitEventActivity;
/* ----------
* Wait Events - Client
*
* Use this category when a process is waiting to send data to or receive data
* from the frontend process to which it is connected. This is never used for
* a background process, which has no client connection.
* ----------
*/
typedef enum
{
WAIT_EVENT_CLIENT_READ = WAIT_CLIENT,
WAIT_EVENT_CLIENT_WRITE,
WAIT_EVENT_SSL_OPEN_SERVER,
WAIT_EVENT_WAL_RECEIVER_WAIT_START,
WAIT_EVENT_WAL_SENDER_WAIT_WAL,
WAIT_EVENT_WAL_SENDER_WRITE_DATA,
} WaitEventClient;
/* ----------
* Wait Events - IPC
*
* Use this category when a process cannot complete the work it is doing because
* it is waiting for a notification from another process.
* ----------
*/
typedef enum
{
WAIT_EVENT_BGWORKER_SHUTDOWN = WAIT_IPC,
WAIT_EVENT_BGWORKER_STARTUP,
WAIT_EVENT_EXECUTE_GATHER,
WAIT_EVENT_MQ_INTERNAL,
WAIT_EVENT_MQ_PUT_MESSAGE,
WAIT_EVENT_MQ_RECEIVE,
WAIT_EVENT_MQ_SEND,
WAIT_EVENT_PARALLEL_FINISH,
WAIT_EVENT_SAFE_SNAPSHOT,
WAIT_EVENT_SYNC_REP
} WaitEventIPC;
/* ----------
* Wait Events - Timeout
*
* Use this category when a process is waiting for a timeout to expire.
* ----------
*/
typedef enum
{
WAIT_EVENT_BASE_BACKUP_THROTTLE = WAIT_TIMEOUT,
WAIT_EVENT_PG_SLEEP,
WAIT_EVENT_RECOVERY_APPLY_DELAY
} WaitEventTimeout;
/* ----------
* Command type for progress reporting purposes
@ -1018,23 +1094,18 @@ extern void pgstat_initstats(Relation rel);
* ----------
*/
static inline void
pgstat_report_wait_start(uint8 classId, uint16 eventId)
pgstat_report_wait_start(uint32 wait_event_info)
{
volatile PGPROC *proc = MyProc;
uint32 wait_event_val;
if (!pgstat_track_activities || !proc)
return;
wait_event_val = classId;
wait_event_val <<= 24;
wait_event_val |= eventId;
/*
* Since this is a four-byte field which is always read and written as
* four-bytes, updates are atomic.
*/
proc->wait_event_info = wait_event_val;
proc->wait_event_info = wait_event_info;
}
/* ----------