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