Commit ee9f0e0a authored by Daniel Zozin's avatar Daniel Zozin Committed by yonghong-song

Remove handling of KeyboardInterrupt exception (#1843)

KeyboardInterrupt exception is not handled anymore. It will be
propagated and handled by the caller.
parent 365eade7
...@@ -1041,30 +1041,27 @@ class BPF(object): ...@@ -1041,30 +1041,27 @@ class BPF(object):
fields (task, pid, cpu, flags, timestamp, msg) or None if no fields (task, pid, cpu, flags, timestamp, msg) or None if no
line was read (nonblocking=True) line was read (nonblocking=True)
""" """
try: while True:
while True: line = self.trace_readline(nonblocking)
line = self.trace_readline(nonblocking) if not line and nonblocking: return (None,) * 6
if not line and nonblocking: return (None,) * 6 # don't print messages related to lost events
# don't print messages related to lost events if line.startswith(b"CPU:"): continue
if line.startswith(b"CPU:"): continue task = line[:16].lstrip()
task = line[:16].lstrip() line = line[17:]
line = line[17:] ts_end = line.find(b":")
ts_end = line.find(b":") pid, cpu, flags, ts = line[:ts_end].split()
pid, cpu, flags, ts = line[:ts_end].split() cpu = cpu[1:-1]
cpu = cpu[1:-1] # line[ts_end:] will have ": [sym_or_addr]: msgs"
# line[ts_end:] will have ": [sym_or_addr]: msgs" # For trace_pipe debug output, the addr typically
# For trace_pipe debug output, the addr typically # is invalid (e.g., 0x1). For kernel 4.12 or earlier,
# is invalid (e.g., 0x1). For kernel 4.12 or earlier, # if address is not able to match a kernel symbol,
# if address is not able to match a kernel symbol, # nothing will be printed out. For kernel 4.13 and later,
# nothing will be printed out. For kernel 4.13 and later, # however, the illegal address will be printed out.
# however, the illegal address will be printed out. # Hence, both cases are handled here.
# Hence, both cases are handled here. line = line[ts_end + 1:]
line = line[ts_end + 1:] sym_end = line.find(b":")
sym_end = line.find(b":") msg = line[sym_end + 2:]
msg = line[sym_end + 2:] return (task, int(pid), int(cpu), flags, float(ts), msg)
return (task, int(pid), int(cpu), flags, float(ts), msg)
except KeyboardInterrupt:
exit()
def trace_readline(self, nonblocking=False): def trace_readline(self, nonblocking=False):
"""trace_readline(nonblocking=False) """trace_readline(nonblocking=False)
...@@ -1080,8 +1077,6 @@ class BPF(object): ...@@ -1080,8 +1077,6 @@ class BPF(object):
line = trace.readline(1024).rstrip() line = trace.readline(1024).rstrip()
except IOError: except IOError:
pass pass
except KeyboardInterrupt:
exit()
return line return line
def trace_print(self, fmt=None): def trace_print(self, fmt=None):
...@@ -1093,18 +1088,15 @@ class BPF(object): ...@@ -1093,18 +1088,15 @@ class BPF(object):
example: trace_print(fmt="pid {1}, msg = {5}") example: trace_print(fmt="pid {1}, msg = {5}")
""" """
try: while True:
while True: if fmt:
if fmt: fields = self.trace_fields(nonblocking=False)
fields = self.trace_fields(nonblocking=False) if not fields: continue
if not fields: continue line = fmt.format(*fields)
line = fmt.format(*fields) else:
else: line = self.trace_readline(nonblocking=False)
line = self.trace_readline(nonblocking=False) print(line)
print(line) sys.stdout.flush()
sys.stdout.flush()
except KeyboardInterrupt:
exit()
@staticmethod @staticmethod
def _sym_cache(pid): def _sym_cache(pid):
...@@ -1194,13 +1186,10 @@ class BPF(object): ...@@ -1194,13 +1186,10 @@ class BPF(object):
Poll from all open perf ring buffers, calling the callback that was Poll from all open perf ring buffers, calling the callback that was
provided when calling open_perf_buffer for each entry. provided when calling open_perf_buffer for each entry.
""" """
try: readers = (ct.c_void_p * len(self.perf_buffers))()
readers = (ct.c_void_p * len(self.perf_buffers))() for i, v in enumerate(self.perf_buffers.values()):
for i, v in enumerate(self.perf_buffers.values()): readers[i] = v
readers[i] = v lib.perf_reader_poll(len(readers), readers, timeout)
lib.perf_reader_poll(len(readers), readers, timeout)
except KeyboardInterrupt:
exit()
def kprobe_poll(self, timeout = -1): def kprobe_poll(self, timeout = -1):
"""kprobe_poll(self) """kprobe_poll(self)
......
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