perf symbols: Avoid annoying message about loading [vdso] symbols
PATCH 1/12 perf symbols: Avoid annoying message about loading [vdso] symbols
From: Arnaldo Carvalho de Melo <[email protected]>
This should be properly fixed when we remove the XXX comment in 'perf report', function resolve_symbol.
--- tools/perf/util/symbol.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
tools/perf/util/symbol.c +1 -0
@@ -1516,6 +1516,7 @@ static int kernel_maps__create_kernel_map(const struct symbol_conf *conf) vdso =dso__new ("[vdso]" );if (vdso ==NULL ) goto out_delete_kernel_map; + vdso->loaded =1 ;if (sysfs__read_build_id ("/sys/kernel/notes" , kernel->build_id,sizeof (kernel->build_id)) ==0 )
Signature · 1 line
1.6.2.5
PATCH 2/12 perf symbols: Rename kernel_map[s] to kernel_map[s]__functions
From: Arnaldo Carvalho de Melo <[email protected]>
As we'll have kernel_map[s]__variables too.
--- tools/perf/builtin-annotate.c | 2 +- tools/perf/util/symbol.c | 46 ++++++++++++++++++++-------------------- tools/perf/util/symbol.h | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-)
tools/perf/builtin-annotate.c +1 -1
@@ -184,7 +184,7 @@ got_map:* trick of looking in the whole kernel symbol list. */ if ((long long )ip <0 ) { - map = kernel_map; + map = kernel_map__functions; goto got_map; } }
tools/perf/util/symbol.c +23 -23
145 lines not on this page · raw message
tools/perf/util/symbol.h +1 -1
@@ -105,6 +105,6 @@ size_t kernel_maps__fprintf(FILE *fp);int symbol__init (struct symbol_conf *conf);extern struct list_head dsos; -extern struct map *kernel_map; +extern struct map *kernel_map__functions;extern struct dso *vdso;#endif /* __PERF_SYMBOL */
Signature · 1 line
1.6.2.5
PATCH 3/12 perf symbols: Split the dsos list into kernel and user parts
From: Arnaldo Carvalho de Melo <[email protected]>
We don't need to look at modules in dsos__findnew because the kernel events come only with user DSOs. Also we need a way to list just the module DSOs so that we can create multiple sets of maps, now that we will support maps for the variables in a symtab.
--- tools/perf/util/header.c | 12 ++++++++- tools/perf/util/symbol.c | 56 ++++++++++++++++++++++++++++++--------------- tools/perf/util/symbol.h | 2 +- 3 files changed, 48 insertions(+), 22 deletions(-)
tools/perf/util/header.c +10 -2
@@ -185,11 +185,11 @@ static int do_write(int fd, const void *buf, size_t size)return 0 ; } -static int dsos__write_buildid_table (int fd) +static int __dsos__write_buildid_table (struct list_head *head,int fd) {struct dso *pos; -list_for_each_entry (pos, &dsos, node) { +list_for_each_entry (pos, head, node) {int err;struct build_id_event b;size_t len;
@@ -212,6 +212,14 @@ static int dsos__write_buildid_table(int fd)return 0 ; } +static int dsos__write_buildid_table (int fd) +{ +int err =__dsos__write_buildid_table (&dsos__kernel, fd); +if (err ==0 ) + err =__dsos__write_buildid_table (&dsos__user, fd); +return err; +} +static int perf_header__adds_write (struct perf_header *self,int fd) {int nr_sections;
tools/perf/util/symbol.c +37 -19
142 lines not on this page · raw message
tools/perf/util/symbol.h +1 -1
@@ -104,7 +104,7 @@ size_t kernel_maps__fprintf(FILE *fp);int symbol__init (struct symbol_conf *conf); -extern struct list_head dsos; +extern struct list_head dsos__user, dsos__kernel;extern struct map *kernel_map__functions;extern struct dso *vdso;#endif /* __PERF_SYMBOL */
Signature · 1 line
1.6.2.5
PATCH 4/12 perf symbols: Unexport kernel_map__functions
From: Arnaldo Carvalho de Melo <[email protected]>
perf annotate was the only user, and it doesn't really needs it.
--- tools/perf/builtin-annotate.c | 8 +++----- tools/perf/util/symbol.c | 3 +-- tools/perf/util/symbol.h | 1 - 3 files changed, 4 insertions(+), 8 deletions(-)
tools/perf/builtin-annotate.c +3 -5
@@ -169,7 +169,6 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) level ='.' ; map =thread__find_map (thread, ip);if (map !=NULL ) { -got_map: ip = map->map_ip (map, ip); sym =map__find_function (map, ip, symbol_filter); }else {
@@ -183,10 +182,9 @@ got_map:* the "[vdso]" dso, but for now lets use the old * trick of looking in the whole kernel symbol list. */ -if ((long long )ip <0 ) { - map = kernel_map__functions; - goto got_map; - } +if ((long long )ip <0 ) + sym =kernel_maps__find_function (ip, &map, + symbol_filter); }dump_printf (" ...... dso: %s\n" , map ? map->dso->long_name :"<not found>" );
tools/perf/util/symbol.c +1 -2
@@ -36,6 +36,7 @@ static int dso__load_kernel_sym(struct dso *self, struct map *map,unsigned int symbol__priv_size;static int vmlinux_path__nr_entries;static char **vmlinux_path; +static struct map *kernel_map__functions;static struct symbol_conf symbol_conf__defaults = { .use_modules = true,
@@ -1164,8 +1165,6 @@ out:return ret; } -struct map *kernel_map__functions; -static void kernel_maps__insert (struct map *map) {maps__insert (&kernel_maps__functions, map);
tools/perf/util/symbol.h +0 -1
@@ -105,6 +105,5 @@ size_t kernel_maps__fprintf(FILE *fp);int symbol__init (struct symbol_conf *conf);extern struct list_head dsos__user, dsos__kernel; -extern struct map *kernel_map__functions;extern struct dso *vdso;#endif /* __PERF_SYMBOL */
Signature · 1 line
1.6.2.5
PATCH 5/12 perf symbols: Add a 'type' field to struct map
From: Arnaldo Carvalho de Melo <[email protected]>
That way we will be able to check if the right symtab is loaded in the underlying DSO.
--- tools/perf/builtin-top.c | 2 +- tools/perf/util/event.h | 12 +++++++++--- tools/perf/util/map.c | 12 +++++++----- tools/perf/util/process_events.c | 2 +- tools/perf/util/symbol.c | 31 +++++++++++++++++++++---------- tools/perf/util/symbol.h | 4 +++- 6 files changed, 42 insertions(+), 21 deletions(-)
tools/perf/builtin-top.c +1 -1
@@ -996,7 +996,7 @@ static void event__process_mmap(event_t *self)struct thread *thread =threads__findnew (self->mmap.pid);if (thread !=NULL ) { -struct map *map =map__new (&self->mmap,NULL ,0 ); +struct map *map =map__new (&self->mmap,MAP__FUNCTION ,NULL ,0 );if (map !=NULL )thread__insert_map (thread, map); }
tools/perf/util/event.h +9 -3
@@ -80,6 +80,10 @@ typedef union event_union {struct sample_event sample; } event_t; +enum map_type { +MAP__FUNCTION , +}; + struct map { union { struct rb_node rb_node;
@@ -87,6 +91,7 @@ struct map { };u64 start;u64 end; +enum map_type type;u64 pgoff;u64 (*map_ip)(struct map *,u64 );u64 (*unmap_ip)(struct map *,u64 );
@@ -112,9 +117,10 @@ struct symbol;typedef int (*symbol_filter_t )(struct map *map,struct symbol *sym); -void map__init (struct map *self,u64 start,u64 end,u64 pgoff, -struct dso *dso); -struct map *map__new (struct mmap_event *event,char *cwd,int cwdlen); +void map__init (struct map *self,enum map_type type, +u64 start,u64 end,u64 pgoff,struct dso *dso); +struct map *map__new (struct mmap_event *event,enum map_type , +char *cwd,int cwdlen);void map__delete (struct map *self);struct map *map__clone (struct map *self);int map__overlap (struct map *l,struct map *r);
tools/perf/util/map.c +7 -5
@@ -20,9 +20,10 @@ static int strcommon(const char *pathname, char *cwd, int cwdlen)return n; } -void map__init (struct map *self,u64 start,u64 end,u64 pgoff, -struct dso *dso) +void map__init (struct map *self,enum map_type type, +u64 start,u64 end,u64 pgoff,struct dso *dso) { + self->type = type; self->start = start; self->end = end; self->pgoff = pgoff;
@@ -32,7 +33,8 @@ void map__init(struct map *self, u64 start, u64 end, u64 pgoff,RB_CLEAR_NODE (&self->rb_node); } -struct map *map__new (struct mmap_event *event,char *cwd,int cwdlen) +struct map *map__new (struct mmap_event *event,enum map_type type, +char *cwd,int cwdlen) {struct map *self =malloc (sizeof (*self));
@@ -63,7 +65,7 @@ struct map *map__new(struct mmap_event *event, char *cwd, int cwdlen)if (dso ==NULL ) goto out_delete; -map__init (self, event->start, event->start + event->len, +map__init (self, type, event->start, event->start + event->len, event->pgoff, dso);if (self->dso == vdso || anon)
@@ -103,7 +105,7 @@ void map__fixup_end(struct map *self, struct rb_root *symbols)struct symbol *map__find_function (struct map *self,u64 ip,symbol_filter_t filter) { -if (!self->dso->loaded) { +if (!dso__loaded (self->dso, self->type)) {int nr =dso__load (self->dso, self, filter);if (nr <0 ) {
tools/perf/util/process_events.c +1 -1
@@ -6,7 +6,7 @@ int cwdlen;int process_mmap_event (event_t *event,unsigned long offset,unsigned long head) { -struct map *map =map__new (&event->mmap, cwd, cwdlen); +struct map *map =map__new (&event->mmap,MAP__FUNCTION , cwd, cwdlen);struct thread *thread =threads__findnew (event->mmap.pid); dump_printf("%p [%p]: PERF_RECORD_MMAP %d/%d: [%p(%p) @ %p]: %s\n",
tools/perf/util/symbol.c +21 -10
@@ -29,7 +29,7 @@ enum dso_origin { };static void dsos__add (struct list_head *head,struct dso *dso); -static struct map *map__new2 (u64 start,struct dso *dso); +static struct map *map__new2 (u64 start,struct dso *dso,enum map_type type);static void kernel_maps__insert (struct map *map);static int dso__load_kernel_sym (struct dso *self,struct map *map,symbol_filter_t filter);
@@ -45,6 +45,16 @@ static struct symbol_conf symbol_conf__defaults = {static struct rb_root kernel_maps__functions; +bool dso__loaded (const struct dso *self,enum map_type type) +{ +return self->loaded & (1 << type); +} + +static void dso__set_loaded (struct dso *self,enum map_type type) +{ + self->loaded |= (1 << type); +} +static void symbols__fixup_end (struct rb_root *self) {struct rb_node *nd, *prevnd =rb_first (self);
@@ -387,7 +397,7 @@ static int kernel_maps__split_kallsyms(symbol_filter_t filter)if (dso ==NULL )return -1 ; - map =map__new2 (pos->start, dso); + map =map__new2 (pos->start, dso,MAP__FUNCTION );if (map ==NULL ) {dso__delete (dso);return -1 ;
@@ -846,7 +856,8 @@ static int dso__load_sym(struct dso *self, struct map *map, const char *name, curr_dso =dso__new (dso_name);if (curr_dso ==NULL ) goto out_elf_end; - curr_map =map__new2 (start, curr_dso); + curr_map =map__new2 (start, curr_dso, +MAP__FUNCTION );if (curr_map ==NULL ) {dso__delete (curr_dso); goto out_elf_end;
@@ -1076,7 +1087,7 @@ int dso__load(struct dso *self, struct map *map, symbol_filter_t filter)int ret =-1 ;int fd; - self->loaded =1 ; +dso__set_loaded (self, map->type);if (self->kernel)return dso__load_kernel_sym (self, map, filter);
@@ -1275,7 +1286,7 @@ static int dsos__set_modules_path(void)* they are loaded) and for vmlinux, where only after we load all the * symbols we'll know where it starts and ends. */ -static struct map *map__new2 (u64 start,struct dso *dso) +static struct map *map__new2 (u64 start,struct dso *dso,enum map_type type) {struct map *self =malloc (sizeof (*self));
@@ -1283,7 +1294,7 @@ static struct map *map__new2(u64 start, struct dso *dso)/* * ->end will be filled after we load all the symbols */ -map__init (self, start,0 ,0 , dso); +map__init (self, type, start,0 ,0 , dso); }return self;
@@ -1333,7 +1344,7 @@ static int kernel_maps__create_module_maps(void)if (dso ==NULL ) goto out_delete_line; - map =map__new2 (start, dso); + map =map__new2 (start, dso,MAP__FUNCTION );if (map ==NULL ) {dso__delete (dso); goto out_delete_line;
@@ -1394,7 +1405,7 @@ static int dso__load_vmlinux(struct dso *self, struct map *map,if (fd <0 )return -1 ; - self->loaded =1 ; +dso__set_loaded (self, map->type); err =dso__load_sym (self, map, self->long_name, fd, filter,1 ,0 );close (fd);
@@ -1522,7 +1533,7 @@ static int kernel_maps__create_kernel_map(const struct symbol_conf *conf)if (kernel ==NULL )return -1 ; - kernel_map__functions =map__new2 (0 , kernel); + kernel_map__functions =map__new2 (0 , kernel,MAP__FUNCTION );if (kernel_map__functions ==NULL ) goto out_delete_kernel_dso;
@@ -1533,7 +1544,7 @@ static int kernel_maps__create_kernel_map(const struct symbol_conf *conf) vdso =dso__new ("[vdso]" );if (vdso ==NULL ) goto out_delete_kernel_map; - vdso->loaded =1 ; +dso__set_loaded (vdso,MAP__FUNCTION );if (sysfs__read_build_id ("/sys/kernel/notes" , kernel->build_id,sizeof (kernel->build_id)) ==0 )
tools/perf/util/symbol.h +3 -1
@@ -69,10 +69,10 @@ struct dso {struct symbol *(*find_function)(struct dso *,u64 ip); u8 adjust_symbols:1; u8 slen_calculated:1; - u8 loaded:1; u8 has_build_id:1; u8 kernel:1;unsigned char origin; +u8 loaded;u8 build_id[BUILD_ID_SIZE ];u16 long_name_len;const char *short_name;
@@ -85,6 +85,8 @@ void dso__delete(struct dso *self);struct symbol *dso__find_function (struct dso *self,u64 ip); +bool dso__loaded (const struct dso *self,enum map_type type); +struct dso *dsos__findnew (const char *name);int dso__load (struct dso *self,struct map *map,symbol_filter_t filter);void dsos__fprintf (FILE *fp);
Signature · 1 line
1.6.2.5
PATCH 6/12 perf symbols: Better support for multiple symbol tables per dso
From: Arnaldo Carvalho de Melo <[email protected]>
By using an array of rb_roots in struct dso we can, from a struct map instance to get the right symbol rb_tree more easily. This way we can have just one symbol lookup method for struct map instances, map__find_symbol, instead of one per symtab type (functions, variables).
--- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/util/event.h | 12 +++++--- tools/perf/util/map.c | 12 +++++--- tools/perf/util/symbol.c | 59 +++++++++++++++++++++++++---------------- tools/perf/util/symbol.h | 7 ++--- 7 files changed, 56 insertions(+), 40 deletions(-)
tools/perf/builtin-annotate.c +1 -1
@@ -170,7 +170,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) map =thread__find_map (thread, ip);if (map !=NULL ) { ip = map->map_ip (map, ip); - sym =map__find_function (map, ip, symbol_filter); + sym =map__find_symbol (map, ip, symbol_filter); }else {/* * If this is outside of all known maps,
tools/perf/builtin-report.c +1 -1
@@ -455,7 +455,7 @@ got_map:dump_printf (" ...... map: %Lx -> %Lx\n" , *ipp, ip); *ipp = ip; -return map ?map__find_function (map, ip,NULL ) :NULL ; +return map ?map__find_symbol (map, ip,NULL ) :NULL ; }static int call__match (struct symbol *sym)
tools/perf/builtin-top.c +1 -1
@@ -948,7 +948,7 @@ static void event__process_sample(const event_t *self, int counter) map =thread__find_map (thread, ip);if (map !=NULL ) { ip = map->map_ip (map, ip); - sym =map__find_function (map, ip, symbol_filter); + sym =map__find_symbol (map, ip, symbol_filter);if (sym ==NULL )return ; userspace_samples++;
tools/perf/util/event.h +7 -5
@@ -81,7 +81,9 @@ typedef union event_union { } event_t;enum map_type { -MAP__FUNCTION , +MAP__FUNCTION =0 , + +MAP__NR_TYPES , };struct map {
@@ -125,10 +127,10 @@ void map__delete(struct map *self);struct map *map__clone (struct map *self);int map__overlap (struct map *l,struct map *r);size_t map__fprintf (struct map *self,FILE *fp); -struct symbol *map__find_function (struct map *self,u64 ip, -symbol_filter_t filter); -void map__fixup_start (struct map *self,struct rb_root *symbols); -void map__fixup_end (struct map *self,struct rb_root *symbols); +struct symbol *map__find_symbol (struct map *self,u64 addr, +symbol_filter_t filter); +void map__fixup_start (struct map *self); +void map__fixup_end (struct map *self);int event__synthesize_thread (pid_t pid,int (*process)(event_t *event));void event__synthesize_threads (int (*process)(event_t *event));
tools/perf/util/map.c +7 -5
@@ -82,8 +82,9 @@ void map__delete(struct map *self)free (self); } -void map__fixup_start (struct map *self,struct rb_root *symbols) +void map__fixup_start (struct map *self) { +struct rb_root *symbols = &self->dso->symbols[self->type];struct rb_node *nd =rb_first (symbols);if (nd !=NULL ) { struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -91,8 +92,9 @@ void map__fixup_start(struct map *self, struct rb_root *symbols) } } -void map__fixup_end (struct map *self,struct rb_root *symbols) +void map__fixup_end (struct map *self) { +struct rb_root *symbols = &self->dso->symbols[self->type];struct rb_node *nd =rb_last (symbols);if (nd !=NULL ) { struct symbol *sym = rb_entry(nd, struct symbol, rb_node);
@@ -102,8 +104,8 @@ void map__fixup_end(struct map *self, struct rb_root *symbols)#define DSO__DELETED "(deleted)" -struct symbol *map__find_function (struct map *self,u64 ip, -symbol_filter_t filter) +struct symbol *map__find_symbol (struct map *self,u64 addr, +symbol_filter_t filter) {if (!dso__loaded (self->dso, self->type)) {int nr =dso__load (self->dso, self, filter);
@@ -138,7 +140,7 @@ struct symbol *map__find_function(struct map *self, u64 ip, } } -return self->dso->find_function (self->dso, ip); +return self->dso->find_symbol (self->dso, self->type, addr); }struct map *map__clone (struct map *self)
tools/perf/util/symbol.c +36 -23
170 lines not on this page · raw message
tools/perf/util/symbol.h +3 -4
@@ -65,8 +65,9 @@ static inline void *symbol__priv(struct symbol *self)struct dso {struct list_head node; -struct rb_root functions; -struct symbol *(*find_function)(struct dso *,u64 ip); +struct rb_root symbols[MAP__NR_TYPES ]; +struct symbol *(*find_symbol)(struct dso *self, +enum map_type type,u64 addr);u8 adjust_symbols:1 ;u8 slen_calculated:1 ;u8 has_build_id:1 ;
@@ -83,8 +84,6 @@ struct dso {struct dso *dso__new (const char *name);void dso__delete (struct dso *self); -struct symbol *dso__find_function (struct dso *self,u64 ip); -bool dso__loaded (const struct dso *self,enum map_type type);struct dso *dsos__findnew (const char *name);
Signature · 1 line
1.6.2.5
PATCH 7/12 perf symbols: Make the kallsyms loading routines part of the dso class
From: Arnaldo Carvalho de Melo <[email protected]>
So that the kallsyms loading routines are the direct counterpart of the vmlinux loading ones, i.e. dso__load_kallsyms is the counterpart of dso__load_vmlinux.
In the process make them also use the symbols rb tree indexed by map->type, paving the way for supporting other types of symtabs, such as the next one to be supported: variables.
This also allowed removal of yet another global variable:kernel_map__functions.
--- tools/perf/util/symbol.c | 77 ++++++++++++++++++++++----------------------- 1 files changed, 38 insertions(+), 39 deletions(-)
tools/perf/util/symbol.c +38 -39
@@ -37,7 +37,6 @@ static int dso__load_kernel_sym(struct dso *self, struct map *map,unsigned int symbol__priv_size;static int vmlinux_path__nr_entries;static char **vmlinux_path; -static struct map *kernel_map__functions;static struct symbol_conf symbol_conf__defaults = { .use_modules = true,
@@ -296,10 +295,11 @@ size_t dso__fprintf(struct dso *self, FILE *fp)* so that we can in the next step set the symbol ->end address and then * call kernel_maps__split_kallsyms. */ -static int kernel_maps__load_all_kallsyms (void ) +static int dso__load_all_kallsyms (struct dso *self,struct map *map) {char *line =NULL ;size_t n; +struct rb_root *root = &self->symbols[map->type];FILE *file =fopen ("/proc/kallsyms" ,"r" );if (file ==NULL )
@@ -342,13 +342,11 @@ static int kernel_maps__load_all_kallsyms(void)if (sym ==NULL ) goto out_delete_line; -/* * We will pass the symbols to the filter later, in -* kernel_maps__split_kallsyms, when we have split the -* maps per module +* map__split_kallsyms, when we have split the maps per module */ -symbols__insert (&kernel_map__functions->dso->symbols[MAP__FUNCTION ], sym); +symbols__insert (root, sym); }free (line);
@@ -367,12 +365,14 @@ out_failure:* kernel range is broken in several maps, named [kernel].N, as we don't have * the original ELF section names vmlinux have. */ -static int kernel_maps__split_kallsyms (symbol_filter_t filter) +static int dso__split_kallsyms (struct dso *self,struct map *map, +symbol_filter_t filter) { -struct map *map = kernel_map__functions; +struct map *curr_map = map;struct symbol *pos;int count =0 ; -struct rb_node *next =rb_first (&kernel_map__functions->dso->symbols[map->type]); +struct rb_root *root = &self->symbols[map->type]; +struct rb_node *next =rb_first (root);int kernel_range =0 ;while (next) {
@@ -385,9 +385,9 @@ static int kernel_maps__split_kallsyms(symbol_filter_t filter)if (module) { *module++ ='\0' ; -if (strcmp (map->dso->name, module)) { - map =kernel_maps__find_by_dso_name (module); -if (!map) { +if (strcmp (self->name, module)) { + curr_map =kernel_maps__find_by_dso_name (module); +if (curr_map ==NULL ) {pr_err ("/proc/{kallsyms,modules} " "inconsistency!\n" );return -1 ;
@@ -397,9 +397,9 @@ static int kernel_maps__split_kallsyms(symbol_filter_t filter)* So that we look just like we get from .ko files, * i.e. not prelinked, relative to map->start. */ - pos->start = map->map_ip (map, pos->start); - pos->end = map->map_ip (map, pos->end); - }else if (map != kernel_map__functions) { + pos->start = curr_map->map_ip (curr_map, pos->start); + pos->end = curr_map->map_ip (curr_map, pos->end); + }else if (curr_map != map) {char dso_name[PATH_MAX ];struct dso *dso;
@@ -410,25 +410,24 @@ static int kernel_maps__split_kallsyms(symbol_filter_t filter)if (dso ==NULL )return -1 ; - map =map__new2 (pos->start, dso,MAP__FUNCTION ); + curr_map =map__new2 (pos->start, dso, map->type);if (map ==NULL ) {dso__delete (dso);return -1 ; } - map->map_ip = map->unmap_ip = identity__map_ip; -kernel_maps__insert (map); + curr_map->map_ip = curr_map->unmap_ip = identity__map_ip; +kernel_maps__insert (curr_map); ++kernel_range; } -if (filter &&filter (map, pos)) { -rb_erase (&pos->rb_node, &kernel_map__functions->dso->symbols[map->type]); +if (filter &&filter (curr_map, pos)) { +rb_erase (&pos->rb_node, root);symbol__delete (pos); }else { -if (map != kernel_map__functions) { -rb_erase (&pos->rb_node, - &kernel_map__functions->dso->symbols[map->type]); -symbols__insert (&map->dso->symbols[map->type], pos); +if (curr_map != map) { +rb_erase (&pos->rb_node, root); +symbols__insert (&curr_map->dso->symbols[curr_map->type], pos); } count++; }
@@ -438,15 +437,16 @@ static int kernel_maps__split_kallsyms(symbol_filter_t filter) } -static int kernel_maps__load_kallsyms (symbol_filter_t filter) +static int dso__load_kallsyms (struct dso *self,struct map *map, +symbol_filter_t filter) { -if (kernel_maps__load_all_kallsyms ()) +if (dso__load_all_kallsyms (self, map) <0 )return -1 ; -symbols__fixup_end (&kernel_map__functions->dso->symbols[MAP__FUNCTION ]); - kernel_map__functions->dso->origin =DSO__ORIG_KERNEL ; +symbols__fixup_end (&self->symbols[map->type]); + self->origin =DSO__ORIG_KERNEL ; -return kernel_maps__split_kallsyms (filter); +return dso__split_kallsyms (self, map, filter); }size_t kernel_maps__fprintf (FILE *fp)
@@ -1457,9 +1457,8 @@ static int dso__load_kernel_sym(struct dso *self, struct map *map,if (err <=0 ) {pr_info ("The file %s cannot be used, " "trying to use /proc/kallsyms..." , self->long_name); -sleep (2 ); do_kallsyms: - err =kernel_maps__load_kallsyms (filter); + err =dso__load_kallsyms (self, map, filter);if (err >0 && !is_kallsyms)dso__set_long_name (self,strdup ("[kernel.kallsyms]" )); }
@@ -1541,18 +1540,19 @@ size_t dsos__fprintf_buildid(FILE *fp)static int kernel_maps__create_kernel_map (const struct symbol_conf *conf) { +struct map *kmap;struct dso *kernel =dso__new (conf->vmlinux_name ?:"[kernel.kallsyms]" );if (kernel ==NULL )return -1 ; - kernel_map__functions =map__new2 (0 , kernel,MAP__FUNCTION ); -if (kernel_map__functions ==NULL ) + kmap =map__new2 (0 , kernel,MAP__FUNCTION ); +if (kmap ==NULL ) goto out_delete_kernel_dso; - kernel_map__functions->map_ip = kernel_map__functions->unmap_ip = identity__map_ip; - kernel->short_name ="[kernel]" ; - kernel->kernel =1 ; + kmap->map_ip = kmap->unmap_ip = identity__map_ip; + kernel->short_name ="[kernel]" ; + kernel->kernel =1 ; vdso =dso__new ("[vdso]" );if (vdso ==NULL )
@@ -1563,15 +1563,14 @@ static int kernel_maps__create_kernel_map(const struct symbol_conf *conf) sizeof(kernel->build_id)) == 0) kernel->has_build_id = true; -kernel_maps__insert (kernel_map__functions); +kernel_maps__insert (kmap);dsos__add (&dsos__kernel, kernel);dsos__add (&dsos__user, vdso);return 0 ; out_delete_kernel_map: -map__delete (kernel_map__functions); - kernel_map__functions =NULL ; +map__delete (kmap); out_delete_kernel_dso:dso__delete (kernel);return -1 ;
Signature · 1 line
1.6.2.5
PATCH 8/12 perf symbols: kernel_maps should be an array of MAP__NR_TYPES entries
From: Arnaldo Carvalho de Melo <[email protected]>
So that we can support multiple symbol table types.
--- tools/perf/util/symbol.c | 51 ++++++++++++++++++++++++++++++++++----------- tools/perf/util/thread.h | 1 - 2 files changed, 38 insertions(+), 14 deletions(-)
tools/perf/util/symbol.c +38 -13
@@ -29,6 +29,7 @@ enum dso_origin { };static void dsos__add (struct list_head *head,struct dso *dso); +static struct map *kernel_maps__find_by_dso_name (const char *name);static struct map *map__new2 (u64 start,struct dso *dso,enum map_type type);static void kernel_maps__insert (struct map *map);struct symbol *dso__find_symbol (struct dso *self,enum map_type type,u64 addr);
@@ -43,7 +44,7 @@ static struct symbol_conf symbol_conf__defaults = { .try_vmlinux_path = true, }; -static struct rb_root kernel_maps__functions; +static struct rb_root kernel_maps[MAP__NR_TYPES ];bool dso__loaded (const struct dso *self,enum map_type type) {
@@ -78,10 +79,10 @@ static void symbols__fixup_end(struct rb_root *self) curr->end =roundup (curr->start,4096 ); } -static void kernel_maps__fixup_end (void ) +static void __kernel_maps__fixup_end (struct rb_root *root) {struct map *prev, *curr; -struct rb_node *nd, *prevnd =rb_first (&kernel_maps__functions); +struct rb_node *nd, *prevnd =rb_first (root);if (prevnd ==NULL )return ;
@@ -101,6 +102,13 @@ static void kernel_maps__fixup_end(void) curr->end = ~0UL ; } +static void kernel_maps__fixup_end (void ) +{ +int i; +for (i =0 ; i <MAP__NR_TYPES ; ++i) +__kernel_maps__fixup_end (&kernel_maps[i]); +} +static struct symbol *symbol__new (u64 start,u64 len,const char *name) {size_t namelen =strlen (name) +1 ;
@@ -449,12 +457,12 @@ static int dso__load_kallsyms(struct dso *self, struct map *map,return dso__split_kallsyms (self, map, filter); } -size_t kernel_maps__fprintf (FILE *fp) +static size_t __kernel_maps__fprintf (enum map_type type,FILE *fp) { -size_t printed =fprintf (fp,"Kernel maps:\n" ); +size_t printed =fprintf (fp,"%s:\n" , map_type__name[type]);struct rb_node *nd; -for (nd =rb_first (&kernel_maps__functions); nd; nd =rb_next (nd)) { +for (nd =rb_first (&kernel_maps[type]); nd; nd =rb_next (nd)) { struct map *pos = rb_entry(nd, struct map, rb_node); printed +=fprintf (fp,"Map:" );
@@ -465,6 +473,16 @@ size_t kernel_maps__fprintf(FILE *fp) } } +return printed; +} + +size_t kernel_maps__fprintf (FILE *fp) +{ +size_t printed =fprintf (fp,"Kernel maps:\n" ); +int i; +for (i =0 ; i <MAP__NR_TYPES ; ++i) + printed +=__kernel_maps__fprintf (i, fp); +return printed +fprintf (fp,"END kernel maps\n" ); }
@@ -1191,13 +1209,14 @@ out:static void kernel_maps__insert (struct map *map) { -maps__insert (&kernel_maps__functions, map); +maps__insert (&kernel_maps[map->type], map); } -struct symbol *kernel_maps__find_function (u64 ip,struct map **mapp, -symbol_filter_t filter) +static struct symbol *kernel_maps__find_symbol (u64 ip,enum map_type type, +struct map **mapp, +symbol_filter_t filter) { -struct map *map =maps__find (&kernel_maps__functions, ip); +struct map *map =maps__find (&kernel_maps[type], ip);if (mapp) *mapp = map;
@@ -1206,17 +1225,23 @@ struct symbol *kernel_maps__find_function(u64 ip, struct map **mapp, ip = map->map_ip (map, ip);return map__find_symbol (map, ip, filter); }else -WARN_ONCE (RB_EMPTY_ROOT (&kernel_maps__functions), +WARN_ONCE (RB_EMPTY_ROOT (&kernel_maps[type]),"Empty kernel_maps, was symbol__init() called?\n" );return NULL ; } -struct map *kernel_maps__find_by_dso_name (const char *name) +struct symbol *kernel_maps__find_function (u64 ip,struct map **mapp, +symbol_filter_t filter) +{ +return kernel_maps__find_symbol (ip,MAP__FUNCTION , mapp, filter); +} + +static struct map *kernel_maps__find_by_dso_name (const char *name) {struct rb_node *nd; -for (nd =rb_first (&kernel_maps__functions); nd; nd =rb_next (nd)) { +for (nd =rb_first (&kernel_maps[MAP__FUNCTION ]); nd; nd =rb_next (nd)) { struct map *map = rb_entry(nd, struct map, rb_node);if (map->dso &&strcmp (map->dso->name, name) ==0 )
tools/perf/util/thread.h +0 -1
@@ -28,7 +28,6 @@ struct map *maps__find(struct rb_root *maps, u64 ip);struct symbol *kernel_maps__find_function (const u64 ip,struct map **mapp,symbol_filter_t filter); -struct map *kernel_maps__find_by_dso_name (const char *name);static inline struct map *thread__find_map (struct thread *self,u64 ip) {
Signature · 1 line
1.6.2.5
PATCH 9/12 perf symbols: Support multiple symtabs in struct thread
From: Arnaldo Carvalho de Melo <[email protected]>
Making the routines that were so far specific to the kernel maps useful for all threads.
This is done by making the kernel maps be contained in a kernel "thread".
This gets the kernel specific routines closer to the userspace counterparts, which will help in reducing the boilerplate for resolving a symbol, as will be demonstrated in the next patches.
--- tools/perf/builtin-annotate.c | 2 +- tools/perf/builtin-report.c | 2 +- tools/perf/builtin-top.c | 2 +- tools/perf/util/symbol.c | 157 +++++++++++++++-------------------------- tools/perf/util/symbol.h | 2 +- tools/perf/util/thread.c | 115 +++++++++++++++++++++++------- tools/perf/util/thread.h | 15 +++- 7 files changed, 162 insertions(+), 133 deletions(-)
tools/perf/builtin-annotate.c +1 -1
@@ -167,7 +167,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) map ? map->dso->long_name : "<not found>"); }else if (event->header.misc &PERF_RECORD_MISC_USER ) { level ='.' ; - map =thread__find_map (thread, ip); + map =thread__find_map (thread,MAP__FUNCTION , ip);if (map !=NULL ) { ip = map->map_ip (map, ip); sym =map__find_symbol (map, ip, symbol_filter);
tools/perf/builtin-report.c +1 -1
@@ -422,7 +422,7 @@ resolve_symbol(struct thread *thread, struct map **mapp, u64 *ipp)if (!thread)return NULL ; - map =thread__find_map (thread, ip); + map =thread__find_map (thread,MAP__FUNCTION , ip);if (map !=NULL ) {/* * We have to do this here as we may have a dso
tools/perf/builtin-top.c +1 -1
@@ -945,7 +945,7 @@ static void event__process_sample(const event_t *self, int counter)if (thread ==NULL )return ; - map =thread__find_map (thread, ip); + map =thread__find_map (thread,MAP__FUNCTION , ip);if (map !=NULL ) { ip = map->map_ip (map, ip); sym =map__find_symbol (map, ip, symbol_filter);
tools/perf/util/symbol.c +58 -99
385 lines not on this page · raw message
tools/perf/util/symbol.h +1 -1
@@ -92,7 +92,7 @@ void dsos__fprintf(FILE *fp);size_t dsos__fprintf_buildid (FILE *fp);size_t dso__fprintf_buildid (struct dso *self,FILE *fp); -size_t dso__fprintf (struct dso *self,FILE *fp); +size_t dso__fprintf (struct dso *self,enum map_type type,FILE *fp);char dso__symtab_origin (const struct dso *self);void dso__set_build_id (struct dso *self,void *build_id);
tools/perf/util/thread.c +89 -26
176 lines not on this page · raw message
tools/perf/util/thread.h +11 -4
@@ -7,20 +7,22 @@struct thread {struct rb_node rb_node; -struct rb_root maps; -struct list_head removed_maps; +struct rb_root maps[MAP__NR_TYPES ]; +struct list_head removed_maps[MAP__NR_TYPES ];pid_t pid;char shortname[3 ];char *comm;int comm_len; }; +void thread__init (struct thread *self,pid_t pid);int thread__set_comm (struct thread *self,const char *comm);int thread__comm_len (struct thread *self);struct thread *threads__findnew (pid_t pid);struct thread *register_idle_thread (void );void thread__insert_map (struct thread *self,struct map *map);int thread__fork (struct thread *self,struct thread *parent); +size_t thread__fprintf_maps (struct thread *self,FILE *fp);size_t threads__fprintf (FILE *fp);void maps__insert (struct rb_root *maps,struct map *map);
@@ -29,9 +31,14 @@ struct map *maps__find(struct rb_root *maps, u64 ip);struct symbol *kernel_maps__find_function (const u64 ip,struct map **mapp,symbol_filter_t filter); -static inline struct map *thread__find_map (struct thread *self,u64 ip) +static inline struct map *thread__find_map (struct thread *self, +enum map_type type,u64 ip) { -return self ?maps__find (&self->maps, ip) :NULL ; +return self ?maps__find (&self->maps[type], ip) :NULL ; } +static inline void __thread__insert_map (struct thread *self,struct map *map) +{ +maps__insert (&self->maps[map->type], map); +}#endif /* __PERF_THREAD_H */
Signature · 1 line
1.6.2.5
PATCH 10/12 perf symbols: When not using modules, discard its symbols
From: Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/util/symbol.c | 6 +++++- tools/perf/util/thread.h | 1 + 2 files changed, 6 insertions(+), 1 deletions(-)
tools/perf/util/symbol.c +5 -1
@@ -381,6 +381,9 @@ static int dso__split_kallsyms(struct dso *self, struct map *map, struct thread module =strchr (pos->name,'\t' );if (module) { +if (!thread->use_modules) + goto discard_symbol; + *module++ ='\0' ;if (strcmp (self->name, module)) {
@@ -420,7 +423,7 @@ static int dso__split_kallsyms(struct dso *self, struct map *map, struct thread }if (filter &&filter (curr_map, pos)) { -rb_erase (&pos->rb_node, root); +discard_symbol:rb_erase (&pos->rb_node, root);symbol__delete (pos); }else {if (curr_map != map) {
@@ -1635,6 +1638,7 @@ int symbol__init(struct symbol_conf *conf)return -1 ; } + kthread->use_modules = pconf->use_modules;if (pconf->use_modules &&thread__create_module_maps (kthread) <0 )pr_debug ("Failed to load list of modules in use, " "continuing...\n" );
tools/perf/util/thread.h +1 -0
@@ -10,6 +10,7 @@ struct thread {struct rb_root maps[MAP__NR_TYPES ];struct list_head removed_maps[MAP__NR_TYPES ];pid_t pid; +bool use_modules;char shortname[3 ];char *comm;int comm_len;
Signature · 1 line
1.6.2.5
PATCH 11/12 perf tools: Reorganize event processing routines, lotsa dups killed
From: Arnaldo Carvalho de Melo <[email protected]>
While implementing event__preprocess_sample, that will do all of the symbol lookup in one convenient function, I noticed that util/process_event.[ch] were not being used at all, then started looking if there were other functions that could be shared and...
All those functions really don't need to receive offset + head, the only thing they did was common to all of them, so do it at one place instead.
Stats about number of each type of event processed now is done in a central place.
--- tools/perf/Makefile | 2 - tools/perf/builtin-annotate.c | 63 ++++++++------------------------ tools/perf/builtin-kmem.c | 33 ++--------------- tools/perf/builtin-report.c | 72 ++++++++++--------------------------- tools/perf/builtin-sched.c | 42 +++------------------- tools/perf/builtin-top.c | 19 ---------- tools/perf/builtin-trace.c | 40 +++------------------ tools/perf/util/data_map.c | 56 ++++++++++++++++++++++------- tools/perf/util/data_map.h | 2 +- tools/perf/util/event.c | 74 ++++++++++++++++++++++++++++++++++++++ tools/perf/util/event.h | 17 +++++++++ tools/perf/util/hist.c | 7 ---- tools/perf/util/process_event.c | 53 --------------------------- tools/perf/util/process_event.h | 29 --------------- tools/perf/util/process_events.c | 64 -------------------------------- tools/perf/util/process_events.h | 35 ------------------ 16 files changed, 183 insertions(+), 425 deletions(-) delete mode 100644 tools/perf/util/process_event.c delete mode 100644 tools/perf/util/process_event.h delete mode 100644 tools/perf/util/process_events.c delete mode 100644 tools/perf/util/process_events.h
tools/perf/Makefile +0 -2
@@ -369,7 +369,6 @@ LIB_H += util/sort.h LIB_H += util/hist.h LIB_H += util/thread.h LIB_H += util/data_map.h -LIB_H += util/process_events.h LIB_OBJS += util/abspath.o LIB_OBJS += util/alias.o
@@ -412,7 +411,6 @@ LIB_OBJS += util/svghelper.o LIB_OBJS += util/sort.o LIB_OBJS += util/hist.o LIB_OBJS += util/data_map.o -LIB_OBJS += util/process_events.o BUILTIN_OBJS += builtin-annotate.o
tools/perf/builtin-annotate.c +15 -48
129 lines not on this page · raw message
tools/perf/builtin-kmem.c +4 -29
@@ -33,9 +33,6 @@ static bool raw_ip;static char default_sort_order[] ="frag,hit,bytes" ; -static char *cwd; -static int cwdlen; -static int *cpunode_map;static int max_cpu_num;
@@ -126,25 +123,6 @@ static void setup_cpunode_map(void) } } -static int -process_comm_event (event_t *event,unsigned long offset,unsigned long head) -{ -struct thread *thread =threads__findnew (event->comm.pid); - -dump_printf ("%p [%p]: PERF_RECORD_COMM: %s:%d\n" , - (void *)(offset + head), - (void *)(long )(event->header.size), - event->comm.comm, event->comm.pid); - -if (thread ==NULL || -thread__set_comm (thread, event->comm.comm)) { -dump_printf ("problem processing PERF_RECORD_COMM, skipping event.\n" ); -return -1 ; - } - -return 0 ; -} -static void insert_alloc_stat (unsigned long call_site,unsigned long ptr,int bytes_req,int bytes_alloc,int cpu) {
@@ -340,8 +318,7 @@ process_raw_event(event_t *raw_event __used, void *more_data, } } -static int -process_sample_event (event_t *event,unsigned long offset,unsigned long head) +static int process_sample_event (event_t *event) {u64 ip = event->ip.ip;u64 timestamp =-1 ;
@@ -366,9 +343,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) more_data +=sizeof (u64); } - dump_printf("%p [%p]: PERF_RECORD_SAMPLE (IP, %d): %d/%d: %p period: %Ld\n", - (void *)(offset + head), - (void *)(long)(event->header.size), + dump_printf("(IP, %d): %d/%d: %p period: %Ld\n", event->header.misc, event->ip.pid, event->ip.tid, (void *)(long)ip,
@@ -403,7 +378,7 @@ static int sample_type_check(u64 type)static struct perf_file_handler file_handler = { .process_sample_event = process_sample_event, - .process_comm_event = process_comm_event, + .process_comm_event = event__process_comm, .sample_type_check = sample_type_check, };
@@ -413,7 +388,7 @@ static int read_events(void)register_perf_file_handler (&file_handler);return mmap_dispatch_perf_file (&header, input_name,0 ,0 , - &cwdlen, &cwd); + &event__cwdlen, &event__cwd); }static double fragmentation (unsigned long n_req,unsigned long n_alloc)
tools/perf/builtin-report.c +19 -53
142 lines not on this page · raw message
tools/perf/builtin-sched.c +5 -37
90 lines not on this page · raw message
tools/perf/builtin-top.c +0 -19
@@ -991,25 +991,6 @@ static void event__process_sample(const event_t *self, int counter) } } -static void event__process_mmap (event_t *self) -{ -struct thread *thread =threads__findnew (self->mmap.pid); - -if (thread !=NULL ) { -struct map *map =map__new (&self->mmap,MAP__FUNCTION ,NULL ,0 ); -if (map !=NULL ) -thread__insert_map (thread, map); - } -} - -static void event__process_comm (event_t *self) -{ -struct thread *thread =threads__findnew (self->comm.pid); - -if (thread !=NULL ) -thread__set_comm (thread, self->comm.comm); -} -static int event__process (event_t *event) {switch (event->header.type) {
tools/perf/builtin-trace.c +5 -35
@@ -16,38 +16,10 @@static char const *input_name ="perf.data" ; -static unsigned long total =0 ; -static unsigned long total_comm =0 ; -static struct perf_header *header;static u64 sample_type; -static char *cwd; -static int cwdlen; - - -static int -process_comm_event (event_t *event,unsigned long offset,unsigned long head) -{ -struct thread *thread =threads__findnew (event->comm.pid); - -dump_printf ("%p [%p]: PERF_RECORD_COMM: %s:%d\n" , - (void *)(offset + head), - (void *)(long )(event->header.size), - event->comm.comm, event->comm.pid); - -if (thread ==NULL || -thread__set_comm (thread, event->comm.comm)) { -dump_printf ("problem processing PERF_RECORD_COMM, skipping event.\n" ); -return -1 ; - } - total_comm++; - -return 0 ; -} - -static int -process_sample_event (event_t *event,unsigned long offset,unsigned long head) +static int process_sample_event (event_t *event) {u64 ip = event->ip.ip;u64 timestamp =-1 ;
@@ -72,9 +44,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head) more_data +=sizeof (u64); } - dump_printf("%p [%p]: PERF_RECORD_SAMPLE (IP, %d): %d/%d: %p period: %Ld\n", - (void *)(offset + head), - (void *)(long)(event->header.size), + dump_printf("(IP, %d): %d/%d: %p period: %Ld\n", event->header.misc, event->ip.pid, event->ip.tid, (void *)(long)ip,
@@ -101,7 +71,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)*/ print_event (cpu, raw->data, raw->size, timestamp, thread->comm); } - total += period; + event__stats.total += period;return 0 ; }
@@ -122,7 +92,7 @@ static int sample_type_check(u64 type)static struct perf_file_handler file_handler = { .process_sample_event = process_sample_event, - .process_comm_event = process_comm_event, + .process_comm_event = event__process_comm, .sample_type_check = sample_type_check, };
@@ -132,7 +102,7 @@ static int __cmd_trace(void)register_perf_file_handler (&file_handler);return mmap_dispatch_perf_file (&header, input_name, -0 ,0 , &cwdlen, &cwd); +0 ,0 , &event__cwdlen, &event__cwd); }static const char *const annotate_usage[] = {
tools/perf/util/data_map.c +43 -13
84 lines not on this page · raw message
tools/perf/util/data_map.h +1 -1
@@ -4,7 +4,7 @@#include "event.h" #include "header.h" -typedef int (*event_type_handler_t )(event_t *,unsigned long ,unsigned long ); +typedef int (*event_type_handler_t )(event_t *);struct perf_file_handler {event_type_handler_t process_sample_event;
tools/perf/util/event.c +74 -0
83 lines not on this page · raw message
tools/perf/util/event.h +17 -0
@@ -80,6 +80,13 @@ typedef union event_union {struct sample_event sample; } event_t; +struct events_stats { +unsigned long total; +unsigned long lost; +}; + +void event__print_totals (void ); +enum map_type {MAP__FUNCTION =0 ,
@@ -135,4 +142,14 @@ void map__fixup_end(struct map *self);int event__synthesize_thread (pid_t pid,int (*process)(event_t *event));void event__synthesize_threads (int (*process)(event_t *event)); +extern char *event__cwd; +extern int event__cwdlen; +extern struct events_stats event__stats; +extern unsigned long event__total[PERF_RECORD_MAX ]; + +int event__process_comm (event_t *self); +int event__process_lost (event_t *self); +int event__process_mmap (event_t *self); +int event__process_task (event_t *self); +#endif /* __PERF_RECORD_H */
tools/perf/util/hist.c +0 -7
@@ -10,13 +10,6 @@ struct callchain_param callchain_param = { .min_percent = 0.5 }; -unsigned long total; -unsigned long total_mmap; -unsigned long total_comm; -unsigned long total_fork; -unsigned long total_unknown; -unsigned long total_lost; -/* * histogram, sorted on item, collects counts */
tools/perf/util/process_event.c deleted +0 -53
53 lines not on this page · raw message
tools/perf/util/process_event.h deleted +0 -29
@@ -1,29 +0,0 @@ -#ifndef __PROCESS_EVENT_H -#define __PROCESS_EVENT_H - -#include "../builtin.h" -#include "util.h" - -#include "color.h" -#include <linux/list.h> -#include "cache.h" -#include <linux/rbtree.h> -#include "symbol.h" -#include "string.h" - -#include "../perf.h" -#include "debug.h" - -#include "parse-options.h" -#include "parse-events.h" - -#include "thread.h" -#include "sort.h" -#include "hist.h" - -extern char *cwd; -extern int cwdlen; -extern int process_mmap_event (event_t *,unsigned long ,unsigned long ); -extern int process_comm_event (event_t *,unsigned long ,unsigned long ); - -#endif /* __PROCESS_H */
tools/perf/util/process_events.c deleted +0 -64
64 lines not on this page · raw message
tools/perf/util/process_events.h deleted +0 -35
@@ -1,35 +0,0 @@ -#ifndef __PROCESS_EVENTS_H -#define __PROCESS_EVENTS_H - -#include "../builtin.h" - -#include "util.h" -#include "color.h" -#include <linux/list.h> -#include "cache.h" -#include <linux/rbtree.h> -#include "symbol.h" -#include "string.h" -#include "callchain.h" -#include "strlist.h" -#include "values.h" - -#include "../perf.h" -#include "debug.h" -#include "header.h" - -#include "parse-options.h" -#include "parse-events.h" - -#include "data_map.h" -#include "thread.h" -#include "sort.h" -#include "hist.h" - -extern char *cwd; -extern int cwdlen; - -extern int process_mmap_event (event_t *,unsigned long ,unsigned long ); -extern int process_task_event (event_t *,unsigned long ,unsigned long ); - -#endif /* __PROCESS_EVENTS_H */
Signature · 1 line
1.6.2.5
PATCH 12/12 perf tools: Consolidate symbol resolving across all tools
From: Arnaldo Carvalho de Melo <[email protected]>
Now we have a very high level routine for simple tools to process IP sample events:
int event__preprocess_sample(const event_t *self,
struct addr_location *al, symbol_filter_t filter)
It receives the event itself and will insert new threads in the global threads list and resolve the map and symbol, filling all this info into the new addr_location struct, so that tools like annotate and report can further process the event by creating hist_entries in their specific way (with or without callgraphs, etc).
It in turn uses the new next layer function:
void thread__find_addr_location(struct thread *self, u8 cpumode,
enum map_type type, u64 addr, struct addr_location *al, symbol_filter_t filter)
This one will, given a thread (userspace or the kernel kthread one), will find the given type (MAP__FUNCTION now, MAP__VARIABLE too in the near future) at the given cpumode, taking vdsos into account (userspace hit, but kernel symbol) and will fill all these details in the addr_location given.
Tools that need a more compact API for plain function resolution, like 'kmem', can use this other one:
struct symbol *thread__find_function(struct thread *self, u64 addr,
symbol_filter_t filter)
So, to resolve a kernel symbol, that is all the 'kmem' tool needs, its just a matter of calling:
sym = thread__find_function(kthread, addr, NULL);
The 'filter' parameter is needed because we do lazy parsing/loading of ELF symtabs or /proc/kallsyms.
With this we remove more code duplication all around, which is always good, huh? :-)
--- tools/perf/builtin-annotate.c | 55 ++--------------- tools/perf/builtin-kmem.c | 2 +- tools/perf/builtin-report.c | 135 ++++++++++++----------------------------- tools/perf/builtin-top.c | 44 +++----------- tools/perf/util/event.c | 62 +++++++++++++++++++ tools/perf/util/event.h | 4 + tools/perf/util/hist.c | 15 ++--- tools/perf/util/hist.h | 6 +- tools/perf/util/symbol.c | 26 +------- tools/perf/util/symbol.h | 10 +++ tools/perf/util/thread.c | 12 ++++ tools/perf/util/thread.h | 23 +++++-- 12 files changed, 172 insertions(+), 222 deletions(-)
tools/perf/builtin-annotate.c +7 -48
@@ -124,71 +124,30 @@ static void hist_hit(struct hist_entry *he, u64 ip) h->ip[offset]); } -static int hist_entry__add (struct thread *thread,struct map *map, -struct symbol *sym,u64 ip,u64 count,char level) +static int hist_entry__add (struct addr_location *al,u64 count) {bool hit; -struct hist_entry *he =__hist_entry__add (thread, map, sym,NULL , ip, - count, level, &hit); +struct hist_entry *he =__hist_entry__add (al,NULL , count, &hit);if (he ==NULL )return -ENOMEM ; -hist_hit (he, ip); +hist_hit (he, al->addr);return 0 ; }static int process_sample_event (event_t *event) { -char level; -u64 ip = event->ip.ip; -struct map *map =NULL ; -struct symbol *sym =NULL ; -struct thread *thread =threads__findnew (event->ip.pid); +struct addr_location al;dump_printf ("(IP, %d): %d: %p\n" , event->header.misc, - event->ip.pid, (void *)(long )ip); + event->ip.pid, (void *)(long )event->ip.ip); -if (thread ==NULL ) { +if (event__preprocess_sample (event, &al, symbol_filter) <0 ) {fprintf (stderr,"problem processing %d event, skipping it.\n" , event->header.type);return -1 ; } -dump_printf (" ... thread: %s:%d\n" , thread->comm, thread->pid); - -if (event->header.misc &PERF_RECORD_MISC_KERNEL ) { - level ='k' ; - sym =kernel_maps__find_function (ip, &map, symbol_filter); -dump_printf (" ...... dso: %s\n" , - map ? map->dso->long_name :"<not found>" ); - }else if (event->header.misc &PERF_RECORD_MISC_USER ) { - level ='.' ; - map =thread__find_map (thread,MAP__FUNCTION , ip); -if (map !=NULL ) { - ip = map->map_ip (map, ip); - sym =map__find_symbol (map, ip, symbol_filter); - }else { -/* -* If this is outside of all known maps, -* and is a negative address, try to look it -* up in the kernel dso, as it might be a -* vsyscall or vdso (which executes in user-mode). -* -* XXX This is nasty, we should have a symbol list in -* the "[vdso]" dso, but for now lets use the old -* trick of looking in the whole kernel symbol list. -*/ -if ((long long )ip <0 ) - sym =kernel_maps__find_function (ip, &map, - symbol_filter); - } -dump_printf (" ...... dso: %s\n" , - map ? map->dso->long_name :"<not found>" ); - }else { - level ='H' ; -dump_printf (" ...... dso: [hypervisor]\n" ); - } - -if (hist_entry__add (thread, map, sym, ip,1 , level)) { +if (hist_entry__add (&al,1 )) {fprintf (stderr,"problem incrementing symbol count, " "skipping event\n" );return -1 ;
tools/perf/builtin-kmem.c +1 -1
@@ -420,7 +420,7 @@ static void __print_result(struct rb_root *root, int n_lines, int is_caller)if (is_caller) { addr = data->call_site;if (!raw_ip) - sym =kernel_maps__find_function (addr,NULL ,NULL ); + sym =thread__find_function (kthread, addr,NULL ); }else addr = data->ptr;
tools/perf/builtin-report.c +38 -97
196 lines not on this page · raw message
tools/perf/builtin-top.c +9 -35
72 lines not on this page · raw message
tools/perf/util/event.c +62 -0
65 lines not on this page · raw message
tools/perf/util/event.h +4 -0
@@ -152,4 +152,8 @@ int event__process_lost(event_t *self);int event__process_mmap (event_t *self);int event__process_task (event_t *self); +struct addr_location ; +int event__preprocess_sample (const event_t *self,struct addr_location *al, +symbol_filter_t filter); +#endif /* __PERF_RECORD_H */
tools/perf/util/hist.c +7 -8
@@ -14,20 +14,19 @@ struct callchain_param callchain_param = {* histogram, sorted on item, collects counts */ -struct hist_entry *__hist_entry__add (struct thread *thread,struct map *map, -struct symbol *sym, +struct hist_entry *__hist_entry__add (struct addr_location *al,struct symbol *sym_parent, -u64 ip,u64 count,char level,bool *hit) +u64 count,bool *hit) {struct rb_node **p = &hist.rb_node;struct rb_node *parent =NULL ;struct hist_entry *he;struct hist_entry entry = { - .thread = thread, - .map = map, - .sym = sym, - .ip = ip, - .level = level, + .thread = al->thread, + .map = al->map, + .sym = al->sym, + .ip = al->addr, + .level = al->level, .count = count, .parent = sym_parent, };
tools/perf/util/hist.h +3 -3
@@ -36,9 +36,9 @@ extern unsigned long total_fork;extern unsigned long total_unknown;extern unsigned long total_lost; -struct hist_entry *__hist_entry__add (struct thread *thread,struct map *map, -struct symbol *sym,struct symbol *parent, -u64 ip,u64 count,char level,bool *hit); +struct hist_entry *__hist_entry__add (struct addr_location *al, +struct symbol *parent, +u64 count,bool *hit);extern int64_t hist_entry__cmp (struct hist_entry *,struct hist_entry *);extern int64_t hist_entry__collapse (struct hist_entry *,struct hist_entry *);extern void hist_entry__free (struct hist_entry *);
tools/perf/util/symbol.c +2 -24
@@ -43,7 +43,8 @@ static struct symbol_conf symbol_conf__defaults = { .try_vmlinux_path = true, }; -static struct thread kthread_mem, *kthread = &kthread_mem; +static struct thread kthread_mem; +struct thread *kthread = &kthread_mem;bool dso__loaded (const struct dso *self,enum map_type type) {
@@ -1178,29 +1179,6 @@ out:return ret; } -static struct symbol *thread__find_symbol (struct thread *self,u64 ip, -enum map_type type,struct map **mapp, -symbol_filter_t filter) -{ -struct map *map =thread__find_map (self, type, ip); - -if (mapp) - *mapp = map; - -if (map) { - ip = map->map_ip (map, ip); -return map__find_symbol (map, ip, filter); - } - -return NULL ; -} - -struct symbol *kernel_maps__find_function (u64 ip,struct map **mapp, -symbol_filter_t filter) -{ -return thread__find_symbol (kthread, ip,MAP__FUNCTION , mapp, filter); -} -static struct map *thread__find_map_by_name (struct thread *self,char *name) {struct rb_node *nd;
tools/perf/util/symbol.h +10 -0
@@ -63,6 +63,14 @@ static inline void *symbol__priv(struct symbol *self)return ((void *)self) - symbol__priv_size; } +struct addr_location { +struct thread *thread; +struct map *map; +struct symbol *sym; +u64 addr; +char level; +}; +struct dso {struct list_head node;struct rb_root symbols[MAP__NR_TYPES ];
@@ -105,6 +113,8 @@ size_t kernel_maps__fprintf(FILE *fp);int symbol__init (struct symbol_conf *conf); +struct thread ; +struct thread *kthread;extern struct list_head dsos__user, dsos__kernel;extern struct dso *vdso;#endif /* __PERF_SYMBOL */
tools/perf/util/thread.c +12 -0
@@ -285,3 +285,15 @@ size_t threads__fprintf(FILE *fp)return ret; } + +struct symbol *thread__find_symbol (struct thread *self, +enum map_type type,u64 addr, +symbol_filter_t filter) +{ +struct map *map =thread__find_map (self, type, addr); + +if (map !=NULL ) +return map__find_symbol (map, map->map_ip (map, addr), filter); + +return NULL ; +}
tools/perf/util/thread.h +17 -6
@@ -27,19 +27,30 @@ size_t thread__fprintf_maps(struct thread *self, FILE *fp);size_t threads__fprintf (FILE *fp);void maps__insert (struct rb_root *maps,struct map *map); -struct map *maps__find (struct rb_root *maps,u64 ip); - -struct symbol *kernel_maps__find_function (const u64 ip,struct map **mapp, -symbol_filter_t filter); +struct map *maps__find (struct rb_root *maps,u64 addr);static inline struct map *thread__find_map (struct thread *self, -enum map_type type,u64 ip) +enum map_type type,u64 addr) { -return self ?maps__find (&self->maps[type], ip) :NULL ; +return self ?maps__find (&self->maps[type], addr) :NULL ; }static inline void __thread__insert_map (struct thread *self,struct map *map) {maps__insert (&self->maps[map->type], map); } + +void thread__find_addr_location (struct thread *self,u8 cpumode, +enum map_type type,u64 addr, +struct addr_location *al, +symbol_filter_t filter); +struct symbol *thread__find_symbol (struct thread *self, +enum map_type type,u64 addr, +symbol_filter_t filter); + +static inline struct symbol * +thread__find_function (struct thread *self,u64 addr,symbol_filter_t filter) +{ +return thread__find_symbol (self,MAP__FUNCTION , addr, filter); +}#endif /* __PERF_THREAD_H */
Signature · 1 line
1.6.2.5