set test "postgres" # Test sdt support in postgres. global env if {! [info exists env(SYSTEMTAP_TESTAPPS)] || ( ! [string match "tcl" $env(SYSTEMTAP_TESTAPPS)] && ! [string match "all" $env(SYSTEMTAP_TESTAPPS)])} { untested "$test sdt app" return } ########## Create /tmp/stap-postgres.stp ########## set postgresrelease "8.3.9" set postgresbuild "[pwd]/postgresql-$postgresrelease/bld" set postgresdir "[pwd]/postgresql-$postgresrelease/install/" set pgdata "/tmp/stap-postgres" set fp [open "$pgdata.stp" "w"] puts $fp " probe process(\"$postgresdir/bin/postgres\").mark(\"transaction__start\") { printf(\"%s %#x\\n\", \$\$name, \$arg1); } probe process(\"$postgresdir/bin/postgres\").mark(\"transaction__commit\") { printf(\"%s %#x\\n\", \$\$name, \$arg1); } probe process(\"$postgresdir/bin/postgres\").mark(\"transaction__abort\") { printf(\"%s %#x\\n\", \$\$name, \$arg1); } probe process(\"$postgresdir/bin/postgres\").mark(\"lock__startwait\") { printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2); } probe process(\"$postgresdir/bin/postgres\").mark(\"lock__endwait\") { printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2); } probe process(\"$postgresdir/bin/postgres\").mark(\"lwlock__endwait\") { printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2); } probe process(\"$postgresdir/bin/postgres\").mark(\"lwlock__acquire\") { printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2); } probe process(\"$postgresdir/bin/postgres\").mark(\"lwlock__condacquire__fail\") { printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2); } probe process(\"$postgresdir/bin/postgres\").mark(\"lwlock__condacquire\") { printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2); } probe process(\"$postgresdir/bin/postgres\").mark(\"lwlock__release\") { printf(\"%s %#x\\n\", \$\$name, \$arg1); } " close $fp ########## Begin /tmp/stap-postgres.sh ########## set fp [open "$pgdata.sh" "w"] puts $fp " function run_tests \{ /bin/rm -rf $pgdata $postgresdir/bin/initdb $pgdata which stap $env(SYSTEMTAP_PATH)/stap -m \$(date +stapsdt_%j%k%M%N | sed 's/ //') -c \"$postgresdir/bin/postgres -D $pgdata\" $pgdata.stp >$pgdata-markers.log 2>&1 & STAPPID=\$! # wait until postgres is running for i in \$(seq 0 10) ; do if $postgresdir/bin/pg_ctl status -D $pgdata then break; fi sleep 5 done (cd $postgresbuild/src/test/regress/ make installcheck > $pgdata.log 2>&1) ACQUIRE=\$(grep 'lwlock__acquire 0x\[0-9\]* 0x\[0-9\]*' $pgdata-markers.log | wc -l) RELEASE=\$(grep 'lwlock__release 0x\[0-9\]*' $pgdata-markers.log | wc -l) START=\$(grep 'transaction__start 0x\[0-9\]*' $pgdata-markers.log | wc -l) COMMIT=\$(grep 'transaction__commit 0x\[0-9\]*' $pgdata-markers.log | wc -l) OKAY=\$(grep 'test .*ok' $pgdata.log | wc -l) echo lwlock__acquire=\$ACQUIRE lwlock__release=\$RELEASE transaction__start=\$START transaction__commit=\$COMMIT test-ok=\$OKAY : 44873 75325 591 489 0 if \[ \$ACQUIRE -gt 40000 -a \$RELEASE -gt 70000 -a \$START -gt 500 -a \$COMMIT -gt 400 \] ; then echo PASS: postgres tests \$1 else echo FAIL: postgres tests \$1 fi if \[ \$OKAY -gt 100 \] ; then echo PASS: postgres markers \$1 else echo FAIL: postgres markers \$1 fi /usr/local/pgsql/bin/pg_ctl stop -D $pgdata kill \$STAPPID \} if \[ ! -r postgresql-$postgresrelease.tar.bz2 \] ; then wget http://wwwmaster.postgresql.org/redir/198/h/source/v${postgresrelease}/postgresql-$postgresrelease.tar.bz2 fi if \[ ! -r postgresql-$postgresrelease.tar.bz2 \] ; then echo FAIL: wget $postgresrelease.tar.gz exit fi if \[ ! -d $postgresbuild/src/backend \] ; then tar -x -f postgresql-${postgresrelease}.tar.bz2 fi cd postgresql-${postgresrelease}/ mkdir bld;cd bld ../configure --enable-dtrace --prefix=$postgresdir sed -i -e 's|^CFLAGS = -O2.*\$|& -g -DEXPERIMENTAL_KPROBE_SDT -I $env(SYSTEMTAP_INCLUDES)|' src/Makefile.global # make # make install # run_tests kprobe sed -i -e 's/-DEXPERIMENTAL_KPROBE_SDT//' src/Makefile.global # (cd src/backend/utils/ # make clean) make make install run_tests uprobe " ########## End /tmp/stap-postgres.sh ########## close $fp ########## /tmp/stap-postgres.sh does most of the work ########## verbose -log Running postgres testsuite spawn sh $pgdata.sh 2>&1 expect { -timeout 1000 -re {FAIL: [a-z_ ]+} { regexp " .*$" $expect_out(0,string) s; fail "$s"; exp_continue } -re {PASS: [a-z_ ]+} { regexp " .*$" $expect_out(0,string) s; pass "$s"; exp_continue } -re {UNSUPPORTED: [a-zA-Z_/: ]+} { regexp " .*$" $expect_out(0,string) s; verbose -log "$s" unsupported "$s"; exp_continue } timeout { fail "$test (timeout)" } eof { } } if { $verbose == 0 } { catch {exec rm -rf $pgdata} catch {exec rm -rf $pgdata.stp $pgdata.log \ $pgdata-markers.log $pgdata.sh postgresql-${postgresrelease}.tar.bz2} catch {exec rm -rf postgresql-${postgresrelease}} }