perf symbols: map_groups__find_symbol must return the map too
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 26 Mar 2010 15:30:40 +0000 (12:30 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 2 Apr 2010 19:27:43 +0000 (16:27 -0300)
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.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-kmem.c
tools/perf/util/map.c
tools/perf/util/map.h

index 924a9518931ade8eb51e17eb36fc38024c556c79..32edb6a86876a748bbde8012be517062ef7e6cbc 100644 (file)
@@ -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;
 
index e21f98001734a2dcc92c464244caa6e97633ee78..37913b241bdf1bca14fa13d4ec4ff3362e70b971 100644 (file)
@@ -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;
 }
index 4e7a11da8ffe687342dbd8a37dbe1f8e4ee082e6..2031278cc06aeebd83faae683a0c5232b8b8ebce 100644 (file)
@@ -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,