Re: [PATCH 16/35] perf annotate: Add samples into struct annotation_line

From: Ravi Bangoria
Date: Mon Nov 13 2017 - 10:46:23 EST


Hi Jiri,

This patch seems to be causing segfault with "perf top --stdio".

Steps to reproduce:
1. start "perf top --stdio" in one terminal
2. run some simple workload in another terminal, let it get finished.
3. annotate function from previous workload in perf top (press 'a' followed by 's')

Perf will crash with:

 perf: Segmentation fault
 Obtained 8 stack frames.
 ./perf(sighandler_dump_stack+0x3e) [0x4f1b6e]
 /lib64/libc.so.6(+0x36a7f) [0x7ff3aa7e4a7f]
 ./perf() [0x4a27fd]
 ./perf(symbol__annotate+0x199) [0x4a4439]
 ./perf() [0x44e32d]
 ./perf() [0x44f098]
 /lib64/libpthread.so.0(+0x736c) [0x7ff3acee836c]
 /lib64/libc.so.6(clone+0x3e) [0x7ff3aa8bee1e]

Can you please check.

Thanks,
Ravi


On 10/11/2017 08:31 PM, Jiri Olsa wrote:
Adding samples array into struct annotation_line to
hold the annotation data. The data are populated in
the following patches.

Link: http://lkml.kernel.org/n/tip-97yja5m7z9brrcuf2gwr56t2@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/util/annotate.c | 8 ++++++++
tools/perf/util/annotate.h | 17 ++++++++++++-----
2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/annotate.c b/tools/perf/util/annotate.c
index 8e1e88aab45a..1b5c7d0a53e8 100644
--- a/tools/perf/util/annotate.c
+++ b/tools/perf/util/annotate.c
@@ -901,7 +901,14 @@ static struct annotation_line*
annotation_line__new(struct annotate_args *args, size_t privsize)
{
struct annotation_line *al;
+ struct perf_evsel *evsel = args->evsel;
size_t size = privsize + sizeof(*al);
+ int nr = 1;
+
+ if (perf_evsel__is_group_event(evsel))
+ nr = evsel->nr_members;
+
+ size += sizeof(al->samples[0]) * nr;

al = zalloc(size);
if (al) {
@@ -910,6 +917,7 @@ annotation_line__new(struct annotate_args *args, size_t privsize)
al->offset = args->offset;
al->line = strdup(args->line);
al->line_nr = args->line_nr;
+ al->samples_nr = nr;
}

return al;
diff --git a/tools/perf/util/annotate.h b/tools/perf/util/annotate.h
index a02a2bf4f2ab..9c722a7e5f6d 100644
--- a/tools/perf/util/annotate.h
+++ b/tools/perf/util/annotate.h
@@ -58,6 +58,16 @@ bool ins__is_fused(struct arch *arch, const char *ins1, const char *ins2);

struct annotation;

+struct sym_hist_entry {
+ u64 nr_samples;
+ u64 period;
+};
+
+struct annotation_data {
+ double percent;
+ struct sym_hist_entry he;
+};
+
struct annotation_line {
struct list_head node;
struct rb_node rb_node;
@@ -67,6 +77,8 @@ struct annotation_line {
float ipc;
u64 cycles;
size_t privsize;
+ int samples_nr;
+ struct annotation_data samples[0];
};

struct disasm_line {
@@ -87,11 +99,6 @@ static inline bool disasm_line__has_offset(const struct disasm_line *dl)
return dl->ops.target.offset_avail;
}

-struct sym_hist_entry {
- u64 nr_samples;
- u64 period;
-};
-
void disasm_line__free(struct disasm_line *dl);
struct annotation_line*
annotation_line__next(struct annotation_line *pos, struct list_head *head);