Commit 46017920 authored by Paul Chaignon's avatar Paul Chaignon

dbslower: linter cleanup

parent e617bf40
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
# #
# dbslower Trace MySQL and PostgreSQL queries slower than a threshold. # 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 # By default, a threshold of 1ms is used. Set the threshold to 0 to trace all
# queries (verbose). # queries (verbose).
...@@ -57,7 +58,8 @@ threshold_ns = args.threshold * 1000000 ...@@ -57,7 +58,8 @@ threshold_ns = args.threshold * 1000000
mode = "USDT" mode = "USDT"
if args.path and not args.pids: if args.path and not args.pids:
if args.db == "mysql": 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: if len(symbols) == 0:
print("Can't find function 'dispatch_command' in %s" % (args.path)) print("Can't find function 'dispatch_command' in %s" % (args.path))
...@@ -71,7 +73,8 @@ if args.path and not args.pids: ...@@ -71,7 +73,8 @@ if args.path and not args.pids:
mode = "MYSQL56" mode = "MYSQL56"
else: else:
# Placeholder for PostrgeSQL # 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") print("Sorry at the moment PostgreSQL supports only USDT")
exit(1) exit(1)
...@@ -164,13 +167,16 @@ int query_end(struct pt_regs *ctx) { ...@@ -164,13 +167,16 @@ int query_end(struct pt_regs *ctx) {
""".replace("DEFINE_USDT", "#define USDT" if mode == "USDT" else "") \ """.replace("DEFINE_USDT", "#define USDT" if mode == "USDT" else "") \
.replace("DEFINE_MYSQL56", "#define MYSQL56" if mode == "MYSQL56" else "") \ .replace("DEFINE_MYSQL56", "#define MYSQL56" if mode == "MYSQL56" else "") \
.replace("DEFINE_MYSQL57", "#define MYSQL57" if mode == "MYSQL57" 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"): if mode.startswith("MYSQL"):
# Uprobes mode # Uprobes mode
bpf = BPF(text=program) bpf = BPF(text=program)
bpf.attach_uprobe(name=args.path, sym=mysql_func_name, fn_name="query_start") bpf.attach_uprobe(name=args.path, sym=mysql_func_name,
bpf.attach_uretprobe(name=args.path, sym=mysql_func_name, fn_name="query_end") fn_name="query_start")
bpf.attach_uretprobe(name=args.path, sym=mysql_func_name,
fn_name="query_end")
else: else:
# USDT mode # USDT mode
if not args.pids or len(args.pids) == 0: if not args.pids or len(args.pids) == 0:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment