diff options
| -rw-r--r-- | tools/perf/util/map.c | 27 | ||||
| -rw-r--r-- | tools/perf/util/map.h | 2 | ||||
| -rw-r--r-- | tools/perf/util/symbol.c | 15 |
3 files changed, 42 insertions, 2 deletions
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index 354e54550d2b..781eed8e3265 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include "unwind.h" | 21 | #include "unwind.h" |
| 22 | 22 | ||
| 23 | static void __maps__insert(struct maps *maps, struct map *map); | 23 | static void __maps__insert(struct maps *maps, struct map *map); |
| 24 | static void __maps__insert_name(struct maps *maps, struct map *map); | ||
| 24 | 25 | ||
| 25 | static inline int is_anon_memory(const char *filename, u32 flags) | 26 | static inline int is_anon_memory(const char *filename, u32 flags) |
| 26 | { | 27 | { |
| @@ -496,6 +497,7 @@ u64 map__objdump_2mem(struct map *map, u64 ip) | |||
| 496 | static void maps__init(struct maps *maps) | 497 | static void maps__init(struct maps *maps) |
| 497 | { | 498 | { |
| 498 | maps->entries = RB_ROOT; | 499 | maps->entries = RB_ROOT; |
| 500 | maps->names = RB_ROOT; | ||
| 499 | init_rwsem(&maps->lock); | 501 | init_rwsem(&maps->lock); |
| 500 | } | 502 | } |
| 501 | 503 | ||
| @@ -664,6 +666,7 @@ size_t map_groups__fprintf(struct map_groups *mg, FILE *fp) | |||
| 664 | static void __map_groups__insert(struct map_groups *mg, struct map *map) | 666 | static void __map_groups__insert(struct map_groups *mg, struct map *map) |
| 665 | { | 667 | { |
| 666 | __maps__insert(&mg->maps, map); | 668 | __maps__insert(&mg->maps, map); |
| 669 | __maps__insert_name(&mg->maps, map); | ||
| 667 | map->groups = mg; | 670 | map->groups = mg; |
| 668 | } | 671 | } |
| 669 | 672 | ||
| @@ -824,10 +827,34 @@ static void __maps__insert(struct maps *maps, struct map *map) | |||
| 824 | map__get(map); | 827 | map__get(map); |
| 825 | } | 828 | } |
| 826 | 829 | ||
| 830 | static void __maps__insert_name(struct maps *maps, struct map *map) | ||
| 831 | { | ||
| 832 | struct rb_node **p = &maps->names.rb_node; | ||
| 833 | struct rb_node *parent = NULL; | ||
| 834 | struct map *m; | ||
| 835 | int rc; | ||
| 836 | |||
| 837 | while (*p != NULL) { | ||
| 838 | parent = *p; | ||
| 839 | m = rb_entry(parent, struct map, rb_node_name); | ||
| 840 | rc = strcmp(m->dso->short_name, map->dso->short_name); | ||
| 841 | if (rc < 0) | ||
| 842 | p = &(*p)->rb_left; | ||
| 843 | else if (rc > 0) | ||
| 844 | p = &(*p)->rb_right; | ||
| 845 | else | ||
| 846 | return; | ||
| 847 | } | ||
| 848 | rb_link_node(&map->rb_node_name, parent, p); | ||
| 849 | rb_insert_color(&map->rb_node_name, &maps->names); | ||
| 850 | map__get(map); | ||
| 851 | } | ||
| 852 | |||
| 827 | void maps__insert(struct maps *maps, struct map *map) | 853 | void maps__insert(struct maps *maps, struct map *map) |
| 828 | { | 854 | { |
| 829 | down_write(&maps->lock); | 855 | down_write(&maps->lock); |
| 830 | __maps__insert(maps, map); | 856 | __maps__insert(maps, map); |
| 857 | __maps__insert_name(maps, map); | ||
| 831 | up_write(&maps->lock); | 858 | up_write(&maps->lock); |
| 832 | } | 859 | } |
| 833 | 860 | ||
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index e0f327b51e66..5c792c90fc4c 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h | |||
| @@ -25,6 +25,7 @@ struct map { | |||
| 25 | struct rb_node rb_node; | 25 | struct rb_node rb_node; |
| 26 | struct list_head node; | 26 | struct list_head node; |
| 27 | }; | 27 | }; |
| 28 | struct rb_node rb_node_name; | ||
| 28 | u64 start; | 29 | u64 start; |
| 29 | u64 end; | 30 | u64 end; |
| 30 | bool erange_warned; | 31 | bool erange_warned; |
| @@ -57,6 +58,7 @@ struct kmap { | |||
| 57 | 58 | ||
| 58 | struct maps { | 59 | struct maps { |
| 59 | struct rb_root entries; | 60 | struct rb_root entries; |
| 61 | struct rb_root names; | ||
| 60 | struct rw_semaphore lock; | 62 | struct rw_semaphore lock; |
| 61 | }; | 63 | }; |
| 62 | 64 | ||
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index d188b7588152..dcce74bae6de 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c | |||
| @@ -1680,11 +1680,22 @@ struct map *map_groups__find_by_name(struct map_groups *mg, const char *name) | |||
| 1680 | { | 1680 | { |
| 1681 | struct maps *maps = &mg->maps; | 1681 | struct maps *maps = &mg->maps; |
| 1682 | struct map *map; | 1682 | struct map *map; |
| 1683 | struct rb_node *node; | ||
| 1683 | 1684 | ||
| 1684 | down_read(&maps->lock); | 1685 | down_read(&maps->lock); |
| 1685 | 1686 | ||
| 1686 | for (map = maps__first(maps); map; map = map__next(map)) { | 1687 | for (node = maps->names.rb_node; node; ) { |
| 1687 | if (map->dso && strcmp(map->dso->short_name, name) == 0) | 1688 | int rc; |
| 1689 | |||
| 1690 | map = rb_entry(node, struct map, rb_node_name); | ||
| 1691 | |||
| 1692 | rc = strcmp(map->dso->short_name, name); | ||
| 1693 | if (rc < 0) | ||
| 1694 | node = node->rb_left; | ||
| 1695 | else if (rc > 0) | ||
| 1696 | node = node->rb_right; | ||
| 1697 | else | ||
| 1698 | |||
| 1688 | goto out_unlock; | 1699 | goto out_unlock; |
| 1689 | } | 1700 | } |
| 1690 | 1701 | ||
