Skip to content

Commit

Permalink
sof_perf_analyzer: fix exception when kernel message not provided
Browse files Browse the repository at this point in the history
If kernel message file is not provided, the component_name
dict will be empty, in calculating the maximum length of
component names, we calls the max function with an empty
sequence, which raises below error:
    "ValueError: max() arg is an empty sequence"

This patch checks if component_name dict is empty, and on
empty, provides a default value.

Signed-off-by: Chao Song <chao.song@linux.intel.com>
  • Loading branch information
Chao Song committed Oct 12, 2023
1 parent e3d7664 commit 82b93fd
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tools/sof_perf_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,10 @@ def format_perf_info() -> list[str] | None:
'''Format SOF trace performance statistics'''
if len(perf_stats):
lines: list[str] = []
max_name_len = max(len(name) for name in component_name.values())
if args.kmsg:
max_name_len = max(len(name) for name in component_name.values())
else:
max_name_len = len('COMP_NAME') # The length of the first column title
name_fmt = '{:>' + f'{max_name_len}' + '},'
title_fmt = name_fmt + ' {:>10}, {:>12}, {:>12}, {:>12},'
title_fmt = title_fmt + ' {:>13}, {:>13}, {:>13}, {:>18}'
Expand Down

0 comments on commit 82b93fd

Please sign in to comment.