Skip to content

Commit e06f756

Browse files
committed
fix: tools: make faulty mtrace lines not exit script
In case of a faulty line in mtrace, the sof_perf_analyzer.py script will log a warning and move on, instead of failing. Signed-off-by: Emilia Kurdybelska <emiliax.kurdybelska@intel.com>
1 parent 0ed9b0b commit e06f756

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

tools/sof_perf_analyzer.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,21 @@ def skip_to_first_trace(trace_item_gen: TraceItemGenerator):
109109
return item
110110
return next(trace_item_gen)
111111

112+
def get_timestamp_from_line(line, span_end_pos):
113+
try:
114+
timestamp = float(line[span_end_pos - 19: span_end_pos - 7].strip())
115+
# Support for CONFIG_LOG_OUTPUT_FORMAT_TIME_TIMESTAMP - For when default Zephyr timestamp format is used
116+
except ValueError:
117+
h, m, rest = line[span_end_pos - 23: span_end_pos - 7].strip().split(':')
118+
s1, s2 = rest.split(',')
119+
s = s1+s2
120+
timestamp = timedelta(
121+
hours=int(h),
122+
minutes=int(m),
123+
seconds=float(s)
124+
).total_seconds()
125+
return timestamp
126+
112127
def make_trace_item(fileio: TextIO) -> TraceItemGenerator:
113128
'''Filter and parse a line of trace in string form into TraceItem object, for example:
114129
'[ 2.566046] <inf> component: comp_copy: comp:0 0x40000 perf comp_copy samples
@@ -134,26 +149,18 @@ def make_trace_item(fileio: TextIO) -> TraceItemGenerator:
134149
# second trace from the line. This is done by regarding the end position
135150
# of the matched substring as sentinel, timestamp and trace level are
136151
# both some specific offset from the sentinel.
137-
span_end_pos = match_obj.span()[1]
138-
trace_lvl = line[span_end_pos - 4: span_end_pos - 1]
139152
try:
140-
timestamp = float(line[span_end_pos - 19: span_end_pos - 7].strip())
141-
# Support for CONFIG_LOG_OUTPUT_FORMAT_TIME_TIMESTAMP - For when default Zephyr timestamp format is used
142-
except ValueError:
143-
h, m, rest = line[span_end_pos - 23: span_end_pos - 7].strip().split(':')
144-
s1, s2 = rest.split(',')
145-
s = s1+s2
146-
timestamp = timedelta(
147-
hours=int(h),
148-
minutes=int(m),
149-
seconds=float(s)
150-
).total_seconds()
151-
152-
# The rest after removing timestamp and log level
153-
rest = line[span_end_pos + 1:].split(': ')
154-
ctx, func = rest[0:2]
155-
msg = ': '.join(rest[2:]).strip()
156-
yield TraceItem(timestamp, trace_lvl, ctx, func, msg)
153+
span_end_pos = match_obj.span()[1]
154+
trace_lvl = line[span_end_pos - 4: span_end_pos - 1]
155+
timestamp = get_timestamp_from_line(line, span_end_pos)
156+
157+
# The rest after removing timestamp and log level
158+
rest = line[span_end_pos + 1:].split(': ')
159+
ctx, func = rest[0:2]
160+
msg = ': '.join(rest[2:]).strip()
161+
yield TraceItem(timestamp, trace_lvl, ctx, func, msg)
162+
except Exception as e: # pylint: disable=W0718
163+
print(f"WARNING: Couldn't parse line: {line}, error: {e}")
157164

158165
def process_trace_file():
159166
'''The top-level caller for processing the trace file'''

0 commit comments

Comments
 (0)