Commit 2a01f7c9 authored by Brenden Blanco's avatar Brenden Blanco

Suppress None return when trace_pipe drops lines

* When a "CPU: X Lost N events" line came on the trace_pipe,
  trace_fields would return None and cause exceptions in callers that do
  (a, b, ...) = b.trace_fields() type of calls. Instead, keep reading
  from trace_pipe when such messages come.

Fixes: #187
Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 79553c20
...@@ -546,10 +546,11 @@ class BPF(object): ...@@ -546,10 +546,11 @@ 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)
""" """
line = BPF.trace_readline(nonblocking) while True:
if line: line = BPF.trace_readline(nonblocking)
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("CPU:"): return if line.startswith("CPU:"): continue
task = line[:16].lstrip() task = line[:16].lstrip()
line = line[17:] line = line[17:]
ts_end = line.find(":") ts_end = line.find(":")
...@@ -557,7 +558,6 @@ class BPF(object): ...@@ -557,7 +558,6 @@ class BPF(object):
cpu = cpu[1:-1] cpu = cpu[1:-1]
msg = line[ts_end + 4:] msg = line[ts_end + 4:]
return (task, int(pid), int(cpu), flags, float(ts), msg) return (task, int(pid), int(cpu), flags, float(ts), msg)
return
@staticmethod @staticmethod
def trace_readline(nonblocking=False): def trace_readline(nonblocking=False):
......
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