mirror of
https://github.com/postgres/postgres.git
synced 2025-08-30 06:01:21 +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:
@@ -598,7 +598,8 @@ AutoVacLauncherMain(int argc, char *argv[])
|
||||
*/
|
||||
rc = WaitLatch(MyLatch,
|
||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||
(nap.tv_sec * 1000L) + (nap.tv_usec / 1000L));
|
||||
(nap.tv_sec * 1000L) + (nap.tv_usec / 1000L),
|
||||
WAIT_EVENT_AUTOVACUUM_MAIN);
|
||||
|
||||
ResetLatch(MyLatch);
|
||||
|
||||
|
@@ -18,6 +18,7 @@
|
||||
#include "libpq/pqsignal.h"
|
||||
#include "postmaster/bgworker_internals.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
#include "pgstat.h"
|
||||
#include "storage/barrier.h"
|
||||
#include "storage/dsm.h"
|
||||
#include "storage/ipc.h"
|
||||
@@ -969,7 +970,8 @@ WaitForBackgroundWorkerStartup(BackgroundWorkerHandle *handle, pid_t *pidp)
|
||||
break;
|
||||
|
||||
rc = WaitLatch(MyLatch,
|
||||
WL_LATCH_SET | WL_POSTMASTER_DEATH, 0);
|
||||
WL_LATCH_SET | WL_POSTMASTER_DEATH, 0,
|
||||
WAIT_EVENT_BGWORKER_STARTUP);
|
||||
|
||||
if (rc & WL_POSTMASTER_DEATH)
|
||||
{
|
||||
@@ -1008,7 +1010,8 @@ WaitForBackgroundWorkerShutdown(BackgroundWorkerHandle *handle)
|
||||
break;
|
||||
|
||||
rc = WaitLatch(&MyProc->procLatch,
|
||||
WL_LATCH_SET | WL_POSTMASTER_DEATH, 0);
|
||||
WL_LATCH_SET | WL_POSTMASTER_DEATH, 0,
|
||||
WAIT_EVENT_BGWORKER_SHUTDOWN);
|
||||
|
||||
if (rc & WL_POSTMASTER_DEATH)
|
||||
{
|
||||
|
@@ -345,7 +345,7 @@ BackgroundWriterMain(void)
|
||||
*/
|
||||
rc = WaitLatch(MyLatch,
|
||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||
BgWriterDelay /* ms */ );
|
||||
BgWriterDelay /* ms */, WAIT_EVENT_BGWRITER_MAIN);
|
||||
|
||||
/*
|
||||
* If no latch event and BgBufferSync says nothing's happening, extend
|
||||
@@ -372,7 +372,8 @@ BackgroundWriterMain(void)
|
||||
/* Sleep ... */
|
||||
rc = WaitLatch(MyLatch,
|
||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||
BgWriterDelay * HIBERNATE_FACTOR);
|
||||
BgWriterDelay * HIBERNATE_FACTOR,
|
||||
WAIT_EVENT_BGWRITER_HIBERNATE);
|
||||
/* Reset the notification request in case we timed out */
|
||||
StrategyNotifyBgWriter(-1);
|
||||
}
|
||||
|
@@ -556,7 +556,8 @@ CheckpointerMain(void)
|
||||
|
||||
rc = WaitLatch(MyLatch,
|
||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||
cur_timeout * 1000L /* convert to ms */ );
|
||||
cur_timeout * 1000L /* convert to ms */,
|
||||
WAIT_EVENT_CHECKPOINTER_MAIN);
|
||||
|
||||
/*
|
||||
* Emergency bailout if postmaster has died. This is to avoid the
|
||||
|
@@ -390,7 +390,8 @@ pgarch_MainLoop(void)
|
||||
|
||||
rc = WaitLatch(MyLatch,
|
||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||
timeout * 1000L);
|
||||
timeout * 1000L,
|
||||
WAIT_EVENT_ARCHIVER_MAIN);
|
||||
if (rc & WL_TIMEOUT)
|
||||
wakened = true;
|
||||
}
|
||||
|
@@ -276,6 +276,11 @@ static PgStat_TableStatus *get_tabstat_entry(Oid rel_id, bool isshared);
|
||||
|
||||
static void pgstat_setup_memcxt(void);
|
||||
|
||||
static const char *pgstat_get_wait_activity(WaitEventActivity w);
|
||||
static const char *pgstat_get_wait_client(WaitEventClient w);
|
||||
static const char *pgstat_get_wait_ipc(WaitEventIPC w);
|
||||
static const char *pgstat_get_wait_timeout(WaitEventTimeout w);
|
||||
|
||||
static void pgstat_setheader(PgStat_MsgHdr *hdr, StatMsgType mtype);
|
||||
static void pgstat_send(void *msg, int len);
|
||||
|
||||
@@ -3131,15 +3136,14 @@ pgstat_read_current_status(void)
|
||||
const char *
|
||||
pgstat_get_wait_event_type(uint32 wait_event_info)
|
||||
{
|
||||
uint8 classId;
|
||||
uint32 classId;
|
||||
const char *event_type;
|
||||
|
||||
/* report process as not waiting. */
|
||||
if (wait_event_info == 0)
|
||||
return NULL;
|
||||
|
||||
wait_event_info = wait_event_info >> 24;
|
||||
classId = wait_event_info & 0XFF;
|
||||
classId = wait_event_info & 0xFF000000;
|
||||
|
||||
switch (classId)
|
||||
{
|
||||
@@ -3155,6 +3159,21 @@ pgstat_get_wait_event_type(uint32 wait_event_info)
|
||||
case WAIT_BUFFER_PIN:
|
||||
event_type = "BufferPin";
|
||||
break;
|
||||
case WAIT_ACTIVITY:
|
||||
event_type = "Activity";
|
||||
break;
|
||||
case WAIT_CLIENT:
|
||||
event_type = "Client";
|
||||
break;
|
||||
case WAIT_EXTENSION:
|
||||
event_type = "Extension";
|
||||
break;
|
||||
case WAIT_IPC:
|
||||
event_type = "IPC";
|
||||
break;
|
||||
case WAIT_TIMEOUT:
|
||||
event_type = "Timeout";
|
||||
break;
|
||||
default:
|
||||
event_type = "???";
|
||||
break;
|
||||
@@ -3172,7 +3191,7 @@ pgstat_get_wait_event_type(uint32 wait_event_info)
|
||||
const char *
|
||||
pgstat_get_wait_event(uint32 wait_event_info)
|
||||
{
|
||||
uint8 classId;
|
||||
uint32 classId;
|
||||
uint16 eventId;
|
||||
const char *event_name;
|
||||
|
||||
@@ -3180,9 +3199,8 @@ pgstat_get_wait_event(uint32 wait_event_info)
|
||||
if (wait_event_info == 0)
|
||||
return NULL;
|
||||
|
||||
eventId = wait_event_info & ((1 << 24) - 1);
|
||||
wait_event_info = wait_event_info >> 24;
|
||||
classId = wait_event_info & 0XFF;
|
||||
classId = wait_event_info & 0xFF000000;
|
||||
eventId = wait_event_info & 0x0000FFFF;
|
||||
|
||||
switch (classId)
|
||||
{
|
||||
@@ -3196,6 +3214,37 @@ pgstat_get_wait_event(uint32 wait_event_info)
|
||||
case WAIT_BUFFER_PIN:
|
||||
event_name = "BufferPin";
|
||||
break;
|
||||
case WAIT_ACTIVITY:
|
||||
{
|
||||
WaitEventActivity w = (WaitEventActivity) wait_event_info;
|
||||
|
||||
event_name = pgstat_get_wait_activity(w);
|
||||
break;
|
||||
}
|
||||
case WAIT_CLIENT:
|
||||
{
|
||||
WaitEventClient w = (WaitEventClient) wait_event_info;
|
||||
|
||||
event_name = pgstat_get_wait_client(w);
|
||||
break;
|
||||
}
|
||||
case WAIT_EXTENSION:
|
||||
event_name = "Extension";
|
||||
break;
|
||||
case WAIT_IPC:
|
||||
{
|
||||
WaitEventIPC w = (WaitEventIPC) wait_event_info;
|
||||
|
||||
event_name = pgstat_get_wait_ipc(w);
|
||||
break;
|
||||
}
|
||||
case WAIT_TIMEOUT:
|
||||
{
|
||||
WaitEventTimeout w = (WaitEventTimeout) wait_event_info;
|
||||
|
||||
event_name = pgstat_get_wait_timeout(w);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
event_name = "unknown wait event";
|
||||
break;
|
||||
@@ -3204,6 +3253,175 @@ pgstat_get_wait_event(uint32 wait_event_info)
|
||||
return event_name;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* pgstat_get_wait_activity() -
|
||||
*
|
||||
* Convert WaitEventActivity to string.
|
||||
* ----------
|
||||
*/
|
||||
static const char *
|
||||
pgstat_get_wait_activity(WaitEventActivity w)
|
||||
{
|
||||
const char *event_name = "unknown wait event";
|
||||
|
||||
switch (w)
|
||||
{
|
||||
case WAIT_EVENT_ARCHIVER_MAIN:
|
||||
event_name = "ArchiverMain";
|
||||
break;
|
||||
case WAIT_EVENT_AUTOVACUUM_MAIN:
|
||||
event_name = "AutoVacuumMain";
|
||||
break;
|
||||
case WAIT_EVENT_BGWRITER_HIBERNATE:
|
||||
event_name = "BgWriterHibernate";
|
||||
break;
|
||||
case WAIT_EVENT_BGWRITER_MAIN:
|
||||
event_name = "BgWriterMain";
|
||||
break;
|
||||
case WAIT_EVENT_CHECKPOINTER_MAIN:
|
||||
event_name = "CheckpointerMain";
|
||||
break;
|
||||
case WAIT_EVENT_PGSTAT_MAIN:
|
||||
event_name = "PgStatMain";
|
||||
break;
|
||||
case WAIT_EVENT_RECOVERY_WAL_ALL:
|
||||
event_name = "RecoveryWalAll";
|
||||
break;
|
||||
case WAIT_EVENT_RECOVERY_WAL_STREAM:
|
||||
event_name = "RecoveryWalStream";
|
||||
break;
|
||||
case WAIT_EVENT_SYSLOGGER_MAIN:
|
||||
event_name = "SysLoggerMain";
|
||||
break;
|
||||
case WAIT_EVENT_WAL_RECEIVER_MAIN:
|
||||
event_name = "WalReceiverMain";
|
||||
break;
|
||||
case WAIT_EVENT_WAL_SENDER_MAIN:
|
||||
event_name = "WalSenderMain";
|
||||
break;
|
||||
case WAIT_EVENT_WAL_WRITER_MAIN:
|
||||
event_name = "WalWriterMain";
|
||||
break;
|
||||
/* no default case, so that compiler will warn */
|
||||
}
|
||||
|
||||
return event_name;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* pgstat_get_wait_client() -
|
||||
*
|
||||
* Convert WaitEventClient to string.
|
||||
* ----------
|
||||
*/
|
||||
static const char *
|
||||
pgstat_get_wait_client(WaitEventClient w)
|
||||
{
|
||||
const char *event_name = "unknown wait event";
|
||||
|
||||
switch (w)
|
||||
{
|
||||
case WAIT_EVENT_CLIENT_READ:
|
||||
event_name = "ClientRead";
|
||||
break;
|
||||
case WAIT_EVENT_CLIENT_WRITE:
|
||||
event_name = "ClientWrite";
|
||||
break;
|
||||
case WAIT_EVENT_SSL_OPEN_SERVER:
|
||||
event_name = "SSLOpenServer";
|
||||
break;
|
||||
case WAIT_EVENT_WAL_RECEIVER_WAIT_START:
|
||||
event_name = "WalReceiverWaitStart";
|
||||
break;
|
||||
case WAIT_EVENT_WAL_SENDER_WAIT_WAL:
|
||||
event_name = "WalSenderWaitForWAL";
|
||||
break;
|
||||
case WAIT_EVENT_WAL_SENDER_WRITE_DATA:
|
||||
event_name = "WalSenderWriteData";
|
||||
break;
|
||||
/* no default case, so that compiler will warn */
|
||||
}
|
||||
|
||||
return event_name;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* pgstat_get_wait_ipc() -
|
||||
*
|
||||
* Convert WaitEventIPC to string.
|
||||
* ----------
|
||||
*/
|
||||
static const char *
|
||||
pgstat_get_wait_ipc(WaitEventIPC w)
|
||||
{
|
||||
const char *event_name = "unknown wait event";
|
||||
|
||||
switch (w)
|
||||
{
|
||||
case WAIT_EVENT_BGWORKER_SHUTDOWN:
|
||||
event_name = "BgWorkerShutdown";
|
||||
break;
|
||||
case WAIT_EVENT_BGWORKER_STARTUP:
|
||||
event_name = "BgWorkerStartup";
|
||||
break;
|
||||
case WAIT_EVENT_EXECUTE_GATHER:
|
||||
event_name = "ExecuteGather";
|
||||
break;
|
||||
case WAIT_EVENT_MQ_INTERNAL:
|
||||
event_name = "MessageQueueInternal";
|
||||
break;
|
||||
case WAIT_EVENT_MQ_PUT_MESSAGE:
|
||||
event_name = "MessageQueuePutMessage";
|
||||
break;
|
||||
case WAIT_EVENT_MQ_RECEIVE:
|
||||
event_name = "MessageQueueReceive";
|
||||
break;
|
||||
case WAIT_EVENT_MQ_SEND:
|
||||
event_name = "MessageQueueSend";
|
||||
break;
|
||||
case WAIT_EVENT_PARALLEL_FINISH:
|
||||
event_name = "ParallelFinish";
|
||||
break;
|
||||
case WAIT_EVENT_SAFE_SNAPSHOT:
|
||||
event_name = "SafeSnapshot";
|
||||
break;
|
||||
case WAIT_EVENT_SYNC_REP:
|
||||
event_name = "SyncRep";
|
||||
break;
|
||||
/* no default case, so that compiler will warn */
|
||||
}
|
||||
|
||||
return event_name;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* pgstat_get_wait_timeout() -
|
||||
*
|
||||
* Convert WaitEventTimeout to string.
|
||||
* ----------
|
||||
*/
|
||||
static const char *
|
||||
pgstat_get_wait_timeout(WaitEventTimeout w)
|
||||
{
|
||||
const char *event_name = "unknown wait event";
|
||||
|
||||
switch (w)
|
||||
{
|
||||
case WAIT_EVENT_BASE_BACKUP_THROTTLE:
|
||||
event_name = "BaseBackupThrottle";
|
||||
break;
|
||||
case WAIT_EVENT_PG_SLEEP:
|
||||
event_name = "PgSleep";
|
||||
break;
|
||||
case WAIT_EVENT_RECOVERY_APPLY_DELAY:
|
||||
event_name = "RecoveryApplyDelay";
|
||||
break;
|
||||
/* no default case, so that compiler will warn */
|
||||
}
|
||||
|
||||
return event_name;
|
||||
}
|
||||
|
||||
/* ----------
|
||||
* pgstat_get_backend_current_activity() -
|
||||
*
|
||||
@@ -3684,8 +3902,8 @@ PgstatCollectorMain(int argc, char *argv[])
|
||||
#ifndef WIN32
|
||||
wr = WaitLatchOrSocket(MyLatch,
|
||||
WL_LATCH_SET | WL_POSTMASTER_DEATH | WL_SOCKET_READABLE,
|
||||
pgStatSock,
|
||||
-1L);
|
||||
pgStatSock, -1L,
|
||||
WAIT_EVENT_PGSTAT_MAIN);
|
||||
#else
|
||||
|
||||
/*
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include "libpq/pqsignal.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "pgstat.h"
|
||||
#include "pgtime.h"
|
||||
#include "postmaster/fork_process.h"
|
||||
#include "postmaster/postmaster.h"
|
||||
@@ -424,7 +425,8 @@ SysLoggerMain(int argc, char *argv[])
|
||||
rc = WaitLatchOrSocket(MyLatch,
|
||||
WL_LATCH_SET | WL_SOCKET_READABLE | cur_flags,
|
||||
syslogPipe[0],
|
||||
cur_timeout);
|
||||
cur_timeout,
|
||||
WAIT_EVENT_SYSLOGGER_MAIN);
|
||||
|
||||
if (rc & WL_SOCKET_READABLE)
|
||||
{
|
||||
|
@@ -290,7 +290,8 @@ WalWriterMain(void)
|
||||
|
||||
rc = WaitLatch(MyLatch,
|
||||
WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH,
|
||||
cur_timeout);
|
||||
cur_timeout,
|
||||
WAIT_EVENT_WAL_WRITER_MAIN);
|
||||
|
||||
/*
|
||||
* Emergency bailout if postmaster has died. This is to avoid the
|
||||
|
Reference in New Issue
Block a user