Skip to contentSkip to conversation

perf sort: Segmentation fault of basic block cycles sort dimension

PATCH Applied [email protected] 3 participants 3 messages Mar 13, 2017 – Mar 15, 2017 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf sort: Segmentation fault of basic block cycles sort dimension

From: Changbin Du <[email protected]>

Skip the sample which doesn't have branch_info to avoid segmentation fault occurrence.

The fault can be reproduced by:
perf record -a
perf report -F cycles

---
 tools/perf/util/sort.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/perf/util/sort.c +5 -0
index 0ff6222..b6db140 100644
@@ -846,6 +846,9 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf,
 static int64_t
 sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
 {
+	if (!left->branch_info || !right->branch_info)
+		return cmp_null(left->branch_info, right->branch_info);
+
 	return left->branch_info->flags.cycles -
 		right->branch_info->flags.cycles;
 }
@@ -853,6 +856,8 @@ sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
 static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf,
 				    size_t size, unsigned int width)
 {
+	if (!he->branch_info)
+		return scnprintf(bf, size, "%-.*s", width, "N/A");
 	if (he->branch_info->flags.cycles == 0)
 		return repsep_snprintf(bf, size, "%-*s", width, "-");
 	return repsep_snprintf(bf, size, "%-*hd", width,
Signature · 1 line
2.7.4
maintainer Applied
#1 lore raw

Em Mon, Mar 13, 2017 at 04:31:48PM +0800, [email protected] escreveu:

Quoted 8 lines

From: Changbin Du <[email protected]>

Skip the sample which doesn't have branch_info to avoid segmentation fault occurrence.

The fault can be reproduced by:
perf record -a
perf report -F cycles

Thanks, applied.

- Arnaldo

Quoted 30 lines
---
 tools/perf/util/sort.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/perf/util/sort.c +5 -0
index 0ff6222..b6db140 100644
@@ -846,6 +846,9 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf,
 static int64_t
 sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
 {
+	if (!left->branch_info || !right->branch_info)
+		return cmp_null(left->branch_info, right->branch_info);
+
 	return left->branch_info->flags.cycles -
 		right->branch_info->flags.cycles;
 }
@@ -853,6 +856,8 @@ sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
 static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf,
 				    size_t size, unsigned int width)
 {
+	if (!he->branch_info)
+		return scnprintf(bf, size, "%-.*s", width, "N/A");
 	if (he->branch_info->flags.cycles == 0)
 		return repsep_snprintf(bf, size, "%-*s", width, "-");
 	return repsep_snprintf(bf, size, "%-*hd", width,
Signature · 1 line
2.7.4
#2 lore raw

[tip:perf/core] perf sort: Fix segfault with basic block 'cycles' sort dimension

In reply to [email protected]
perf sort: Fix segfault with basic block 'cycles' sort dimension
Commit-ID:  4b0b3aa6a2756e6115fdf275c521e4552a7082f3
Gitweb:     http://git.kernel.org/tip/4b0b3aa6a2756e6115fdf275c521e4552a7082f3
Author:     Changbin Du <[email protected]>
AuthorDate: Mon, 13 Mar 2017 16:31:48 +0800
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 13 Mar 2017 11:41:20 -0300

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

Cc Andi Kleen <[email protected]>
Cc Peter Zijlstra <[email protected]>
Fixes 0e332f033a82 ("perf tools: Add support for cycles, weight branch_info field")
---
 tools/perf/util/sort.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/perf/util/sort.c +5 -0
index f8f16c0..93f755a 100644
@@ -846,6 +846,9 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf,
 static int64_t
 sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
 {
+	if (!left->branch_info || !right->branch_info)
+		return cmp_null(left->branch_info, right->branch_info);
+
 	return left->branch_info->flags.cycles -
 		right->branch_info->flags.cycles;
 }
@@ -853,6 +856,8 @@ sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
 static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf,
 				    size_t size, unsigned int width)
 {
+	if (!he->branch_info)
+		return scnprintf(bf, size, "%-.*s", width, "N/A");
 	if (he->branch_info->flags.cycles == 0)
 		return repsep_snprintf(bf, size, "%-*s", width, "-");
 	return repsep_snprintf(bf, size, "%-*hd", width,