From b84f97a9027604de0ac8a9abfbf5806c0c546d88 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Tue, 12 Jan 2016 10:12:00 +0000 Subject: [PATCH] trace_cmd: updated to handle empty CPUs. Updated trace-cmd parser to handle messages that the trace for a CPU is empty. --- wlauto/utils/trace_cmd.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/wlauto/utils/trace_cmd.py b/wlauto/utils/trace_cmd.py index 50a5aac7..68110276 100644 --- a/wlauto/utils/trace_cmd.py +++ b/wlauto/utils/trace_cmd.py @@ -196,13 +196,15 @@ HEADER_REGEX = re.compile(r'^\s*(?:version|cpus)\s*=\s*([\d.]+)\s*$') DROPPED_EVENTS_REGEX = re.compile(r'CPU:(?P\d+) \[\d*\s*EVENTS DROPPED\]') +EMPTY_CPU_REGEX = re.compile(r'CPU \d+ is empty') + class TraceCmdTrace(object): def __init__(self, filter_markers=True): self.filter_markers = filter_markers - def parse(self, filepath, names=None, check_for_markers=True): # pylint: disable=too-many-branches + def parse(self, filepath, names=None, check_for_markers=True): # pylint: disable=too-many-branches,too-many-locals """ This is a generator for the trace event stream. @@ -217,6 +219,7 @@ class TraceCmdTrace(object): else: # maker not found force filtering by marker to False self.filter_markers = False + with open(filepath) as fh: for line in fh: # if processing trace markers, skip marker lines as well as all @@ -235,9 +238,14 @@ class TraceCmdTrace(object): yield DroppedEventsEvent(match.group('cpu_id')) continue - match = HEADER_REGEX.search(line) - if match: - logger.debug(line.strip()) + matched = False + for rx in [HEADER_REGEX, EMPTY_CPU_REGEX]: + match = rx.search(line) + if match: + logger.debug(line.strip()) + matched = True + break + if matched: continue match = TRACE_EVENT_REGEX.search(line)