perf annotate: Misc fixes / improvements
cover perf annotate: Misc fixes / improvements
Few fixes / improvements related to perf annotate.
Ravi Bangoria (3):
perf annotate: Nuke privsize
perf annotate: Align struct annotate_args
perf annotate: Fix segfault with source toggle
tools/perf/builtin-top.c | 2 +- tools/perf/ui/gtk/annotate.c | 2 +- tools/perf/util/annotate.c | 106 +++++++++++++---------------------- tools/perf/util/annotate.h | 3 +- 4 files changed, 43 insertions(+), 70 deletions(-)
Signature · 1 line
2.24.1
PATCH 1/3 perf annotate: Nuke privsize
We don't use privsize now and it's always 0. Remove privsize from code. Also simplify disasm_line allocation and freeing code which was bit complex because of privsize.
--- tools/perf/builtin-top.c | 2 +- tools/perf/ui/gtk/annotate.c | 2 +- tools/perf/util/annotate.c | 92 +++++++++++++----------------------- tools/perf/util/annotate.h | 3 +- 4 files changed, 35 insertions(+), 64 deletions(-)
tools/perf/builtin-top.c +1 -1
@@ -143,7 +143,7 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)return err; } - err =symbol__annotate (&he->ms, evsel,0 , &top->annotation_opts,NULL ); + err =symbol__annotate (&he->ms, evsel, &top->annotation_opts,NULL );if (err ==0 ) { top->sym_filter_entry = he; }else {
tools/perf/ui/gtk/annotate.c +1 -1
@@ -174,7 +174,7 @@ static int symbol__gtk_annotate(struct map_symbol *ms, struct evsel *evsel,if (ms->map->dso->annotate_warned)return -1 ; - err =symbol__annotate (ms, evsel,0 , &annotation__default_options,NULL ); + err =symbol__annotate (ms, evsel, &annotation__default_options,NULL );if (err) {char msg[BUFSIZ ];symbol__strerror_disassemble (ms, err, msg,sizeof (msg));
tools/perf/util/annotate.c +32 -60
156 lines not on this page · raw message
tools/perf/util/annotate.h +1 -2
@@ -139,7 +139,6 @@ struct annotation_line {u64 cycles;u64 cycles_max;u64 cycles_min; -size_t privsize;char *path;u32 idx;int idx_asm;
@@ -350,7 +349,7 @@ struct annotated_source *symbol__hists(struct symbol *sym, int nr_hists);void symbol__annotate_zero_histograms (struct symbol *sym);int symbol__annotate (struct map_symbol *ms, -struct evsel *evsel,size_t privsize, +struct evsel *evsel,struct annotation_options *options,struct arch **parch); int symbol__annotate2(struct map_symbol *ms,
Signature · 1 line
2.24.1
Re: [PATCH 1/3] perf annotate: Nuke privsize
Quoted 75 lines · Ravi Bangoria
We don't use privsize now and it's always 0. Remove privsize from code. Also simplify
disasm_lineallocation and freeing code which was bit complex because of privsize.Signed-off-by Ravi Bangoria <[email protected]>--- tools/perf/builtin-top.c | 2 +- tools/perf/ui/gtk/annotate.c | 2 +- tools/perf/util/annotate.c | 92 +++++++++++++----------------------- tools/perf/util/annotate.h | 3 +- 4 files changed, 35 insertions(+), 64 deletions(-)tools/perf/builtin-top.c +1
-1@@ -143,7 +143,7 @@ static int perf_top__parse_source(struct perf_top *top, struct hist_entry *he)return err; } - err =symbol__annotate (&he->ms, evsel,0 , &top->annotation_opts,NULL ); + err =symbol__annotate (&he->ms, evsel, &top->annotation_opts,NULL );if (err ==0 ) { top->sym_filter_entry = he; }else {tools/perf/ui/gtk/annotate.c +1
-1@@ -174,7 +174,7 @@ static int symbol__gtk_annotate(struct map_symbol *ms, struct evsel *evsel,if (ms->map->dso->annotate_warned)return -1 ; - err =symbol__annotate (ms, evsel,0 , &annotation__default_options,NULL ); + err =symbol__annotate (ms, evsel, &annotation__default_options,NULL );if (err) {char msg[BUFSIZ ];symbol__strerror_disassemble (ms, err, msg,sizeof (msg));tools/perf/util/annotate.c +7
-12@@ -1143,7 +1143,6 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp) }struct annotate_args { -size_t privsize;struct arch *arch;struct map_symbol ms;struct evsel *evsel;@@ -1153,83 +1152,55 @@ struct annotate_args {int line_nr; }; -static void annotation_line__delete (struct annotation_line *al) +static void annotation_line__new (struct annotation_line *al, +struct annotate_args *args, +int nr) { -void *ptr = (void *) al - al->privsize; - -free_srcline (al->path); -zfree (&al->line); -free (ptr); + al->offset = args->offset; + al->line =strdup (args->line); + al->line_nr = args->line_nr; + al->data_nr = nr; } -/* -* Allocating the annotation line data with following -* structure: -* -* --------------------------------------
tools/perf/util/annotate.c struct annotate_args { · line 1166
Quoted 10 lines
tools/perf/util/annotate.c +1
-8-* private space | struct annotation_line -* -------------------------------------- -* -* Size of the private space is stored in 'struct annotation_line'. -* -*/ -static struct annotation_line * -annotation_line__new (struct annotate_args *args,size_t privsize) +static size_t disasm_line_size (int nr) {
I agree we can get rid of the 'users' privsize passed from symbol__annotate, but could you please put it in separate patch, while keeping privsize in here?
and then put the rest of the code factoring into separate patch, so we can see clearly the change and the benefits
your new annotation_line__new should be renamed to something like annotation_line__init ... we keep __new suffix for functions that return new objects
thanks,
jirka
Re: [PATCH 1/3] perf annotate: Nuke privsize
Quoted 19 lines · Jiri Olsa
Quoted 5 lines
tools/perf/util/annotate.c +0
-5-/* -* Allocating the annotation line data with following -* structure: -* -* -------------------------------------- tools/perf/util/annotate.c struct annotate_args { · line 1166
Quoted 10 lines
tools/perf/util/annotate.c +1
-8-* private space | struct annotation_line -* -------------------------------------- -* -* Size of the private space is stored in 'struct annotation_line'. -* -*/ -static struct annotation_line * -annotation_line__new (struct annotate_args *args,size_t privsize) +static size_t disasm_line_size (int nr) {I agree we can get rid of the 'users' privsize passed from
symbol__annotate, but could you please put it in separate patch, while keeping privsize in here?
Quoted 6 lines
and then put the rest of the code factoring into separate patch, so we can see clearly the change and the benefits
your new
annotation_line__newshould be renamed to something likeannotation_line__init... we keep__newsuffix for functions that return new objects
Sure Jiri. Will resend with these changes.
- Ravi
PATCH 2/3 perf annotate: Align struct annotate_args
In reply to Ravi BangoriaAlign fields of struct annotate_args.
--- tools/perf/util/annotate.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
tools/perf/util/annotate.c +6 -6
@@ -1143,13 +1143,13 @@ static int disasm_line__parse(char *line, const char **namep, char **rawp) }struct annotate_args { -struct arch *arch; -struct map_symbol ms; -struct evsel *evsel; +struct arch *arch; +struct map_symbol ms; +struct evsel *evsel;struct annotation_options *options; -s64 offset; -char *line; -int line_nr; +s64 offset; +char *line; +int line_nr; }; static void annotation_line__new(struct annotation_line *al,
Signature · 1 line
2.24.1
PATCH 3/3 perf annotate: Fix segfault with source toggle
In reply to Ravi BangoriaWhile rendering annotate browser from perf report tui, we keep track of total number of lines(asm + source) in annotation->nr_entries and total number of asm lines in annotation->nr_asm_entries. But we don't reset them before starting. Thus if user annotates same function multiple times, we restart incrementing these fields with old values.
This causes a segfault when user tries to toggle source code after annotating same function multiple times. Fix it.
--- tools/perf/util/annotate.c | 2 ++ 1 file changed, 2 insertions(+)
tools/perf/util/annotate.c +2 -0
@@ -2610,6 +2610,8 @@ void annotation__set_offsets(struct annotation *notes, s64 size)struct annotation_line *al; notes->max_line_len =0 ; + notes->nr_entries =0 ; + notes->nr_asm_entries =0 ;list_for_each_entry (al, ¬es->src->source, node) {size_t line_len =strlen (al->line);
Signature · 1 line
2.24.1
Re: [PATCH 3/3] perf annotate: Fix segfault with source toggle
Quoted 19 lines · Ravi Bangoria
While rendering annotate browser from perf report tui, we keep track of total number of lines(asm + source) in
annotation->nr_entriesand total number of asm lines inannotation->nr_asm_entries. But we don't reset them before starting. Thus if user annotates same function multiple times, we restart incrementing these fields with old values.This causes a segfault when user tries to toggle source code after annotating same function multiple times. Fix it.
Signed-off-by Ravi Bangoria <[email protected]>--- tools/perf/util/annotate.c | 2 ++ 1 file changed, 2 insertions(+)tools/perf/util/annotate.c +0
-0
tools/perf/util/annotate.c void annotation__set_offsets(struct annotation *notes, s64 size) · line 2614
Quoted 5 lines
tools/perf/util/annotate.c +2
-0@@ -2610,6 +2610,8 @@ void annotation__set_offsets(struct annotation *notes, s64 size)struct annotation_line *al; notes->max_line_len =0 ; + notes->nr_entries =0 ; + notes->nr_asm_entries =0 ;
seems fair ;-)
also could you please make that function static (in separate change) in your next repost?
thanks,
jirka
Quoted 6 lines
tools/perf/util/annotate.c +0
-0list_for_each_entry (al, ¬es->src->source, node) {size_t line_len =strlen (al->line);Signature · 1 line
2.24.1
Re: [PATCH 3/3] perf annotate: Fix segfault with source toggle
Quoted 22 lines · Jiri Olsa
Quoted 21 lines · Ravi Bangoria
While rendering annotate browser from perf report tui, we keep track of total number of lines(asm + source) in
annotation->nr_entriesand total number of asm lines inannotation->nr_asm_entries. But we don't reset them before starting. Thus if user annotates same function multiple times, we restart incrementing these fields with old values.This causes a segfault when user tries to toggle source code after annotating same function multiple times. Fix it.
Signed-off-by Ravi Bangoria <[email protected]>--- tools/perf/util/annotate.c | 2 ++ 1 file changed, 2 insertions(+)tools/perf/util/annotate.c +0
-0@@ -2610,6 +2610,8 @@ void annotation__set_offsets(struct annotation *notes, s64 size)struct annotation_line *al;
Quoted 7 lines
tools/perf/util/annotate.c void annotation__set_offsets(struct annotation *notes, s64 size) · line 2614
Quoted 3 lines
tools/perf/util/annotate.c +2
-0notes->max_line_len =0 ; + notes->nr_entries =0 ; + notes->nr_asm_entries =0 ;seems fair ;-)
Acked-by Jiri Olsa <[email protected]>
Thanks!
Quoted 3 lines
also could you please make that function static (in separate change) in your next repost?
Sure will do.
- Ravi