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



-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to