Skip to content

Commit 525975f

Browse files
Nik Samokhvalovclaude
andcommitted
Add USDT static tracepoints to pgstat_report_wait_start/end
Add wait__event__start and wait__event__end probes to the DTrace provider definition and invoke them from the static inline functions pgstat_report_wait_start() and pgstat_report_wait_end(). Because these functions are static inline, they get inlined at every call site (~100 locations across 36 files), leaving no function symbol for eBPF uprobes to attach to. USDT probes solve this: the compiler emits a nop instruction at each inlined site with ELF .note.stapsdt metadata, allowing eBPF tools to discover and attach to all call sites with a single probe definition. This enables full eBPF-based wait event tracing (e.g., with bpftrace) without requiring hardware watchpoints or PostgreSQL source patches beyond this change. When built without --enable-dtrace, the probes compile to do {} while(0) with zero overhead. PoC: covers all wait events via the two central inline functions. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 1c5bf11 commit 525975f

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

src/backend/utils/probes.d

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,7 @@ provider postgresql {
9191
probe wal__switch();
9292
probe wal__buffer__write__dirty__start();
9393
probe wal__buffer__write__dirty__done();
94+
95+
probe wait__event__start(unsigned int);
96+
probe wait__event__end();
9497
};

src/include/utils/wait_event.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/* enums for wait events */
1414
#include "utils/wait_event_types.h"
15+
#include "utils/probes.h"
1516

1617
extern const char *pgstat_get_wait_event(uint32 wait_event_info);
1718
extern const char *pgstat_get_wait_event_type(uint32 wait_event_info);
@@ -73,6 +74,8 @@ pgstat_report_wait_start(uint32 wait_event_info)
7374
* four-bytes, updates are atomic.
7475
*/
7576
*(volatile uint32 *) my_wait_event_info = wait_event_info;
77+
78+
TRACE_POSTGRESQL_WAIT_EVENT_START(wait_event_info);
7679
}
7780

7881
/* ----------
@@ -86,6 +89,8 @@ pgstat_report_wait_end(void)
8689
{
8790
/* see pgstat_report_wait_start() */
8891
*(volatile uint32 *) my_wait_event_info = 0;
92+
93+
TRACE_POSTGRESQL_WAIT_EVENT_END();
8994
}
9095

9196

0 commit comments

Comments
 (0)