Commit 3dfaf983 authored by 4ast's avatar 4ast

Merge pull request #262 from iovisor/bblanco_dev

Make KeyboardInterrupt catch more aggressive
parents 0b904997 d0c31819
...@@ -653,18 +653,21 @@ class BPF(object): ...@@ -653,18 +653,21 @@ 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)
""" """
while True: try:
line = self.trace_readline(nonblocking) while True:
if not line and nonblocking: return (None,) * 6 line = self.trace_readline(nonblocking)
# don't print messages related to lost events if not line and nonblocking: return (None,) * 6
if line.startswith("CPU:"): continue # don't print messages related to lost events
task = line[:16].lstrip() if line.startswith("CPU:"): continue
line = line[17:] task = line[:16].lstrip()
ts_end = line.find(":") line = line[17:]
pid, cpu, flags, ts = line[:ts_end].split() ts_end = line.find(":")
cpu = cpu[1:-1] pid, cpu, flags, ts = line[:ts_end].split()
msg = line[ts_end + 4:] cpu = cpu[1:-1]
return (task, int(pid), int(cpu), flags, float(ts), msg) msg = line[ts_end + 4:]
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)
...@@ -693,15 +696,18 @@ class BPF(object): ...@@ -693,15 +696,18 @@ class BPF(object):
example: trace_print(fmt="pid {1}, msg = {5}") example: trace_print(fmt="pid {1}, msg = {5}")
""" """
while True: try:
if fmt: while True:
fields = self.trace_fields(nonblocking=False) if fmt:
if not fields: continue fields = self.trace_fields(nonblocking=False)
line = fmt.format(*fields) if not fields: continue
else: line = fmt.format(*fields)
line = self.trace_readline(nonblocking=False) else:
print(line) line = self.trace_readline(nonblocking=False)
sys.stdout.flush() print(line)
sys.stdout.flush()
except KeyboardInterrupt:
exit()
@staticmethod @staticmethod
def _load_kallsyms(): def _load_kallsyms():
......
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