trace hooks (for 2nd commitfest)

From: Itagaki Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Dimitri Fontaine <dfontaine(at)hi-media(dot)com>
Subject: trace hooks (for 2nd commitfest)
Date: 2009-07-23 07:56:48
Message-ID: 20090723162853.9828.52131E4D@oss.ntt.co.jp
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> How about export dtrace functions as hook function pointers?

Here is a proposal to integrate profiler to postgres without adding
any tracing markers. The goal is to provide platform-independent
and easy-to-use performance profiler. (typically just adding some
configuration to postgresql.conf.)

----
1. Add Gen_trace_hooks.sed to generate hook functions from probes.d.
It appends hook variables at the tail of probes.h like:
extern void (*TRANSACTION_START_hook)(LocalTransactionId arg1);

2. Rewrite trace function calls into PG_TRACE(name, (args...)).
Trace macros are defined as:
#define PG_TRACE(name, args) \
do { \
TRACE_POSTGRESQL_##name args; \
if (name##_hook) \
name##_hook args; \
} while(0)
and called as:
PG_TRACE(TRANSACTION_START, (vxid.localTransactionId));

The changes are not always necessary, but PG_TRACE macro is
useful to add common logic for all probes. We can also use it
to disable probes; Gen_dummy_probes.sed will be no longer needed.

3. Implement profiler using trace hooks.
Timer callbacks might be needed for periodical sampling,
but I'll try to use simple polling from sql for now.
----

I tested performance regression by empty dtrace-probes and empty
trace-hooks, but the differences were 1-2%. Close enough to dtrace.

$ pgbench -n -S -c8 -T60
No probes : tps = 28103
ENABLE_TRACE_HOOK only : tps = 28101
ENABLE_DTRACE only : tps = 27945
Enable both : tps = 27760

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Dimitri Fontaine 2009-07-23 08:08:34 Re: Extension Facility
Previous Message Mark Kirkwood 2009-07-23 07:41:56 Re: Lock Wait Statistics (next commitfest)