Debian Codegraph @

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

raw
1 set test "mysql"
2
3 # Test sdt support in mysql.
4
5 global env
6
7 # deprecate as mysql no longer supports dtrace probes
8 untested "$test test is deprecated"
9 return
10
11 if {! [info exists env(SYSTEMTAP_TESTAPPS)] || (
12 ! [string match "mysql" $env(SYSTEMTAP_TESTAPPS)] &&
13 ! [string match "all" $env(SYSTEMTAP_TESTAPPS)])} {
14 untested "$test sdt app"
15 return
16 }
17
18 ########## Create stap-mysql.stp ##########
19 set msdata "[pwd]/stap-mysql"
20 set mysqlmajorrelease "5.6"
21 set mysqlrelease "mysql-5.6.26"
22 set mysqldir "[pwd]/mysql/install/"
23 set testsuite "[pwd]"
24
25 set fp [open "$testsuite/stap-mysql.stp" "w"]
26 puts $fp "
27 probe process(@1).mark(\"connection__start\")
28 {
29 arg2 = user_string(\$arg2)
30 arg3 = user_string(\$arg3)
31 printf(\"%s %#x %s %s\\n\",\"connection__start\", \$arg1, arg2, arg3);
32 }
33 probe process(@1).mark(\"connection__done\")
34 {
35 printf(\"%s %#x %#x \\n\",\"connection__done\", \$arg1, \$arg2);
36 }
37 probe process(@1).mark(\"command__start\")
38 {
39 arg3 = user_string(\$arg3)
40 arg4 = user_string(\$arg4)
41 printf(\"%s %#x %#x %s %s\\n\",\"command__start\", \$arg1, \$arg2, arg3, arg4);
42 }
43 probe process(@1).mark(\"command__done\")
44 {
45 printf(\"%s %#x\\n\",\"command__done\", \$arg1);
46 }
47 probe process(@1).mark(\"query__start\")
48 {
49 arg1 = user_string(\$arg1)
50 arg3 = user_string(\$arg3)
51 arg4 = user_string(\$arg4)
52 arg5 = user_string(\$arg5)
53 printf(\"%s %s %#x %s %s %s\\n\",\"query__start\", arg1, \$arg2,
54 arg3, arg4, arg5);
55 }
56 probe process(@1).mark(\"query__done\")
57 {
58 printf(\"%s %#x\\n\",\"query__done\", \$arg1);
59 }
60 probe process(@1).mark(\"query__parse__start\")
61 {
62 arg1 = user_string(\$arg1)
63 printf(\"%s %s\\n\",\"query__parse__start\", arg1);
64 }
65 probe process(@1).mark(\"query__parse__done\")
66 {
67 printf(\"%s %#x\\n\",\"query__parse__done\", \$arg1);
68 }
69 probe process(@1).mark(\"query__cache__hit\")
70 {
71 arg1=user_string(\$arg1)
72 arg2=user_string(\$arg2)
73 printf(\"%s %s %s \\n\",\"query__cache__hit\", arg1, arg2);
74 }
75 probe process(@1).mark(\"query__cache__miss\")
76 {
77 arg1=user_string(\$arg1)
78 printf(\"%s %s\\n\",\"query__cache__miss\", arg1);
79 }
80 probe process(@1).mark(\"query__exec__start\")
81 {
82 arg1=user_string(\$arg1)
83 arg3=user_string(\$arg3)
84 arg4=user_string(\$arg4)
85 arg5=user_string(\$arg5)
86 printf(\"%s %s %#x %s %s %s\\n\",\"query__exec__start\", arg1, \$arg2,
87 arg3, arg4, arg5);
88 }
89 probe process(@1).mark(\"query__exec__done\")
90 {
91 printf(\"%s %#x\\n\",\"query__exec__done\", \$arg1);
92 }
93 probe process(@1).mark(\"insert__row__start\")
94 {
95 arg1=user_string(\$arg1)
96 arg2=user_string(\$arg2)
97 printf(\"%s %s %s \\n\",\"insert__row__start\", arg1, arg2);
98 }
99 probe process(@1).mark(\"insert__row__done\")
100 {
101 printf(\"%s %#x\\n\",\"insert__row__done\", \$arg1);
102 }
103 probe process(@1).mark(\"update__row__start\")
104 {
105 arg1=user_string(\$arg1)
106 arg2=user_string(\$arg2)
107 printf(\"%s %s %s \\n\",\"update__row__start\", arg1, arg2);
108 }
109 probe process(@1).mark(\"update__row__done\")
110 {
111 printf(\"%s %#x\\n\",\"update__row__done\", \$arg1);
112 }
113 probe process(@1).mark(\"delete__row__start\")
114 {
115 arg1=user_string(\$arg1)
116 arg2=user_string(\$arg2)
117 printf(\"%s %s %s \\n\",\"delete__row__start\", arg1, arg2);
118 }
119 probe process(@1).mark(\"delete__row__done\")
120 {
121 printf(\"%s %#x\\n\",\"delete__row__done\", \$arg1);
122 }
123 probe process(@1).mark(\"handler__rdlock__start\")
124 {
125 arg1=user_string(\$arg1)
126 arg2=user_string(\$arg2)
127 printf(\"%s %s %s \\n\",\"handler__rdlock__start\", arg1, arg2);
128 }
129 probe process(@1).mark(\"handler__wrlock__start\")
130 {
131 arg1=user_string(\$arg1)
132 arg2=user_string(\$arg2)
133 printf(\"%s %s %s \\n\",\"handler__wrlock__start\", arg1, arg2);
134 }
135 probe process(@1).mark(\"handler__unlock__start\")
136 {
137 arg1=user_string(\$arg1)
138 arg2=user_string(\$arg2)
139 printf(\"%s %s %s \\n\",\"handler__unlock__start\", arg1, arg2);
140 }
141 probe process(@1).mark(\"handler__rdlock__done\")
142 {
143 printf(\"%s %#x\\n\",\"handler__rdlock__done\", \$arg1);
144 }
145 probe process(@1).mark(\"handler__wrlock__done\")
146 {
147 printf(\"%s %#x\\n\",\"handler__wrlock__done\", \$arg1);
148 }
149 probe process(@1).mark(\"handler__unlock__done\")
150 {
151 printf(\"%s %#x\\n\",\"handler__unlock__done\", \$arg1);
152 }
153 probe process(@1).mark(\"filesort__start\")
154 {
155 printf(\"%s %#x %#x \\n\",\"filesort__start\", \$arg1, \$arg2);
156 }
157 probe process(@1).mark(\"filesort__done\")
158 {
159 printf(\"%s %#x %#x \\n\",\"filesort__done\", \$arg1, \$arg2);
160 }
161 probe process(@1).mark(\"select__start\")
162 {
163 arg1=user_string(\$arg1)
164 printf(\"%s %s\\n\",\"select__start\", arg1);
165 }
166 probe process(@1).mark(\"select__done\")
167 {
168 printf(\"%s %#x %#x \\n\",\"select__done\", \$arg1, \$arg2);
169 }
170 probe process(@1).mark(\"insert__start\")
171 {
172 arg1=user_string(\$arg1)
173 printf(\"%s %s\\n\",\"insert__start\", arg1);
174 }
175 probe process(@1).mark(\"insert__done\")
176 {
177 printf(\"%s %#x %#x \\n\",\"insert__done\", \$arg1, \$arg2);
178 }
179 probe process(@1).mark(\"insert__select__start\")
180 {
181 arg1=user_string(\$arg1)
182 printf(\"%s %s\\n\",\"insert__select__start\", arg1);
183 }
184 probe process(@1).mark(\"insert__select__done\")
185 {
186 printf(\"%s %#x %#x \\n\",\"insert__select__done\", \$arg1, \$arg2);
187 }
188 probe process(@1).mark(\"update__start\")
189 {
190 arg1=user_string(\$arg1)
191 printf(\"%s %s\\n\",\"update__start\", arg1);
192 }
193 probe process(@1).mark(\"update__done\")
194 {
195 printf(\"%s %#x %#x %#x\\n\",\"update__done\", \$arg1, \$arg2, \$arg3);
196 }
197 probe process(@1).mark(\"multi__update__start\")
198 {
199 arg1=user_string(\$arg1)
200 printf(\"%s %s\\n\",\"multi__update__start\", arg1);
201 }
202 probe process(@1).mark(\"multi__update__done\")
203 {
204 printf(\"%s %#x %#x %#x\\n\",\"multi__update__done\", \$arg1, \$arg2, \$arg3);
205 }
206 probe process(@1).mark(\"delete__start\")
207 {
208 arg1=user_string(\$arg1)
209 printf(\"%s %s\\n\",\"delete__start\", arg1);
210 }
211 probe process(@1).mark(\"delete__done\")
212 {
213 printf(\"%s %#x %#x \\n\",\"delete__done\", \$arg1, \$arg2);
214 }
215 probe process(@1).mark(\"multi__delete__start\")
216 {
217 arg1=user_string(\$arg1)
218 printf(\"%s %s\\n\",\"multi__delete__start\", arg1);
219 }
220 probe process(@1).mark(\"multi__delete__done\")
221 {
222 printf(\"%s %#x %#x \\n\",\"multi__delete__done\", \$arg1, \$arg2);
223 }
224 probe process(@1).mark(\"net__read__start\")
225 {
226 printf(\"%s \\n\",\"net__read__start\");
227 }
228 probe process(@1).mark(\"net__read__done\")
229 {
230 printf(\"%s %#x %#x \\n\",\"net__read__done\", \$arg1, \$arg2);
231 }
232 probe process(@1).mark(\"net__write__start\")
233 {
234 printf(\"%s %#x\\n\",\"net__write__start\", \$arg1);
235 }
236 probe process(@1).mark(\"net__write__done\")
237 {
238 printf(\"%s %#x\\n\",\"net__write__done\", \$arg1);
239 }
240 "
241 close $fp
242
243 ########## Begin stap-mysql.sh ##########
244 set fp [open "$testsuite/stap-mysql.sh" "w"]
245 puts $fp "
246 ##### begin run_tests #####
247 function run_tests \{
248 /bin/rm -rf $testsuite/stap-mysql
249 $mysqldir/scripts/mysql_install_db --basedir=$mysqldir --datadir=$msdata --user=\$(whoami)
250
251 (cd $mysqldir/mysql-test
252 # wait until mysql is running
253 MOD=stapsdt_\$(date +%j%k%M%N | sed 's/ //')
254 if \[ \"\$1\"x = \"dyninstx\" \] ; then
255 echo -e \"\n##### Using --dyninst\n\" >$testsuite/stap-mysql.log
256 RUN=\"--dyninst\"
257 fi
258 echo \"$env(SYSTEMTAP_PATH)/stap \$RUN -m \$MOD -c \"$mysqldir/bin/mysqld --basedir=$mysqldir --datadir=$msdata --log-error=$msdata/mysql.log --pid-file=$msdata/mysql.pid --socket=$msdata/mysql.sock\" $testsuite/stap-mysql.stp $mysqldir/bin/mysqld >$testsuite/stap-mysql-markers.log\"
259 $env(SYSTEMTAP_PATH)/stap \$RUN -m \$MOD -c \"$mysqldir/bin/mysqld --basedir=$mysqldir --datadir=$msdata --log-error=$msdata/mysql.log --pid-file=$msdata/mysql.pid --socket=$msdata/mysql.sock\" $testsuite/stap-mysql.stp $mysqldir/bin/mysqld >$testsuite/stap-mysql-markers.log 2>&1 &
260 STAPPID=\$!
261 sleep 10
262
263 # wait until mysql is running
264 for i in \$(seq 0 10) ; do
265 if $mysqldir/bin/mysqladmin ping --socket=$msdata/mysql.sock
266 then break;
267 fi
268 sleep 5
269 done
270
271 for i in select join insert query
272 do
273 echo '##### ' \$i
274 export PERL5LIB=$mysqldir/mysql-test
275 ./mysql-test-run.pl --force --extern socket=$msdata/mysql.sock \
276 --tmpdir=/tmp/,mysql --vardir=/tmp/,mysql --do-test=\$i
277 done >> $testsuite/stap-mysql.log
278 )
279
280 ACQUIRE=\$(grep 'handler__unlock__start' $testsuite/stap-mysql-markers.log | wc -l)
281 RELEASE=\$(grep 'handler__unlock__done' $testsuite/stap-mysql-markers.log | wc -l)
282 COMMAND=\$(grep 'command__start' $testsuite/stap-mysql-markers.log | wc -l)
283 QUERY=\$(grep 'query__start' $testsuite/stap-mysql-markers.log | wc -l)
284 RDLOCK=\$(grep 'handler__rdlock__start' $testsuite/stap-mysql-markers.log | wc -l)
285 SELECT=\$(grep 'select__start' $testsuite/stap-mysql-markers.log | wc -l)
286 OKAY=\$(grep 'All.*tests were successful' $testsuite/stap-mysql.log | wc -l)
287
288 echo ACQUIRE=\$ACQUIRE RELEASE=\$RELEASE COMMAND=\$COMMAND QUERY=\$QUERY RDLOCK=\$RDLOCK SELECT=\$SELECT OKAY=\$OKAY
289 # ACQUIRE=10040 RELEASE=10040 COMMAND=11265 QUERY=11167 RDLOCK=5149 SELECT=2895 OKAY=0
290 # ACQUIRE=9055 RELEASE=9055 COMMAND=8129 QUERY=8081 RDLOCK=4913 SELECT=2155 OKAY=0
291
292 if \[ \$ACQUIRE -gt 9000 -a \$RELEASE -gt 9000 -a \$COMMAND -gt 8000 -a \$QUERY -gt 8000 -a \$RDLOCK -gt 4900 -a \$SELECT -gt 2000 \] ; then
293 echo PASS: mysql markers \$1
294 else
295 echo FAIL: mysql markers \$1
296 fi
297
298 # Do not assume that all the mysql tests passed
299 if \[ \$OKAY -eq 4 \] ; then
300 echo PASS: mysql tests \$1
301 else
302 echo XFAIL: mysql tests \$1
303 fi
304
305 mv $testsuite/stap-mysql.log $testsuite/stap-mysql-\$1.log
306 cat $testsuite/stap-mysql-markers.log >> $testsuite/stap-mysql-\$1.log
307 rm $testsuite/stap-mysql-markers.log
308
309 $mysqldir/bin/mysqladmin shutdown -u root --socket=$testsuite/stap-mysql/mysql.sock
310 kill -9 \$STAPPID
311 kill -9 \$(cat $msdata/mysql.pid)
312 }
313 ##### end run_tests #####
314
315 if \[ ! -r $mysqlrelease.tar.gz \] ; then
316 wget -q https://github.com/mysql/mysql-server/archive/$mysqlmajorrelease.tar.gz
317 # wget -q http://downloads.mysql.com/archives/mysql-5.6/$mysqlrelease.tar.gz
318 mv $mysqlmajorrelease.tar.gz $mysqlrelease.tar.gz
319 fi
320 if \[ ! -r $mysqlrelease.tar.gz \] ; then
321 echo FAIL: wget $mysqlrelease.tar.gz
322 exit
323 fi
324
325
326 if \[ ! -d mysql/src \] ; then
327 tar -x -z -f $mysqlrelease.tar.gz
328 mkdir mysql
329 # mv $mysqlrelease mysql/src
330 mv mysql-server-$mysqlmajorrelease mysql/src
331 fi
332
333 if \[ ! -d mysql/bld \] ; then
334 mkdir -p mysql/bld
335 cd mysql/bld
336 cmake ../src/ -DENABLE_DTRACE=1 -DCMAKE_INSTALL_PREFIX=$mysqldir -DCMAKE_CXX_FLAGS='-Wall -Wextra -Wformat-security -Wvla -Woverloaded-virtual -Wno-unused-parameter -fpermissive'
337 for i in \$(find . -name Makefile) ; do
338 sed -i -e 's|^CXXFLAGS =|& -g -I $env(SYSTEMTAP_INCLUDES)|' \$i
339 sed -i -e 's|^CFLAGS =|& -g -I $env(SYSTEMTAP_INCLUDES)|' \$i
340 done
341 fi
342
343 J=\$(getconf _NPROCESSORS_CONF)
344 # skip the 'make abi_check' step
345 touch do_abi_check
346
347 # mysql erroneously defines min/max which c++ limits (via sdt.h) also defines
348 sed -i -e '/HAVE_DTRACE/i\\
349 #pragma push_macro(\"max\")\\
350 #pragma push_macro(\"min\")\\
351 #undef max\\
352 #undef min' -e '/endif.*PROBES_MYSQL_H/i\\
353 #pragma pop_macro(\"max\")\\
354 #pragma pop_macro(\"min\")' ../src/include/probes_mysql.h
355
356 make -j\$J
357 make install
358 run_tests uprobe
359 run_tests dyninst
360 "
361 ########## End stap-mysql.sh ##########
362 close $fp
363
364 ########## stap-mysql.sh does most of the work ##########
365 verbose -log Running mysql testsuite
366 spawn sh stap-mysql.sh 2>&1
367 # The mysql testsuite takes quite a while to complete
368 expect {
369 -timeout 3600
370 -re {PASS: [a-z_ ]+} { regexp " .*$" $expect_out(0,string) s;
371 pass "$s"; exp_continue }
372 -re {XFAIL: [a-z_ ]+} { regexp " .*$" $expect_out(0,string) s;
373 xfail "$s"; exp_continue }
374 -re {FAIL: [a-z_ ]+} { regexp " .*$" $expect_out(0,string) s;
375 fail "$s"; exp_continue }
376 -re {UNSUPPORTED: [a-zA-Z_/: ]+} { regexp " .*$" $expect_out(0,string) s;
377 verbose -log "$s"
378 unsupported "$s"; exp_continue }
379 timeout { fail "$test (timeout)" }
380 eof { }
381 }
382 catch {close}; catch {wait}
383
384 if { $verbose == 0 } {
385 catch {exec rm -rf $msdata}
386 catch {exec rm -rf $testsuite/stap-mysql.stp $testsuite/stap-mysql.log \
387 $testsuite/stap-mysql-markers.log $testsuite/stap-mysql-dyninst.log $testsuite/stap-mysql-uprobe.log \
388 $testsuite/stap-mysql.sh $mysqlrelease.tar.gz}
389 catch {exec rm -rf mysql}
390 }