Building Postgres with SystemTap static user markers enabled
Replace sdt.h with sduprobes.h in the Postgres tracing include file
sed -i -e 's/<sys.sdt.h./"sduprobes.h"/' <postgres-src-dir>/src/src/include/pg_trace.h ln -s /usr/local/share/systemtap/runtime/sduprobes.h <postgres-src-dir>/src/src/include
Create a script called dtrace, which can be found on $PATH while building Postgres, that is defined as follows. It is used to generate profile.o.
while test ! -z "$1" ; do
if [ $(expr "$1" : "-o") -gt 0 ] ; then
shift
filename=$1
fi
shift
done
echo '_dtrace_ () {}' >| /tmp/$$.c
gcc -c /tmp/$$.c -o /tmp/probes.o
mv /tmp/probes.o $filename
rm /tmp/$$.cPostgres sources which use tracing need to be built with debugging information.
sed -i -e 's/^CFLAGS = /CFLAGS = -g /' <postgres-build-dir>/src/Makefile.global
Run postgres under the control of stap
PGDATA=<initdb-location> stap -c '/usr/local/pgsql/bin/postgres' postgres.stp
An example of postgres.stp is:
probe process("/usr/local/pgsql/bin/postgres").mark("transaction__start")
{
printf("%s %#x\n", "transaction__start", $arg1);
}
probe process("/usr/local/pgsql/bin/postgres").mark("transaction__commit")
{
printf("%s %#x\n", "transaction__commit", $arg1);
}
probe process("/usr/local/pgsql/bin/postgres").mark("transaction__abort")
{
printf("%s %#x\n", "transaction__abort", $arg1);
}
probe process("/usr/local/pgsql/bin/postgres").mark("lock__startwait")
{
printf("%s %#x %#x\n", "lock__startwait", $arg1, $arg2);
}
probe process("/usr/local/pgsql/bin/postgres").mark("lock__endwait")
{
printf("%s %#x %#x\n", "lock__endwait", $arg1, $arg2);
}
probe process("/usr/local/pgsql/bin/postgres").mark("lwlock__endwait")
{
printf("%s %#x %#x\n", "lwlock__endwait", $arg1, $arg2);
}
probe process("/usr/local/pgsql/bin/postgres").mark("lwlock__acquire")
{
printf("%s %#x %#x\n", "lwlock__acquire", $arg1, $arg2);
}
probe process("/usr/local/pgsql/bin/postgres").mark("lwlock__condacquire__fail")
{
printf("%s %#x %#x\n", "lwlock__condacquire__fail",
$arg1, $arg2);
}
probe process("/usr/local/pgsql/bin/postgres").mark("lwlock__condacquire")
{
printf("%s %#x %#x\n", "lwlock__condacquire", $arg1, $arg2);
}
probe process("/usr/local/pgsql/bin/postgres").mark("lwlock__release")
{
printf("%s %#x\n", "lwlock__release", $arg1);
}