Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bcc
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
la
platform
external
bcc
Commits
46017920
Commit
46017920
authored
7 years ago
by
Paul Chaignon
Browse files
Options
Downloads
Patches
Plain Diff
dbslower: linter cleanup
parent
e617bf40
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tools/dbslower.py
+21
-15
21 additions, 15 deletions
tools/dbslower.py
with
21 additions
and
15 deletions
tools/dbslower.py
+
21
−
15
View file @
46017920
...
...
@@ -2,17 +2,18 @@
#
# dbslower Trace MySQL and PostgreSQL queries slower than a threshold.
#
# USAGE: dbslower [-v] [-p PID [PID ...]] [-b PATH_TO_BINARY] [-m THRESHOLD] {mysql,postgres}
# USAGE: dbslower [-v] [-p PID [PID ...]] [-b PATH_TO_BINARY] [-m THRESHOLD]
# {mysql,postgres}
#
# By default, a threshold of 1ms is used. Set the threshold to 0 to trace all
# queries (verbose).
#
# Script works in two different modes:
# 1) USDT probes, which means it needs MySQL and PostgreSQL built with
# queries (verbose).
#
# Script works in two different modes:
# 1) USDT probes, which means it needs MySQL and PostgreSQL built with
# USDT (DTrace) support.
# 2) uprobe and uretprobe on exported function of binary specified by
# 2) uprobe and uretprobe on exported function of binary specified by
# PATH_TO_BINARY parameter. (At the moment only MySQL support)
#
#
# If no PID or PATH_TO_BINARY is provided, the script attempts to discover
# all MySQL or PostgreSQL database processes and uses USDT probes.
#
...
...
@@ -57,12 +58,13 @@ threshold_ns = args.threshold * 1000000
mode
=
"
USDT
"
if
args
.
path
and
not
args
.
pids
:
if
args
.
db
==
"
mysql
"
:
symbols
=
BPF
.
get_user_functions_and_addresses
(
args
.
path
,
"
\\
w+dispatch_command
\\
w+
"
)
regex
=
"
\\
w+dispatch_command
\\
w+
"
symbols
=
BPF
.
get_user_functions_and_addresses
(
args
.
path
,
regex
)
if
len
(
symbols
)
==
0
:
print
(
"
Can
'
t find function
'
dispatch_command
'
in %s
"
%
(
args
.
path
))
exit
(
1
)
(
mysql_func_name
,
addr
)
=
symbols
[
0
]
if
mysql_func_name
.
find
(
"
COM_DATA
"
)
>=
0
:
...
...
@@ -71,7 +73,8 @@ if args.path and not args.pids:
mode
=
"
MYSQL56
"
else
:
# Placeholder for PostrgeSQL
# Look on functions initStringInfo, pgstat_report_activity, EndCommand, NullCommand
# Look on functions initStringInfo, pgstat_report_activity, EndCommand,
# NullCommand
print
(
"
Sorry at the moment PostgreSQL supports only USDT
"
)
exit
(
1
)
...
...
@@ -109,7 +112,7 @@ int query_start(struct pt_regs *ctx) {
#if defined(MYSQL56) || defined(MYSQL57)
/*
Trace only packets with enum_server_command == COM_QUERY
Trace only packets with enum_server_command == COM_QUERY
*/
#ifdef MYSQL56
u64 command = (u64) PT_REGS_PARM1(ctx);
...
...
@@ -148,7 +151,7 @@ int query_end(struct pt_regs *ctx) {
u64 delta = bpf_ktime_get_ns() - tempp->timestamp;
#ifdef THRESHOLD
if (delta >= THRESHOLD) {
#endif //THRESHOLD
#endif //THRESHOLD
struct data_t data = {};
data.pid = pid >> 32; // only process id
data.timestamp = tempp->timestamp;
...
...
@@ -164,13 +167,16 @@ int query_end(struct pt_regs *ctx) {
"""
.
replace
(
"
DEFINE_USDT
"
,
"
#define USDT
"
if
mode
==
"
USDT
"
else
""
)
\
.
replace
(
"
DEFINE_MYSQL56
"
,
"
#define MYSQL56
"
if
mode
==
"
MYSQL56
"
else
""
)
\
.
replace
(
"
DEFINE_MYSQL57
"
,
"
#define MYSQL57
"
if
mode
==
"
MYSQL57
"
else
""
)
\
.
replace
(
"
DEFINE_THRESHOLD
"
,
(
"
#define THRESHOLD
"
+
str
(
threshold_ns
))
if
threshold_ns
>
0
else
""
)
.
replace
(
"
DEFINE_THRESHOLD
"
,
"
#define THRESHOLD %d
"
%
threshold_ns
if
threshold_ns
>
0
else
""
)
if
mode
.
startswith
(
"
MYSQL
"
):
# Uprobes mode
bpf
=
BPF
(
text
=
program
)
bpf
.
attach_uprobe
(
name
=
args
.
path
,
sym
=
mysql_func_name
,
fn_name
=
"
query_start
"
)
bpf
.
attach_uretprobe
(
name
=
args
.
path
,
sym
=
mysql_func_name
,
fn_name
=
"
query_end
"
)
bpf
.
attach_uprobe
(
name
=
args
.
path
,
sym
=
mysql_func_name
,
fn_name
=
"
query_start
"
)
bpf
.
attach_uretprobe
(
name
=
args
.
path
,
sym
=
mysql_func_name
,
fn_name
=
"
query_end
"
)
else
:
# USDT mode
if
not
args
.
pids
or
len
(
args
.
pids
)
==
0
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment