Skip to content

Commit

Permalink
Travis CI build to check compliance with PEP8 (iovisor#987)
Browse files Browse the repository at this point in the history
* Travis CI build to check compliance with PEP8

* argdist: linter cleanup

* dbslower: linter cleanup

* dbstat: linter cleanup

* memleak: linter cleanup

* syscount: linter cleanup

* tplist: linter cleanup

* trace: linter cleanup

* ucalls: linter cleanup

* uflow: linter cleanup

* ugc: linter cleanup

* uobjnew: linter cleanup

* ustat: linter cleanup
  • Loading branch information
pchaigno authored and goldshtn committed Mar 4, 2017
1 parent 0a2a46e commit 956ca1c
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 32 deletions.
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: generic
install:
- sudo apt-get install -y python-pip
- sudo pip install pep8
script:
- find tools/ -type f -name "*.py" | xargs pep8 -r --show-source --ignore=E123,E125,E126,E127,E128,E302
6 changes: 3 additions & 3 deletions tools/argdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def __init__(self, tool, type, specifier):
elif self.probe_type == "u":
self.library = parts[1]
self.probe_func_name = self._make_valid_identifier(
"%s_probe%d" % \
"%s_probe%d" %
(self.function, Probe.next_probe_index))
self._enable_usdt_probe()
else:
Expand Down Expand Up @@ -238,10 +238,10 @@ def check(expr):
(any(map(check, self.exprs)) or check(self.filter))

self.probe_func_name = self._make_valid_identifier(
"%s_probe%d" % \
"%s_probe%d" %
(self.function, Probe.next_probe_index))
self.probe_hash_name = self._make_valid_identifier(
"%s_hash%d" % \
"%s_hash%d" %
(self.function, Probe.next_probe_index))
Probe.next_probe_index += 1

Expand Down
5 changes: 2 additions & 3 deletions tools/dbslower.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
# Strongly inspired by Brendan Gregg's work on the mysqld_qslower script.
#
# Copyright 2017, Sasha Goldshtein
# Copyright 2017, Sasha Goldshtein
# Licensed under the Apache License, Version 2.0
#
# 15-Feb-2017 Sasha Goldshtein Created this.
Expand All @@ -27,7 +27,7 @@
dbslower postgres # trace PostgreSQL queries slower than 1ms
dbslower postgres -p 188 322 # trace specific PostgreSQL processes
dbslower mysql -p 480 -m 30 # trace MySQL queries slower than 30ms
dbslower mysql -p 480 -v # trace MySQL queries and print the BPF program
dbslower mysql -p 480 -v # trace MySQL queries & print the BPF program
"""
parser = argparse.ArgumentParser(
description="",
Expand Down Expand Up @@ -134,4 +134,3 @@ def print_event(cpu, data, size):
bpf["events"].open_perf_buffer(print_event, page_cnt=64)
while True:
bpf.kprobe_poll()

4 changes: 2 additions & 2 deletions tools/dbstat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# This tool uses USDT probes, which means it needs MySQL and PostgreSQL built
# with USDT (DTrace) support.
#
# Copyright 2017, Sasha Goldshtein
# Copyright 2017, Sasha Goldshtein
# Licensed under the Apache License, Version 2.0
#
# 15-Feb-2017 Sasha Goldshtein Created this.
Expand Down Expand Up @@ -80,7 +80,7 @@
}
"""
program = program.replace("SCALE", str(1000 if args.microseconds else 1000000))
program = program.replace("FILTER", "" if args.threshold == 0 else \
program = program.replace("FILTER", "" if args.threshold == 0 else
"if (delta / 1000000 < %d) { return 0; }" % args.threshold)

usdts = map(lambda pid: USDT(pid=pid), args.pids)
Expand Down
5 changes: 3 additions & 2 deletions tools/old/memleak.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ def run_command_get_pid(command):
allocs.update(&address, &info);
if (SHOULD_PRINT) {
bpf_trace_printk("alloc exited, size = %lu, result = %lx, frames = %d\\n",
info.size, address, info.num_frames);
bpf_trace_printk("alloc exited, size = %lu, result = %lx,"
"frames = %d\\n", info.size, address,
info.num_frames);
}
return 0;
}
Expand Down
9 changes: 5 additions & 4 deletions tools/syscount.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
# cat syscallent.h | awk -F, '{ gsub(/[ \t"}]/, "", $4);
# gsub(/[ \t/*]/, "", $5);
# print " "$5": \""$4"\","; }
# BEGIN { print "syscalls = {" } END { print "}" }'
# BEGIN { print "syscalls = {" }
# END { print "}" }'
#
syscalls = {
0: "read",
Expand Down Expand Up @@ -459,7 +460,7 @@ def comm_for_pid(pid):

def agg_colval(key):
if args.process:
return "%-6d %-15s" % (key.value, comm_for_pid(key.value))
return "%-6d %-15s" % (key.value, comm_for_pid(key.value))
else:
return syscalls.get(key.value, "[unknown: %d]" % key.value)

Expand All @@ -478,7 +479,8 @@ def print_latency_stats():
data = bpf["data"]
print("[%s]" % strftime("%H:%M:%S"))
print("%-22s %8s %16s" % (agg_colname, "COUNT", time_colname))
for k, v in sorted(data.items(), key=lambda kv: -kv[1].total_ns)[:args.top]:
for k, v in sorted(data.items(),
key=lambda kv: -kv[1].total_ns)[:args.top]:
if k.value == 0xFFFFFFFF:
continue # happens occasionally, we don't need it
print(("%-22s %8d " + ("%16.6f" if args.milliseconds else "%16.3f")) %
Expand All @@ -497,4 +499,3 @@ def print_latency_stats():
if not args.interval:
print_stats()
break

4 changes: 2 additions & 2 deletions tools/tplist.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ def print_tracepoints():
def print_usdt_argument_details(location):
for idx in range(0, location.num_arguments):
arg = location.get_argument(idx)
print(" argument #%d %s" % (idx+1, arg))
print(" argument #%d %s" % (idx + 1, arg))

def print_usdt_details(probe):
if args.verbosity > 0:
print(probe)
if args.verbosity > 1:
for idx in range(0, probe.num_locations):
loc = probe.get_location(idx)
print(" location #%d %s" % (idx+1, loc))
print(" location #%d %s" % (idx + 1, loc))
print_usdt_argument_details(loc)
else:
print(" %d location(s)" % probe.num_locations)
Expand Down
6 changes: 4 additions & 2 deletions tools/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def __init__(self, probe, string_size, kernel_stack, user_stack):
self.probe_num = Probe.probe_count
self.probe_name = "probe_%s_%d" % \
(self._display_function(), self.probe_num)
self.probe_name = re.sub(r'[^A-Za-z0-9_]', '_', self.probe_name)
self.probe_name = re.sub(r'[^A-Za-z0-9_]', '_',
self.probe_name)

def __str__(self):
return "%s:%s:%s FLT=%s ACT=%s/%s" % (self.probe_type,
Expand Down Expand Up @@ -81,7 +82,8 @@ def _parse_probe(self):
text).groups()

self._parse_spec(spec)
self.signature = sig[1:-1] if sig else None # remove the parens
# Remove the parens
self.signature = sig[1:-1] if sig else None
if self.signature and self.probe_type in ['u', 't']:
self._bail("USDT and tracepoint probes can't have " +
"a function signature; use arg1, arg2, " +
Expand Down
7 changes: 4 additions & 3 deletions tools/ucalls.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ def get_data():
bpf["systimes"].items())
data.extend(syscalls)
else:
syscalls = map(lambda kv: (bpf.ksym(kv[0].value), (kv[1].value, 0)),
syscalls = map(lambda kv: (bpf.ksym(kv[0].value),
(kv[1].value, 0)),
bpf["syscounts"].items())
data.extend(syscalls)

Expand Down Expand Up @@ -294,8 +295,8 @@ def clear_data():
data = data[-args.top:]
for key, value in data:
if args.latency:
time = value[1]/1000000.0 if args.milliseconds else \
value[1]/1000.0
time = value[1] / 1000000.0 if args.milliseconds else \
value[1] / 1000.0
print("%-50s %8d %6.2f" % (key, value[0], time))
else:
print("%-50s %8d" % (key, value[0]))
Expand Down
2 changes: 1 addition & 1 deletion tools/uflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
def enable_probe(probe_name, func_name, read_class, read_method, is_return):
global program, trace_template, usdt
depth = "*depth + 1" if not is_return else "*depth | (1ULL << 63)"
update = "++(*depth);" if not is_return else "if (*depth) --(*depth);"
update = "++(*depth);" if not is_return else "if (*depth) --(*depth);"
filter_class = "if (!prefix_class(data.clazz)) { return 0; }" \
if args.clazz else ""
filter_method = "if (!prefix_method(data.method)) { return 0; }" \
Expand Down
18 changes: 11 additions & 7 deletions tools/ugc.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,10 @@ def format(self, data):
bpf_probe_read(&event.string1, sizeof(event.string1), (void *)manager);
bpf_probe_read(&event.string2, sizeof(event.string2), (void *)pool);
"""
formatter = lambda e: "%s %s used=%d->%d max=%d->%d" % \
(e.string1, e.string2, e.field1, e.field3, e.field2, e.field4)

def formatter(e):
"%s %s used=%d->%d max=%d->%d" % \
(e.string1, e.string2, e.field1, e.field3, e.field2, e.field4)
probes.append(Probe("mem__pool__gc__begin", "mem__pool__gc__end",
begin_save, end_save, formatter))
probes.append(Probe("gc__begin", "gc__end",
Expand All @@ -155,8 +157,10 @@ def format(self, data):
event.field1 = e->field1;
event.field2 = objs;
"""
formatter = lambda event: "gen %d GC collected %d objects" % \
(event.field1, event.field2)

def formatter(event):
"gen %d GC collected %d objects" % \
(event.field1, event.field2)
probes.append(Probe("gc__start", "gc__done",
begin_save, end_save, formatter))
#
Expand Down Expand Up @@ -214,10 +218,10 @@ class GCEvent(ct.Structure):

def print_event(cpu, data, size):
event = ct.cast(data, ct.POINTER(GCEvent)).contents
elapsed = event.elapsed_ns/1000000 if args.milliseconds else \
event.elapsed_ns/1000
elapsed = event.elapsed_ns / 1000000 if args.milliseconds else \
event.elapsed_ns / 1000
description = probes[event.probe_index].format(event)
if args.filter and not args.filter in description:
if args.filter and args.filter not in description:
return
print("%-8.3f %-8.2f %s" % (time.time() - start_ts, elapsed, description))

Expand Down
3 changes: 2 additions & 1 deletion tools/uobjnew.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
usdt.enable_probe_or_bail("object__create", "object_alloc_entry")
for thing in ["string", "hash", "array"]:
program += create_template.replace("THETHING", thing)
usdt.enable_probe_or_bail("%s__create" % thing, "%s_alloc_entry" % thing)
usdt.enable_probe_or_bail("%s__create" % thing,
"%s_alloc_entry" % thing)
#
# C
#
Expand Down
5 changes: 3 additions & 2 deletions tools/ustat.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,9 @@ def _loop_iter(self):
counts.update(probe.get_counts(self.bpf))
targets.update(probe.targets)
if self.args.sort:
counts = sorted(counts.items(), key=lambda kv:
-kv[1].get(self.args.sort.upper(), 0))
sort_field = self.args.sort.upper()
counts = sorted(counts.items(),
key=lambda kv: -kv[1].get(sort_field, 0))
else:
counts = sorted(counts.items(), key=lambda kv: kv[0])
for pid, stats in counts:
Expand Down

0 comments on commit 956ca1c

Please sign in to comment.