perf symbols: Move more map_groups methods to map.c
PATCH 1/3 perf symbols: Move more map_groups methods to map.c
From: Arnaldo Carvalho de Melo <[email protected]>
While writing a standalone test app that uses the symbol system to find kernel space symbols I noticed these also need to be moved.
--- tools/perf/util/hist.c | 2 +- tools/perf/util/map.c | 168 +++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/map.h | 11 +++- tools/perf/util/thread.c | 169 +--------------------------------------------- 4 files changed, 180 insertions(+), 170 deletions(-)
tools/perf/util/hist.c +1 -1
@@ -658,7 +658,7 @@ print_entries:if (h->ms.map ==NULL && verbose >1 ) {__map_groups__fprintf_maps (&h->thread->mg, -MAP__FUNCTION , fp); +MAP__FUNCTION , verbose, fp);fprintf (fp,"%.10s end\n" , graph_dotted_line); } }
tools/perf/util/map.c +168 -0
184 lines not on this page · raw message
tools/perf/util/map.h +9 -2
@@ -97,11 +97,14 @@ struct map_groups { };size_t __map_groups__fprintf_maps (struct map_groups *self, -enum map_type type,FILE *fp); +enum map_type type,int verbose,FILE *fp);void maps__insert (struct rb_root *maps,struct map *map);struct map *maps__find (struct rb_root *maps,u64 addr);void map_groups__init (struct map_groups *self); -size_t map_groups__fprintf_maps (struct map_groups *self,FILE *fp); +int map_groups__clone (struct map_groups *self, +struct map_groups *parent,enum map_type type); +size_t map_groups__fprintf (struct map_groups *self,int verbose,FILE *fp); +size_t map_groups__fprintf_maps (struct map_groups *self,int verbose,FILE *fp);static inline void map_groups__insert (struct map_groups *self,struct map *map) {
@@ -125,6 +128,9 @@ static inline struct symbol *map_groups__find_function(struct map_groups *self,return map_groups__find_symbol (self,MAP__FUNCTION , addr, filter); } +int map_groups__fixup_overlappings (struct map_groups *self,struct map *map, +int verbose,FILE *fp); +struct map *map_groups__find_by_name (struct map_groups *self,enum map_type type,const char *name); int __map_groups__create_kernel_maps(struct map_groups *self,
@@ -134,5 +140,6 @@ int map_groups__create_kernel_maps(struct map_groups *self, struct map *vmlinux_maps[MAP__NR_TYPES]);struct map *map_groups__new_module (struct map_groups *self,u64 start,const char *filename); +void map_groups__flush (struct map_groups *self);#endif /* __PERF_MAP_H */
tools/perf/util/thread.c +2 -167
201 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 2/3 perf symbols: map_groups__find_symbol must return the map too
From: Arnaldo Carvalho de Melo <[email protected]>
Tools need to know from which map in the map_group a symbol was resolved to, so that, for isntance, we can annotate kernel modules symbols by getting its precise name, etc.
Also add the _by_name variants for completeness.
--- tools/perf/builtin-kmem.c | 3 ++- tools/perf/util/map.c | 28 +++++++++++++++++++++++++++- tools/perf/util/map.h | 23 +++++++++++++++++++---- 3 files changed, 48 insertions(+), 6 deletions(-)
tools/perf/builtin-kmem.c +2 -1
@@ -369,7 +369,8 @@ static void __print_result(struct rb_root *root, struct perf_session *session,if (is_caller) { addr = data->call_site;if (!raw_ip) - sym =map_groups__find_function (&session->kmaps, addr,NULL ); + sym =map_groups__find_function (&session->kmaps, + addr,NULL ,NULL ); }else addr = data->ptr;
tools/perf/util/map.c +27 -1
@@ -268,12 +268,38 @@ void map_groups__flush(struct map_groups *self)struct symbol *map_groups__find_symbol (struct map_groups *self,enum map_type type,u64 addr, +struct map **mapp,symbol_filter_t filter) {struct map *map =map_groups__find (self, type, addr); -if (map !=NULL ) +if (map !=NULL ) { +if (mapp !=NULL ) + *mapp = map;return map__find_symbol (map, map->map_ip (map, addr), filter); + } + +return NULL ; +} + +struct symbol *map_groups__find_symbol_by_name (struct map_groups *self, +enum map_type type, +const char *name, +struct map **mapp, +symbol_filter_t filter) +{ +struct rb_node *nd; + +for (nd =rb_first (&self->maps[type]); nd; nd =rb_next (nd)) { + struct map *pos = rb_entry(nd, struct map, rb_node); +struct symbol *sym =map__find_symbol_by_name (pos, name, filter); + +if (sym ==NULL ) +continue ; +if (mapp !=NULL ) + *mapp = pos; +return sym; + }return NULL ; }
tools/perf/util/map.h +19 -4
@@ -119,13 +119,28 @@ static inline struct map *map_groups__find(struct map_groups *self,struct symbol *map_groups__find_symbol (struct map_groups *self,enum map_type type,u64 addr, +struct map **mapp,symbol_filter_t filter); -static inline struct symbol *map_groups__find_function (struct map_groups *self, -u64 addr, -symbol_filter_t filter) +struct symbol *map_groups__find_symbol_by_name (struct map_groups *self, +enum map_type type, +const char *name, +struct map **mapp, +symbol_filter_t filter); + +static inline +struct symbol *map_groups__find_function (struct map_groups *self,u64 addr, +struct map **mapp,symbol_filter_t filter) +{ +return map_groups__find_symbol (self,MAP__FUNCTION , addr, mapp, filter); +} + +static inline +struct symbol *map_groups__find_function_by_name (struct map_groups *self, +const char *name,struct map **mapp, +symbol_filter_t filter) { -return map_groups__find_symbol (self,MAP__FUNCTION , addr, filter); +return map_groups__find_symbol_by_name (self,MAP__FUNCTION , name, mapp, filter); } int map_groups__fixup_overlappings(struct map_groups *self, struct map *map,
Signature · 1 line
1.6.2.5
PATCH 3/3 perf tools: Move the prototypes in util/string.h to util.h
In reply to Arnaldo Carvalho de MeloFrom: Arnaldo Carvalho de Melo <[email protected]>
So that we avoid conflict with libc's string.h header.
--- tools/perf/Makefile | 1 - tools/perf/bench/mem-memcpy.c | 1 - tools/perf/builtin-annotate.c | 1 - tools/perf/builtin-record.c | 1 - tools/perf/builtin-report.c | 1 - tools/perf/builtin-timechart.c | 1 - tools/perf/perf.c | 1 - tools/perf/util/string.h | 16 ---------------- tools/perf/util/util.h | 11 +++++++++++ 9 files changed, 11 insertions(+), 23 deletions(-) delete mode 100644 tools/perf/util/string.h
tools/perf/Makefile +0 -1
@@ -377,7 +377,6 @@ LIB_H += util/header.h LIB_H += util/help.h LIB_H += util/session.h LIB_H += util/strbuf.h -LIB_H += util/string.h LIB_H += util/strlist.h LIB_H += util/svghelper.h LIB_H += util/run-command.h
tools/perf/bench/mem-memcpy.c +0 -1
@@ -10,7 +10,6 @@#include "../perf.h" #include "../util/util.h" #include "../util/parse-options.h" -#include "../util/string.h" #include "../util/header.h" #include "bench.h"
tools/perf/builtin-annotate.c +0 -1
@@ -14,7 +14,6 @@#include "util/cache.h" #include <linux/rbtree.h> #include "util/symbol.h" -#include "util/string.h" #include "perf.h" #include "util/debug.h"
tools/perf/builtin-record.c +0 -1
@@ -15,7 +15,6 @@#include "util/util.h" #include "util/parse-options.h" #include "util/parse-events.h" -#include "util/string.h" #include "util/header.h" #include "util/event.h"
tools/perf/builtin-report.c +0 -1
@@ -14,7 +14,6 @@#include "util/cache.h" #include <linux/rbtree.h> #include "util/symbol.h" -#include "util/string.h" #include "util/callchain.h" #include "util/strlist.h" #include "util/values.h"
tools/perf/builtin-timechart.c +0 -1
@@ -21,7 +21,6 @@#include "util/cache.h" #include <linux/rbtree.h> #include "util/symbol.h" -#include "util/string.h" #include "util/callchain.h" #include "util/strlist.h"
tools/perf/perf.c +0 -1
@@ -13,7 +13,6 @@#include "util/quote.h" #include "util/run-command.h" #include "util/parse-events.h" -#include "util/string.h" #include "util/debugfs.h" bool use_browser;
tools/perf/util/string.h deleted +0 -16
@@ -1,16 +0,0 @@ -#ifndef __PERF_STRING_H_ -#define __PERF_STRING_H_ - -#include <stdbool.h> -#include "types.h" - -s64 perf_atoll (const char *str); -char **argv_split (const char *str,int *argcp); -void argv_free (char **argv); -bool strglobmatch (const char *str,const char *pat); -bool strlazymatch (const char *str,const char *pat); - -#define _STR (x) #x -#define STR (x) _STR(x) - -#endif /* __PERF_STRING_H */
tools/perf/util/util.h +11 -0
@@ -48,6 +48,7 @@#include <sys/stat.h> #include <sys/statfs.h> #include <fcntl.h> +#include <stdbool.h> #include <stddef.h> #include <stdlib.h> #include <stdarg.h>
@@ -78,6 +79,7 @@#include <pwd.h> #include <inttypes.h> #include "../../../include/linux/magic.h" +#include "types.h" #ifndef NO_ICONV
@@ -415,4 +417,13 @@ void git_qsort(void *base, size_t nmemb, size_t size,int mkdir_p (char *path,mode_t mode);int copyfile (const char *from,const char *to); +s64 perf_atoll (const char *str); +char **argv_split (const char *str,int *argcp); +void argv_free (char **argv); +bool strglobmatch (const char *str,const char *pat); +bool strlazymatch (const char *str,const char *pat); + +#define _STR (x) #x +#define STR (x) _STR(x) +#endif
Signature · 1 line
1.6.2.5
Re: [PATCH 3/3] perf tools: Move the prototypes in util/string.h to util.h
Quoted 11 lines
From: Arnaldo Carvalho de Melo <[email protected]>
So that we avoid conflict with libc's
string.hheader.Suggested-by KOSAKI Motohiro <[email protected]>Cc KOSAKI Motohiro <[email protected]>Cc Frédéric Weisbecker <[email protected]>Cc Mike Galbraith <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Paul Mackerras <[email protected]>Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
Thank you. I like this :)