Skip site navigation (1) Skip section navigation (2)

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: (view raw, whole thread or download thread mbox)
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

ITAGAKI Takahiro
NTT Open Source Software Center

In response to

pgsql-hackers by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2018 The PostgreSQL Global Development Group