Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ fi
AC_SUBST(DTRACEFLAGS)])
AC_SUBST(enable_dtrace)

#
# --enable-wait-event-timing adds wait event timing instrumentation
#
PGAC_ARG_BOOL(enable, wait-event-timing, no,
[build with wait event timing instrumentation],
[AC_DEFINE([USE_WAIT_EVENT_TIMING], 1,
[Define to 1 to build with wait event timing. (--enable-wait-event-timing)])])

#
# TAP tests
#
Expand Down
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ meson_bin = find_program(meson_binpath, native: true)

cdata.set('USE_ASSERT_CHECKING', get_option('cassert') ? 1 : false)
cdata.set('USE_INJECTION_POINTS', get_option('injection_points') ? 1 : false)
cdata.set('USE_WAIT_EVENT_TIMING', get_option('wait_event_timing') ? 1 : false)

blocksize = get_option('blocksize').to_int() * 1024

Expand Down
3 changes: 3 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ option('pgport', type: 'integer', value: 5432,
option('cassert', type: 'boolean', value: false,
description: 'Enable assertion checks (for debugging)')

option('wait_event_timing', type: 'boolean', value: false,
description: 'Enable wait event timing instrumentation')

option('tap_tests', type: 'feature', value: 'auto',
description: 'Enable TAP tests')

Expand Down
10 changes: 10 additions & 0 deletions src/backend/storage/ipc/ipci.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ CalculateShmemSize(void)
size = add_size(size, AsyncShmemSize());
size = add_size(size, StatsShmemSize());
size = add_size(size, WaitEventCustomShmemSize());
#ifdef USE_WAIT_EVENT_TIMING
size = add_size(size, WaitEventTimingShmemSize());
size = add_size(size, WaitEventQueryShmemSize());
size = add_size(size, WaitEventTraceShmemSize());
#endif
size = add_size(size, InjectionPointShmemSize());
size = add_size(size, SlotSyncShmemSize());
size = add_size(size, AioShmemSize());
Expand Down Expand Up @@ -325,6 +330,11 @@ CreateOrAttachShmemStructs(void)
AsyncShmemInit();
StatsShmemInit();
WaitEventCustomShmemInit();
#ifdef USE_WAIT_EVENT_TIMING
WaitEventTimingShmemInit();
WaitEventQueryShmemInit();
WaitEventTraceShmemInit();
#endif
InjectionPointShmemInit();
AioShmemInit();
WaitLSNShmemInit();
Expand Down
12 changes: 12 additions & 0 deletions src/backend/storage/lmgr/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ InitProcess(void)

/* now that we have a proc, report wait events to shared memory */
pgstat_set_wait_event_storage(&MyProc->wait_event_info);
#ifdef USE_WAIT_EVENT_TIMING
pgstat_set_wait_event_timing_storage(GetNumberFromPGProc(MyProc));
#endif

/*
* We might be reusing a semaphore that belonged to a failed process. So
Expand Down Expand Up @@ -701,6 +704,9 @@ InitAuxiliaryProcess(void)

/* now that we have a proc, report wait events to shared memory */
pgstat_set_wait_event_storage(&MyProc->wait_event_info);
#ifdef USE_WAIT_EVENT_TIMING
pgstat_set_wait_event_timing_storage(GetNumberFromPGProc(MyProc));
#endif

/* Check that group locking fields are in a proper initial state. */
Assert(MyProc->lockGroupLeader == NULL);
Expand Down Expand Up @@ -991,6 +997,9 @@ ProcKill(int code, Datum arg)
*/
SwitchBackToLocalLatch();
pgstat_reset_wait_event_storage();
#ifdef USE_WAIT_EVENT_TIMING
pgstat_reset_wait_event_timing_storage();
#endif

proc = MyProc;
MyProc = NULL;
Expand Down Expand Up @@ -1056,6 +1065,9 @@ AuxiliaryProcKill(int code, Datum arg)
/* look at the equivalent ProcKill() code for comments */
SwitchBackToLocalLatch();
pgstat_reset_wait_event_storage();
#ifdef USE_WAIT_EVENT_TIMING
pgstat_reset_wait_event_timing_storage();
#endif

proc = MyProc;
MyProc = NULL;
Expand Down
3 changes: 2 additions & 1 deletion src/backend/utils/activity/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ OBJS = \
pgstat_wal.o \
pgstat_xact.o \
wait_event.o \
wait_event_funcs.o
wait_event_funcs.o \
wait_event_timing.o

# Force these dependencies to be known even without dependency info built:
wait_event.o: wait_event.c $(top_builddir)/src/backend/utils/pgstat_wait_event.c
Expand Down
12 changes: 12 additions & 0 deletions src/backend/utils/activity/backend_status.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "storage/proc.h" /* for MyProc */
#include "storage/procarray.h"
#include "utils/ascii.h"
#ifdef USE_WAIT_EVENT_TIMING
#include "utils/wait_event_timing.h"
#endif
#include "utils/guc.h" /* for application_name */
#include "utils/memutils.h"

Expand Down Expand Up @@ -249,6 +252,15 @@ pgstat_beinit(void)
Assert(MyProcNumber >= 0 && MyProcNumber < NumBackendStatSlots);
MyBEEntry = &BackendStatusArray[MyProcNumber];

#ifdef USE_WAIT_EVENT_TIMING
/*
* Point the wait event timing query_id pointer at our st_query_id.
* This must happen here (not in InitProcess) because MyBEEntry is
* not yet set when pgstat_set_wait_event_timing_storage() runs.
*/
my_wait_event_query_id_ptr = &MyBEEntry->st_query_id;
#endif

/* Set up a process-exit hook to clean up */
on_shmem_exit(pgstat_beshutdown_hook, 0);
}
Expand Down
1 change: 1 addition & 0 deletions src/backend/utils/activity/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ backend_sources += files(
'pgstat_subscription.c',
'pgstat_wal.c',
'pgstat_xact.c',
'wait_event_timing.c',
)

# this includes a .c file with contents generated in ../../../include/activity,
Expand Down
Loading