I updated Sampling profiler patch to be applied to HEAD cleanly.
Basic concept of the patch is same as DTrace probes:
Call pgstat_push_condition(condition) before a operation and call
pgstat_pop_condition() at the end of the operation. Those functions
should be light-weight because they only change a variable on shared
memory without any locks.
Stats collector process checks those shard variables periodically and
sums the status in collector's local memory. We cannot know exact
numbers of each operation, but can expect the sampling numbers reflect
the tendency of times spend in each operation. The sampling result
can be retrived with pg_profiles system view.
Of course the profiler could be implemented on the top of DTrace or
SystemTap, but it is not so easy if we try to avoid any performance
regressions and to provide the information by VIEW-like interface.
Also, this approach is platform-independent.
A new feature compared with previous patch is function
pgstat_register_condition(condition, name).
We can add user-defined conditions in extended modules.
Comments welcome.
Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center