From 47855301517ce26070dd24745e0c3bdaa3b9c872 Mon Sep 17 00:00:00 2001 From: Chao Song Date: Wed, 6 Sep 2023 13:45:37 +0800 Subject: [PATCH 1/3] sof_perf_analyzer: add skip-to-first-trace option In CI test, some traces from previous test case will apprear in the mtrace of current test case, this is a know issue. Previously, we always skip to the first valid trace of this test case, this could raise trouble for developer use of this script. This patch adds skip-to-first-trace option, for CI test, this option should be set (True), and for developer use, this option should be left as it is (False). Signed-off-by: Chao Song --- tools/sof_perf_analyzer.py | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/tools/sof_perf_analyzer.py b/tools/sof_perf_analyzer.py index 2ea231d3..4641503f 100755 --- a/tools/sof_perf_analyzer.py +++ b/tools/sof_perf_analyzer.py @@ -120,15 +120,11 @@ def skip_to_first_trace(trace_item_gen: TraceItemGenerator) -> Optional[TraceIte 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: @@ -169,9 +165,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 @@ -295,6 +297,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() From f25183d5446a11d9629f48fb7e40ba1c205870c9 Mon Sep 17 00:00:00 2001 From: Chao Song Date: Thu, 7 Sep 2023 11:07:17 +0800 Subject: [PATCH 2/3] lib.sh: set skip-to-first-trace option for CI test Due to a known issue in CI test, some traces from previous test case will apprear in the mtrace of current test case. Set skip-to-first-trace option to skip those traces. Signed-off-by: Chao Song --- case-lib/lib.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/case-lib/lib.sh b/case-lib/lib.sh index 09ed78c1..4875569d 100644 --- a/case-lib/lib.sh +++ b/case-lib/lib.sh @@ -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" || { From ddde86717378d4120dd477f4a620fbbf34086394 Mon Sep 17 00:00:00 2001 From: Chao Song Date: Thu, 7 Sep 2023 11:18:19 +0800 Subject: [PATCH 3/3] sof_perf_analyzer: remove type annotation for skip_to_first_trace() The skip_to_first_trace() function either return a value or raise an exception. Currently there is no good way to do type annotation for such function, so remove its type annotation. Signed-off-by: Chao Song --- tools/sof_perf_analyzer.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tools/sof_perf_analyzer.py b/tools/sof_perf_analyzer.py index 4641503f..33703d56 100755 --- a/tools/sof_perf_analyzer.py +++ b/tools/sof_perf_analyzer.py @@ -26,7 +26,6 @@ import pathlib import argparse from typing import TextIO -from typing import Optional from typing import Generator from dataclasses import dataclass @@ -115,7 +114,7 @@ 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.