Skip to content

Commit 4b0b3aa

Browse files
Changbin Duacmel
authored andcommitted
perf sort: Fix segfault with basic block 'cycles' sort dimension
Skip the sample which doesn't have branch_info to avoid segmentation fault: The fault can be reproduced by: perf record -a perf report -F cycles Signed-off-by: Changbin Du <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Peter Zijlstra <[email protected]> Fixes: 0e332f0 ("perf tools: Add support for cycles, weight branch_info field") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 12a601c commit 4b0b3aa

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tools/perf/util/sort.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,13 +846,18 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf,
846846
static int64_t
847847
sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
848848
{
849+
if (!left->branch_info || !right->branch_info)
850+
return cmp_null(left->branch_info, right->branch_info);
851+
849852
return left->branch_info->flags.cycles -
850853
right->branch_info->flags.cycles;
851854
}
852855

853856
static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf,
854857
size_t size, unsigned int width)
855858
{
859+
if (!he->branch_info)
860+
return scnprintf(bf, size, "%-.*s", width, "N/A");
856861
if (he->branch_info->flags.cycles == 0)
857862
return repsep_snprintf(bf, size, "%-*s", width, "-");
858863
return repsep_snprintf(bf, size, "%-*hd", width,

0 commit comments

Comments
 (0)