Debian Codegraph @

doc/SystemTap_Beginners_Guide/testsuite/systemtap.apps/postgres.exp

raw
1 set test "postgres"
2
3 # Test sdt support in postgres.
4
5 global env
6
7 if {! [info exists env(SYSTEMTAP_TESTAPPS)] || (
8 ! [string match "postgres" $env(SYSTEMTAP_TESTAPPS)] &&
9 ! [string match "all" $env(SYSTEMTAP_TESTAPPS)])} {
10 untested "$test sdt app"
11 return
12 }
13
14 ########## Create stap-postgres.stp ##########
15 set pgdata "[pwd]/stap-postgres"
16 set postgresrelease "9.4.5"
17 set postgresdir "[pwd]/postgresql-$postgresrelease/install/"
18
19 set fp [open "$pgdata.stp" "w"]
20 puts $fp "
21 probe process(\"$postgresdir/bin/postgres\").mark(\"transaction__start\")
22 {
23 printf(\"%s %#x\\n\", \$\$name, \$arg1);
24 }
25 probe process(\"$postgresdir/bin/postgres\").mark(\"transaction__commit\")
26 {
27 printf(\"%s\\n\", \$\$name);
28 }
29 probe process(\"$postgresdir/bin/postgres\").mark(\"transaction__abort\")
30 {
31 printf(\"%s\\n\", \$\$name);
32 }
33 probe process(\"$postgresdir/bin/postgres\").mark(\"lock__wait__start\")
34 {
35 printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2);
36 }
37 probe process(\"$postgresdir/bin/postgres\").mark(\"lock__wait__done\")
38 {
39 printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2);
40 }
41 probe process(\"$postgresdir/bin/postgres\").mark(\"lwlock__wait__done\")
42 {
43 printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2);
44 }
45 probe process(\"$postgresdir/bin/postgres\").mark(\"lwlock__acquire\")
46 {
47 printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2);
48 }
49 probe process(\"$postgresdir/bin/postgres\").mark(\"lwlock__condacquire__fail\")
50 {
51 printf(\"%s %#x %#x\\n\", \$\$name,
52 \$arg1, \$arg2);
53 }
54 probe process(\"$postgresdir/bin/postgres\").mark(\"lwlock__condacquire\")
55 {
56 printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2);
57 }
58 probe process(\"$postgresdir/bin/postgres\").mark(\"lwlock__release\")
59 {
60 printf(\"%s %#x\\n\", \$\$name, \$arg1);
61 }
62 "
63 close $fp
64
65 ########## Begin stap-postgres.sh ##########
66 set fp [open "$pgdata.sh" "w"]
67 puts $fp "
68 ##### begin run_tests #####
69 function run_tests \{
70 /bin/rm -rf $pgdata
71 $postgresdir/bin/initdb $pgdata
72
73 if \[ \"\$1\"x = \"dyninstx\" \] ; then
74 echo -e \"\n##### Using --dyninst\n\" >$pgdata.log
75 RUN=\"--dyninst\"
76 fi
77 echo \"$env(SYSTEMTAP_PATH)/stap \$RUN -m \$(date +stapsdt_%j%k%M%N | sed 's/ //') -c \"$postgresdir/bin/postgres -D $pgdata\" $pgdata.stp >$pgdata-markers.log\"
78 $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 &
79 STAPPID=\$!
80 sleep 10
81
82 # wait until postgres is running
83 for i in \$(seq 0 10) ; do
84 if $postgresdir/bin/pg_ctl status -D $pgdata
85 then break;
86 fi
87 sleep 5
88 done
89
90 (cd $postgresdir/../src/test/regress/
91 make installcheck >> $pgdata.log 2>&1)
92
93 ACQUIRE=\$(grep -a 'lwlock__acquire 0x\[0-9a-z\]* 0x\[0-9a-z\]*' $pgdata-markers.log | wc -l)
94 RELEASE=\$(grep -a 'lwlock__release 0x\[0-9a-z\]*' $pgdata-markers.log | wc -l)
95 START=\$(grep -a 'transaction__start 0x\[0-9a-z\]*' $pgdata-markers.log | wc -l)
96 COMMIT=\$(grep -a 'transaction__commit' $pgdata-markers.log | wc -l)
97 OKAY=\$(grep -a 'test .*ok' $pgdata.log | wc -l)
98
99 echo lwlock__acquire=\$ACQUIRE lwlock__release=\$RELEASE transaction__start=\$START transaction__commit=\$COMMIT test-ok=\$OKAY
100 : 44873 75325 591 489 0
101
102 if \[ \$ACQUIRE -ge 100000 -a \$RELEASE -gt 100000 -a \$START -gt 1000 -a \$COMMIT -gt 1000 \] ; then
103 echo PASS: postgres probe hits \$ACQUIRE/\$RELEASE/\$START/\$COMMIT
104 else
105 echo FAIL: postgres probe hits \$ACQUIRE/\$RELEASE/\$START/\$COMMIT
106 fi
107
108 if \[ \$OKAY -gt 100 \] ; then
109 echo PASS: postgres testsuite \$1 \$OKAY
110 else
111 echo FAIL: postgres testsuite \$1 \$OKAY
112 fi
113
114 mv $pgdata.log $pgdata-\$1.log
115 cat $pgdata-markers.log >> $pgdata-\$1.log
116 rm $pgdata-markers.log
117
118 $postgresdir/bin/pg_ctl stop -D $pgdata
119 kill \$STAPPID
120 \}
121
122 if \[ ! -r postgresql-$postgresrelease.tar.bz2 \] ; then
123 wget -q http://ftp.postgresql.org/pub/source/v${postgresrelease}/postgresql-$postgresrelease.tar.bz2
124 fi
125 if \[ ! -r postgresql-$postgresrelease.tar.bz2 \] ; then
126 echo FAIL: wget $postgresrelease.tar.gz
127 exit
128 fi
129
130 if \[ ! -d $postgresdir/../src/backend \] ; then
131 tar -x -f postgresql-${postgresrelease}.tar.bz2
132 fi
133
134 cd postgresql-${postgresrelease}/
135 # postgres 9.0.4 now seems to want build done from source dir
136 # mkdir bld;cd bld
137 ./configure --without-readline --enable-dtrace --prefix=$postgresdir
138 sed -i -e 's|^CFLAGS = -O2.*\$|& -g -I $env(SYSTEMTAP_INCLUDES)|' -e 's|-O2|-O0|' src/Makefile.global
139 if \[ \$(uname -m) = ppc64 \] ; then
140 sed -i -e 's|CFLAGS = |& -DSTAP_SDT_ARG_CONSTRAINT=nr |' src/Makefile.global
141 fi
142
143 J=\$(getconf _NPROCESSORS_CONF)
144 make -j\$J
145 make install
146 run_tests uprobe
147 run_tests dyninst
148 "
149
150 ########## End stap-postgres.sh ##########
151 close $fp
152
153 ########## stap-postgres.sh does most of the work ##########
154 verbose -log Running postgres testsuite
155 spawn sh $pgdata.sh 2>&1
156 expect {
157 -timeout 1000
158 -re {FAIL: [a-z_ ]+} { regexp " .*$" $expect_out(0,string) s;
159 fail "$s"; exp_continue }
160 -re {PASS: [a-z_ ]+} { regexp " .*$" $expect_out(0,string) s;
161 pass "$s"; exp_continue }
162 -re {UNSUPPORTED: [a-zA-Z_/: ]+} { regexp " .*$" $expect_out(0,string) s;
163 verbose -log "$s"
164 unsupported "$s"; exp_continue }
165 timeout { fail "$test (timeout)" }
166 eof { }
167 }
168 catch {close}; catch {wait}
169
170 if { $verbose == 0 } {
171 catch {exec rm -rf $pgdata}
172 catch {exec rm -rf $pgdata.stp $pgdata.log \
173 $pgdata-uprobe.log $pgdata-dyninst.log $pgdata.sh postgresql-${postgresrelease}.tar.bz2}
174 catch {exec rm -rf postgresql-${postgresrelease}}
175 }