1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
set test "postgres"
# Test sdt support in postgres.
global env
if {! [info exists env(SYSTEMTAP_TEST_SDT)]} {
unsupported "postgres (\"SYSTEMTAP_TEST_SDT\" not in env)"
return
}
########## Create /tmp/stap-postgres.stp ##########
set postgresbuild "[pwd]/postgresql-8.3.6/bld"
set postgresdir "[pwd]/postgresql-8.3.6/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
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-8.3.6.tar.bz2 \] ; then
wget http://wwwmaster.postgresql.org/redir/198/h/source/v8.3.6/postgresql-8.3.6.tar.bz2
fi
if \[ ! -d $postgresbuild/src/backend \] ; then
tar -x -f postgresql-8.3.6.tar.bz2
fi
cd postgresql-8.3.6/
mkdir bld;cd bld
../configure --enable-dtrace --prefix=$postgresdir
# sed -i -e 's/ifeq (\$(PORTNAME), solaris)/ifeq (\$(enable_dtrace), yes)/' src/backend/Makefile
sed -i -e 's/^CFLAGS = -O2.*\$/& -g -DEXPERIMENTAL_UTRACE_SDT/' src/Makefile.global
make
make install
run_tests utrace
sed -i -e 's/UTRACE/KPROBE/' src/Makefile.global
(cd src/backend/utils/
make clean)
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-8.3.6.tar.bz2}
catch {exec rm -rf postgresql-8.3.6}
}
|