perf symbols: Add documentation to struct symbol.
Ian Rogers
reviewerPATCH 1/3 perf symbols: Add documentation to struct symbol.
Refactor some existing comments and then infer the rest.
--- tools/perf/util/symbol.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
tools/perf/util/symbol.h +14 -3
@@ -40,22 +40,33 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, GElf_Shdr *shp, const char *name, size_t *idx);#endif -/** struct symbol - symtab entry -* -* @ignore - resolvable but tools ignore it (e.g. idle routines) +/** +* A symtab entry. When allocated this may be preceded by an annotation (see +* symbol__annotation), a browser_index (see symbol__browser_index) and rb_node +* to sort by name (see struct symbol_name_rb_node). */ struct symbol {struct rb_node rb_node; +/** Range of symbol [start, end). */ u64 start;u64 end; +/** Length of the string name. */ u16 namelen; +/** ELF symbol type as defined for st_info. E.g STT_OBJECT or STT_FUNC. */ u8 type:4 ; +/** ELF binding type as defined for st_info. E.g. STB_WEAK or STB_GLOBAL. */ u8 binding:4 ; +/** Set true for kernel symbols of idle routines. */ u8 idle:1 ; +/** Resolvable but tools ignore it (e.g. idle routines). */ u8 ignore:1 ; +/** Symbol for an inlined function. */ u8 inlined:1 ; +/** Architecture specific. Unused except on PPC where it holds st_other. */ u8 arch_sym; +/** Has symbol__annotate2 been performed. */ bool annotate2; +/** The name of length namelen associated with the symbol. */ char name[]; };
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
Ian Rogers
reviewerPATCH 2/3 perf symbols: Bit pack to save a byte
Use a bit field alongside the earlier bit fields.
--- tools/perf/util/annotate.c | 2 +- tools/perf/util/symbol.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/annotate.c +1 -1
@@ -3132,7 +3132,7 @@ int symbol__annotate2(struct map_symbol *ms, struct evsel *evsel, notes->nr_events = nr_pcnt;annotation__update_column_widths (notes); - sym->annotate2 = true; + sym->annotate2 =1 ;return 0 ;
tools/perf/util/symbol.h +2 -2
@@ -62,10 +62,10 @@ struct symbol { u8 ignore:1;/** Symbol for an inlined function. */ u8 inlined:1; +/** Has symbol__annotate2 been performed. */ + u8 annotate2:1;/** Architecture specific. Unused except on PPC where it holds st_other. */ u8 arch_sym; -/** Has symbol__annotate2 been performed. */ -bool annotate2;/** The name of length namelen associated with the symbol. */ char name[]; };
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
Ian Rogers
reviewerPATCH 3/3 perf symbols: Factor out annotation init/exit
In reply to Ian RogersThe exit function fixes a memory leak with the src field as detected by leak sanitizer. An example of which is:
Indirect leak of 25133184 byte(s) in 207 object(s) allocated from:
#0 0x7f199ecfe987 in __interceptor_calloc libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x55defe638224 in annotated_source__alloc_histograms util/annotate.c:803
#2 0x55defe6397e4 in symbol__hists util/annotate.c:952
#3 0x55defe639908 in symbol__inc_addr_samples util/annotate.c:968
#4 0x55defe63aa29 in hist_entry__inc_addr_samples util/annotate.c:1119
#5 0x55defe499a79 in hist_iter__report_callback tools/perf/builtin-report.c:182
#6 0x55defe7a859d in hist_entry_iter__add util/hist.c:1236
#7 0x55defe49aa63 in process_sample_event tools/perf/builtin-report.c:315
#8 0x55defe731bc8 in evlist__deliver_sample util/session.c:1473
#9 0x55defe731e38 in machines__deliver_event util/session.c:1510
#10 0x55defe732a23 in perf_session__deliver_event util/session.c:1590
#11 0x55defe72951e in ordered_events__deliver_event util/session.c:183
#12 0x55defe740082 in do_flush util/ordered-events.c:244
#13 0x55defe7407cb in __ordered_events__flush util/ordered-events.c:323
#14 0x55defe740a61 in ordered_events__flush util/ordered-events.c:341
#15 0x55defe73837f in __perf_session__process_events util/session.c:2390
#16 0x55defe7385ff in perf_session__process_events util/session.c:2420
...--- tools/perf/util/annotate.c | 11 +++++++++++ tools/perf/util/annotate.h | 3 +++ tools/perf/util/symbol.c | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-)
tools/perf/util/annotate.c +11 -0
@@ -1255,6 +1255,17 @@ int disasm_line__scnprintf(struct disasm_line *dl, char *bf, size_t size, bool rreturn ins__scnprintf (&dl->ins, bf, size, &dl->ops, max_ins_name); } +void annotation__init (struct annotation *notes) +{ +pthread_mutex_init (¬es->lock,NULL ); +} + +void annotation__exit (struct annotation *notes) +{ +annotated_source__delete (notes->src); +pthread_mutex_destroy (¬es->lock); +} +static void annotation_line__add (struct annotation_line *al,struct list_head *head) {list_add_tail (&al->node, head);
tools/perf/util/annotate.h +3 -0
@@ -299,6 +299,9 @@ struct annotation {struct annotated_source *src; }; +void annotation__init (struct annotation *notes); +void annotation__exit (struct annotation *notes); +static inline int annotation__cycles_width (struct annotation *notes) {if (notes->have_cycles && notes->options->show_minmax_cycle)
tools/perf/util/symbol.c +8 -1
@@ -274,7 +274,7 @@ struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const char *if (symbol_conf.priv_size) {if (symbol_conf.init_annotation) {struct annotation *notes = (void *)sym; -pthread_mutex_init (¬es->lock,NULL ); +annotation__init (notes); } sym = ((void *)sym) + symbol_conf.priv_size; }
@@ -294,6 +294,13 @@ struct symbol *symbol__new(u64 start, u64 len, u8 binding, u8 type, const char *void symbol__delete (struct symbol *sym) { +if (symbol_conf.priv_size) { +if (symbol_conf.init_annotation) { +struct annotation *notes =symbol__annotation (sym); + +annotation__exit (notes); + } + }free (((void *)sym) - symbol_conf.priv_size); }
Signature · 1 line
2.34.0.rc1.387.gb447b232ab-goog
Hi Ian,
Quoted 4 lines · Ian Rogers
Refactor some existing comments and then infer the rest.
Signed-off-by Ian Rogers <[email protected]>
For all 3 patches,
Thanks,
Namhyung
Quoted 48 lines
--- tools/perf/util/symbol.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)tools/perf/util/symbol.h +14
-4@@ -40,22 +40,33 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, GElf_Shdr *shp, const char *name, size_t *idx);#endif -/** struct symbol - symtab entry -* -* @ignore - resolvable but tools ignore it (e.g. idle routines) +/** +* A symtab entry. When allocated this may be preceded by an annotation (see +* symbol__annotation), a browser_index (see symbol__browser_index) and rb_node +* to sort by name (see struct symbol_name_rb_node). */ struct symbol {struct rb_node rb_node; +/** Range of symbol [start, end). */ u64 start;u64 end; +/** Length of the string name. */ u16 namelen; +/** ELF symbol type as defined for st_info. E.g STT_OBJECT or STT_FUNC. */ u8 type:4 ; +/** ELF binding type as defined for st_info. E.g. STB_WEAK or STB_GLOBAL. */ u8 binding:4 ; +/** Set true for kernel symbols of idle routines. */ u8 idle:1 ; +/** Resolvable but tools ignore it (e.g. idle routines). */ u8 ignore:1 ; +/** Symbol for an inlined function. */ u8 inlined:1 ; +/** Architecture specific. Unused except on PPC where it holds st_other. */ u8 arch_sym; +/** Has symbol__annotate2 been performed. */ bool annotate2; +/** The name of length namelen associated with the symbol. */ char name[]; }; --2.34.0.rc1.387.gb447b232ab-goog
Em Thu, Nov 11, 2021 at 08:04:35PM -0800, Namhyung Kim escreveu:
Quoted 11 lines
Hi Ian,
Quoted 4 lines · Ian Rogers
Refactor some existing comments and then infer the rest.
Signed-off-by Ian Rogers <[email protected]>For all 3 patches,
Acked-by Namhyung Kim <[email protected]>
b4 doesn't catch these Acked-by for the whole series when sent to one of the patches, please consider to send your Acked-by/etc to the [PATCH 0/N] message in that case.
Thanks, applied!
- Arnaldo
Quoted 52 lines
Thanks,
NamhyungQuoted 48 lines
--- tools/perf/util/symbol.h | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)tools/perf/util/symbol.h +14
-4@@ -40,22 +40,33 @@ Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep, GElf_Shdr *shp, const char *name, size_t *idx);#endif -/** struct symbol - symtab entry -* -* @ignore - resolvable but tools ignore it (e.g. idle routines) +/** +* A symtab entry. When allocated this may be preceded by an annotation (see +* symbol__annotation), a browser_index (see symbol__browser_index) and rb_node +* to sort by name (see struct symbol_name_rb_node). */ struct symbol {struct rb_node rb_node; +/** Range of symbol [start, end). */ u64 start;u64 end; +/** Length of the string name. */ u16 namelen; +/** ELF symbol type as defined for st_info. E.g STT_OBJECT or STT_FUNC. */ u8 type:4 ; +/** ELF binding type as defined for st_info. E.g. STB_WEAK or STB_GLOBAL. */ u8 binding:4 ; +/** Set true for kernel symbols of idle routines. */ u8 idle:1 ; +/** Resolvable but tools ignore it (e.g. idle routines). */ u8 ignore:1 ; +/** Symbol for an inlined function. */ u8 inlined:1 ; +/** Architecture specific. Unused except on PPC where it holds st_other. */ u8 arch_sym; +/** Has symbol__annotate2 been performed. */ bool annotate2; +/** The name of length namelen associated with the symbol. */ char name[]; }; --2.34.0.rc1.387.gb447b232ab-goog
Signature · 1 line
- Arnaldo