xref: /aosp_15_r20/external/bcc/tools/mysqld_qslower_example.txt (revision 387f9dfdfa2baef462e92476d413c7bc2470293e)
1*387f9dfdSAndroid Build Coastguard WorkerDemonstrations of mysqld_qslower, the Linux eBPF/bcc version.
2*387f9dfdSAndroid Build Coastguard Worker
3*387f9dfdSAndroid Build Coastguard Worker
4*387f9dfdSAndroid Build Coastguard Workermysqld_qslower traces queries served by a MySQL server, and prints those that
5*387f9dfdSAndroid Build Coastguard Workerexceed a latency (query time) threshold. By default a threshold of 1 ms is
6*387f9dfdSAndroid Build Coastguard Workerused. For example:
7*387f9dfdSAndroid Build Coastguard Worker
8*387f9dfdSAndroid Build Coastguard Worker# ./mysqld_qslower.py `pgrep -n mysqld`
9*387f9dfdSAndroid Build Coastguard WorkerTracing MySQL server queries for PID 14371 slower than 1 ms...
10*387f9dfdSAndroid Build Coastguard WorkerTIME(s)        PID          MS QUERY
11*387f9dfdSAndroid Build Coastguard Worker0.000000       18608   130.751 SELECT * FROM words WHERE word REGEXP '^bre.*n$'
12*387f9dfdSAndroid Build Coastguard Worker2.921535       18608   130.590 SELECT * FROM words WHERE word REGEXP '^alex.*$'
13*387f9dfdSAndroid Build Coastguard Worker4.603549       18608    24.164 SELECT COUNT(*) FROM words
14*387f9dfdSAndroid Build Coastguard Worker9.733847       18608   130.936 SELECT count(*) AS count FROM words WHERE word REGEXP '^bre.*n$'
15*387f9dfdSAndroid Build Coastguard Worker17.864776      18608   130.298 SELECT * FROM words WHERE word REGEXP '^bre.*n$' ORDER BY word
16*387f9dfdSAndroid Build Coastguard Worker
17*387f9dfdSAndroid Build Coastguard WorkerThis traced 5 queries, 4 of which took about 130 milliseconds.
18*387f9dfdSAndroid Build Coastguard Worker
19*387f9dfdSAndroid Build Coastguard WorkerA pgrep command was used to specify the PID of mysqld.
20*387f9dfdSAndroid Build Coastguard Worker
21*387f9dfdSAndroid Build Coastguard Worker
22*387f9dfdSAndroid Build Coastguard WorkerIn this example, a lower threshold is used of 0.1 ms:
23*387f9dfdSAndroid Build Coastguard Worker
24*387f9dfdSAndroid Build Coastguard Worker# ./mysqld_qslower.py `pgrep -n mysqld` 0.1
25*387f9dfdSAndroid Build Coastguard WorkerTracing MySQL server queries for PID 14371 slower than 0.1 ms...
26*387f9dfdSAndroid Build Coastguard WorkerTIME(s)        PID          MS QUERY
27*387f9dfdSAndroid Build Coastguard Worker0.000000       18608    24.201 SELECT COUNT(*) FROM words
28*387f9dfdSAndroid Build Coastguard Worker13.242390      18608   130.378 SELECT * FROM words WHERE word REGEXP '^bre.*n$'
29*387f9dfdSAndroid Build Coastguard Worker23.601751      18608   119.198 SELECT * FROM words WHERE word REGEXP '^zzzzzzzz$'
30*387f9dfdSAndroid Build Coastguard Worker
31*387f9dfdSAndroid Build Coastguard WorkerIt worked, but I'm not catching any faster queries in this example. Notice I
32*387f9dfdSAndroid Build Coastguard Workeradded a query that searched for "zzzzzzzz": it returned an empty set, and ran
33*387f9dfdSAndroid Build Coastguard Worker11 ms faster.
34*387f9dfdSAndroid Build Coastguard Worker
35*387f9dfdSAndroid Build Coastguard Worker
36*387f9dfdSAndroid Build Coastguard WorkerA 0 ms threshold can be specified to trace all queries:
37*387f9dfdSAndroid Build Coastguard Worker
38*387f9dfdSAndroid Build Coastguard Worker# ./mysqld_qslower.py `pgrep -n mysqld` 0
39*387f9dfdSAndroid Build Coastguard WorkerTracing MySQL server queries for PID 14371 slower than 0 ms...
40*387f9dfdSAndroid Build Coastguard WorkerTIME(s)        PID          MS QUERY
41*387f9dfdSAndroid Build Coastguard Worker0.000000       18608     0.105 select @@version_comment limit 1
42*387f9dfdSAndroid Build Coastguard Worker2.049312       18608     0.099 SELECT DATABASE()
43*387f9dfdSAndroid Build Coastguard Worker2.050666       18608     0.274 show databases
44*387f9dfdSAndroid Build Coastguard Worker2.051040       18608     0.176 show tables
45*387f9dfdSAndroid Build Coastguard Worker5.730044       18608   130.365 SELECT count(*) AS count FROM words WHERE word REGEXP '^bre.*n$'
46*387f9dfdSAndroid Build Coastguard Worker9.273837       18608     0.096 select 1
47*387f9dfdSAndroid Build Coastguard Worker9.553742       18608     0.059 select 1
48*387f9dfdSAndroid Build Coastguard Worker9.986087       18608     0.080 select 1
49*387f9dfdSAndroid Build Coastguard Worker
50*387f9dfdSAndroid Build Coastguard WorkerThis includes an initialization of a mysql client command, and selecting the
51*387f9dfdSAndroid Build Coastguard Workerdatabase. I also added some "select 1;" queries, which do no work and return
52*387f9dfdSAndroid Build Coastguard Workerquickly.
53*387f9dfdSAndroid Build Coastguard Worker
54*387f9dfdSAndroid Build Coastguard Worker
55*387f9dfdSAndroid Build Coastguard WorkerUSAGE:
56*387f9dfdSAndroid Build Coastguard Worker
57*387f9dfdSAndroid Build Coastguard Worker# ./mysqld_qslower.py -h
58*387f9dfdSAndroid Build Coastguard WorkerUSAGE: mysqld_latency PID [min_ms]
59