Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sof_perf_analyzer: add skip-to-first-trace option #1100

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions case-lib/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -901,9 +901,9 @@ perf_analyze()
dlogi "Checking SOF component performance"
if [ -e "$LOG_ROOT/mtrace.txt" ]; then
if [ -e "$LOG_ROOT/dmesg.txt" ]; then
perf_cmd="sof_perf_analyzer.py --kmsg=$LOG_ROOT/dmesg.txt --out2csv $LOG_ROOT/sof_perf.txt $LOG_ROOT/mtrace.txt "
perf_cmd="sof_perf_analyzer.py --skip-to-first-trace --kmsg=$LOG_ROOT/dmesg.txt --out2csv $LOG_ROOT/sof_perf.txt $LOG_ROOT/mtrace.txt"
else
perf_cmd="sof_perf_analyzer.py --out2csv $LOG_ROOT/sof_perf.txt $LOG_ROOT/mtrace.txt"
perf_cmd="sof_perf_analyzer.py --skip-to-first-trace --out2csv $LOG_ROOT/sof_perf.txt $LOG_ROOT/mtrace.txt"
fi
dlogc "$perf_cmd"
eval "$perf_cmd" || {
Expand Down
34 changes: 20 additions & 14 deletions tools/sof_perf_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import pathlib
import argparse
from typing import TextIO
from typing import Optional
from typing import Generator
from dataclasses import dataclass

Expand Down Expand Up @@ -115,20 +114,16 @@ def dispatch_trace_item(trace_item: TraceItem):
if trace_item.func == 'comp_copy':
collect_perf_info(trace_item)

def skip_to_first_trace(trace_item_gen: TraceItemGenerator) -> Optional[TraceItem]:
def skip_to_first_trace(trace_item_gen: TraceItemGenerator):
'''The current sof-test test case may collect some traces belonging to previous
test case due to mtrace is configured in deferred mode. This function consumes
those traces from the generator, and return the first trace item of current test.
'''
try:
while item := next(trace_item_gen):
# On test running, the SOF firmware is reloaded to DSP, timer is reset to 0.
# The first trace must have a timestamp with integral part equals to 0.
if int(item.timestamp) == 0:
return item
except StopIteration:
return None
return None
while item := next(trace_item_gen):
# On test running, the SOF firmware is reloaded to DSP, timer is reset to 0.
# The first trace must have a timestamp with integral part equals to 0.
if int(item.timestamp) == 0:
return item

def make_trace_item(fileio: TextIO) -> TraceItemGenerator:
'''Filter and parse a line of trace in string form into TraceItem object, for example:
Expand Down Expand Up @@ -169,9 +164,15 @@ def process_trace_file():
'''The top-level caller for processing the trace file'''
with open(args.filename, 'r', encoding='utf8') as file:
trace_item_gen = make_trace_item(file)
trace_prev = skip_to_first_trace(trace_item_gen)
if trace_prev is None:
raise Exception('No valid trace in provided file')
trace_prev = None
try:
if args.skip_to_first_trace:
trace_prev = skip_to_first_trace(trace_item_gen)
else:
trace_prev = next(trace_item_gen)
except StopIteration as si:
si.args = ('No valid trace in provided file',)
raise
for trace_curr in trace_item_gen:
# pylint: disable=W0603
global ts_shift
Expand Down Expand Up @@ -295,6 +296,11 @@ def parse_args():
help='Kernel message file captured with journalctl or other log utility')
parser.add_argument('--out2csv', type=pathlib.Path, required=False,
help='Output SOF performance statistics to csv file')
parser.add_argument('-s', '--skip-to-first-trace', action="store_true", default=False,
help='''In CI test, some traces from previous test case will appear in
the mtrace of current test case, this flag is used to denote if we
want to skip until the first line with a timestamp between 0 and 1s.
For CI test, set the flag to True''')

return parser.parse_args()

Expand Down
Loading