Commit aaca976c authored by Teng Qin's avatar Teng Qin Committed by yonghong-song

Misc fixes on Python tools (#2136)

Misc fixes on Python tools
parent 6a0a7918
......@@ -53,7 +53,7 @@ loadavg = "/proc/loadavg"
diskstats = "/proc/diskstats"
# signal handler
def signal_ignore(signal, frame):
def signal_ignore(signal_value, frame):
print()
# load BPF program
......
......@@ -40,7 +40,7 @@ FIELDS = (
"WRITE_HIT%"
)
DEFAULT_FIELD = "HITS"
DEFAULT_SORT_FIELD = FIELDS.index(DEFAULT_FIELD)
# signal handler
def signal_ignore(signal, frame):
......@@ -61,7 +61,7 @@ def get_meminfo():
def get_processes_stats(
bpf,
sort_field=FIELDS.index(DEFAULT_FIELD),
sort_field=DEFAULT_SORT_FIELD,
sort_reverse=False):
'''
Return a tuple containing:
......@@ -223,7 +223,7 @@ def handle_loop(stdscr, args):
uid = int(stat[1])
try:
username = pwd.getpwuid(uid)[0]
except KeyError as ex:
except KeyError:
# `pwd` throws a KeyError if the user cannot be found. This can
# happen e.g. when the process is running in a cgroup that has
# different users from the host.
......
......@@ -319,7 +319,7 @@ def print_event(cpu, data, size):
print("NO STACK FOUND DUE TO COLLISION")
print("===================================")
print("")
except:
except Exception:
sys.exit(0)
b["events"].open_perf_buffer(print_event, page_cnt=256)
......
......@@ -205,7 +205,7 @@ b.attach_kretprobe(event="__vfs_read", fn_name="trace_read_return")
try:
b.attach_kprobe(event="__vfs_write", fn_name="trace_write_entry")
b.attach_kretprobe(event="__vfs_write", fn_name="trace_write_return")
except:
except Exception:
# older kernels don't have __vfs_write so try vfs_write instead
b.attach_kprobe(event="vfs_write", fn_name="trace_write_entry")
b.attach_kretprobe(event="vfs_write", fn_name="trace_write_return")
......
......@@ -60,7 +60,7 @@ debug = 0
loadavg = "/proc/loadavg"
# signal handler
def signal_ignore(signal, frame):
def signal_ignore(signal_value, frame):
print()
# define BPF program
......
......@@ -48,8 +48,8 @@ CPU PID TID TIME(us) METHOD
3 27722 27731 3.144 <- java/lang/ThreadGroup.checkAccess
3 27722 27731 3.144 -> java/lang/ThreadGroup.addUnstarted
3 27722 27731 3.144 <- java/lang/ThreadGroup.addUnstarted
3 27722 27731 3.145 -> java/lang/Thread.isDaemon
3 27722 27731 3.145 <- java/lang/Thread.isDaemon
3 27722 27731 3.145 -> java/lang/Thread.isDaemon
3 27722 27731 3.145 <- java/lang/Thread.isDaemon
3 27722 27731 3.145 -> java/lang/Thread.getPriority
3 27722 27731 3.145 <- java/lang/Thread.getPriority
3 27722 27731 3.145 -> java/lang/Thread.getContextClassLoader
......
......@@ -85,7 +85,7 @@ try:
b.attach_perf_event(
ev_type=PerfType.HARDWARE, ev_config=PerfHWConfig.CACHE_REFERENCES,
fn_name="on_cache_ref", sample_period=args.sample_period)
except:
except Exception:
print("Failed to attach to a hardware event. Is this a virtual machine?")
exit()
......
......@@ -218,7 +218,7 @@ if min_us == 0:
else:
bpf_text = bpf_text.replace('FILTER_US', 'delta_us <= %s' % str(min_us))
if args.pid:
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % pid)
bpf_text = bpf_text.replace('FILTER_PID', 'pid != %s' % args.pid)
else:
bpf_text = bpf_text.replace('FILTER_PID', '0')
if debug or args.ebpf:
......
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