File: postgres.exp

package info (click to toggle)
systemtap 5.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 47,556 kB
  • sloc: cpp: 81,117; ansic: 54,933; xml: 49,795; exp: 43,595; sh: 11,526; python: 5,003; perl: 2,252; tcl: 1,312; makefile: 1,006; javascript: 149; lisp: 105; awk: 101; asm: 91; java: 70; sed: 16
file content (175 lines) | stat: -rw-r--r-- 5,435 bytes parent folder | download | duplicates (3)
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
167
168
169
170
171
172
173
174
175
set test "postgres"

# Test sdt support in postgres.

global env

if {! [info exists env(SYSTEMTAP_TESTAPPS)] || (
    ! [string match "postgres" $env(SYSTEMTAP_TESTAPPS)] &&
    ! [string match "all" $env(SYSTEMTAP_TESTAPPS)])} {
    untested "$test sdt app"
    return
}

########## Create stap-postgres.stp ########## 
set pgdata "[pwd]/stap-postgres"
set postgresrelease "9.4.5"
set postgresdir "[pwd]/postgresql-$postgresrelease/install/"

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\\n\", \$\$name);
}
probe process(\"$postgresdir/bin/postgres\").mark(\"transaction__abort\")
{
  printf(\"%s\\n\", \$\$name);
}
probe process(\"$postgresdir/bin/postgres\").mark(\"lock__wait__start\")
{
  printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2);
}
probe process(\"$postgresdir/bin/postgres\").mark(\"lock__wait__done\")
{
  printf(\"%s %#x %#x\\n\", \$\$name, \$arg1, \$arg2);
}
probe process(\"$postgresdir/bin/postgres\").mark(\"lwlock__wait__done\")
{
  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 stap-postgres.sh ########## 
set fp [open "$pgdata.sh" "w"]
puts $fp "
##### begin run_tests #####
function run_tests \{
/bin/rm -rf $pgdata
$postgresdir/bin/initdb $pgdata

if \[ \"\$1\"x = \"dyninstx\" \] ; then 
   echo -e \"\n##### Using --dyninst\n\" >$pgdata.log
   RUN=\"--dyninst\" 
fi
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\"
$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=\$!
sleep 10

# 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 $postgresdir/../src/test/regress/
 make installcheck >> $pgdata.log 2>&1)

ACQUIRE=\$(grep -a 'lwlock__acquire 0x\[0-9a-z\]* 0x\[0-9a-z\]*' $pgdata-markers.log | wc -l)
RELEASE=\$(grep -a 'lwlock__release 0x\[0-9a-z\]*' $pgdata-markers.log | wc -l)
START=\$(grep -a 'transaction__start 0x\[0-9a-z\]*' $pgdata-markers.log | wc -l)
COMMIT=\$(grep -a 'transaction__commit' $pgdata-markers.log | wc -l)
OKAY=\$(grep -a '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 -ge 100000 -a \$RELEASE -gt 100000 -a \$START -gt 1000 -a \$COMMIT -gt 1000 \] ; then
   echo PASS: postgres probe hits \$ACQUIRE/\$RELEASE/\$START/\$COMMIT
else
   echo FAIL: postgres probe hits \$ACQUIRE/\$RELEASE/\$START/\$COMMIT
fi

if \[ \$OKAY -gt 100 \] ; then
   echo PASS: postgres testsuite \$1 \$OKAY
else
   echo FAIL: postgres testsuite \$1 \$OKAY
fi

mv $pgdata.log $pgdata-\$1.log
cat $pgdata-markers.log >> $pgdata-\$1.log
rm $pgdata-markers.log

$postgresdir/bin/pg_ctl stop -D $pgdata
kill \$STAPPID
\}

if \[ ! -r postgresql-$postgresrelease.tar.bz2 \] ; then
wget -q http://ftp.postgresql.org/pub/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 $postgresdir/../src/backend \] ; then
tar -x -f postgresql-${postgresrelease}.tar.bz2
fi

cd postgresql-${postgresrelease}/
# postgres 9.0.4 now seems to want build done from source dir
# mkdir bld;cd bld
./configure --without-readline --enable-dtrace --prefix=$postgresdir
sed -i -e 's|^CFLAGS = -O2.*\$|& -g -I $env(SYSTEMTAP_INCLUDES)|' -e 's|-O2|-O0|' src/Makefile.global
if \[ \$(uname -m) = ppc64 \] ; then 
   sed -i -e 's|CFLAGS = |& -DSTAP_SDT_ARG_CONSTRAINT=nr |' src/Makefile.global
fi

J=\$(getconf _NPROCESSORS_CONF)
make -j\$J
make install
run_tests uprobe
run_tests dyninst
"

########## End stap-postgres.sh ########## 
close $fp

########## 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 { }
}
catch {close}; catch {wait}

if { $verbose == 0 } {
catch {exec rm -rf $pgdata}
catch {exec rm -rf $pgdata.stp $pgdata.log \
	   $pgdata-uprobe.log $pgdata-dyninst.log $pgdata.sh postgresql-${postgresrelease}.tar.bz2}
catch {exec rm -rf postgresql-${postgresrelease}}
}