diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-01-16 14:40:25 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-01-21 08:06:15 -0500 |
commit | 0a3873a8e2709ebc759361e2d872d9f71541806c (patch) | |
tree | 735b7be4757a8af9f4b5fd8363440c9cdeb980fc /tools | |
parent | 564c62a4d7f9a4b60920ee0b02cfe890471d87f4 (diff) |
perf symbols: Introduce 'for' method to iterate over the symbols with a given name
Removing boilerplate from two places, where one would have to find the
first entry, then iterate using symbol__next_by_name + strcmp to see if
the next member had the same name.
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Link: http://lkml.kernel.org/n/tip-eh73z8gthv20yowirmx2yk38@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/map.h | 16 | ||||
-rw-r--r-- | tools/perf/util/probe-event.c | 14 |
2 files changed, 19 insertions, 11 deletions
diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 6951a9d42339..0e42438b1e59 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h | |||
@@ -116,6 +116,22 @@ struct thread; | |||
116 | #define map__for_each_symbol(map, pos, n) \ | 116 | #define map__for_each_symbol(map, pos, n) \ |
117 | dso__for_each_symbol(map->dso, pos, n, map->type) | 117 | dso__for_each_symbol(map->dso, pos, n, map->type) |
118 | 118 | ||
119 | /* map__for_each_symbol_with_name - iterate over the symbols in the given map | ||
120 | * that have the given name | ||
121 | * | ||
122 | * @map: the 'struct map *' in which symbols itereated | ||
123 | * @sym_name: the symbol name | ||
124 | * @pos: the 'struct symbol *' to use as a loop cursor | ||
125 | * @filter: to use when loading the DSO | ||
126 | */ | ||
127 | #define __map__for_each_symbol_by_name(map, sym_name, pos, filter) \ | ||
128 | for (pos = map__find_symbol_by_name(map, sym_name, filter); \ | ||
129 | pos && strcmp(pos->name, sym_name) == 0; \ | ||
130 | pos = symbol__next_by_name(pos)) | ||
131 | |||
132 | #define map__for_each_symbol_by_name(map, sym_name, pos) \ | ||
133 | __map__for_each_symbol_by_name(map, sym_name, (pos), NULL) | ||
134 | |||
119 | typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); | 135 | typedef int (*symbol_filter_t)(struct map *map, struct symbol *sym); |
120 | 136 | ||
121 | void map__init(struct map *map, enum map_type type, | 137 | void map__init(struct map *map, enum map_type type, |
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c index b24482e54451..7cc89b15fdb0 100644 --- a/tools/perf/util/probe-event.c +++ b/tools/perf/util/probe-event.c | |||
@@ -2196,14 +2196,11 @@ static int __add_probe_trace_events(struct perf_probe_event *pev, | |||
2196 | static int find_probe_functions(struct map *map, char *name) | 2196 | static int find_probe_functions(struct map *map, char *name) |
2197 | { | 2197 | { |
2198 | int found = 0; | 2198 | int found = 0; |
2199 | struct symbol *sym = map__find_symbol_by_name(map, name, NULL); | 2199 | struct symbol *sym; |
2200 | 2200 | ||
2201 | while (sym != NULL) { | 2201 | map__for_each_symbol_by_name(map, name, sym) { |
2202 | if (sym->binding == STB_GLOBAL || sym->binding == STB_LOCAL) | 2202 | if (sym->binding == STB_GLOBAL || sym->binding == STB_LOCAL) |
2203 | found++; | 2203 | found++; |
2204 | sym = symbol__next_by_name(sym); | ||
2205 | if (sym == NULL || strcmp(sym->name, name)) | ||
2206 | break; | ||
2207 | } | 2204 | } |
2208 | 2205 | ||
2209 | return found; | 2206 | return found; |
@@ -2275,9 +2272,8 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev, | |||
2275 | } | 2272 | } |
2276 | 2273 | ||
2277 | ret = 0; | 2274 | ret = 0; |
2278 | sym = map__find_symbol_by_name(map, pp->function, NULL); | ||
2279 | 2275 | ||
2280 | while (sym != NULL) { | 2276 | map__for_each_symbol_by_name(map, pp->function, sym) { |
2281 | tev = (*tevs) + ret; | 2277 | tev = (*tevs) + ret; |
2282 | tp = &tev->point; | 2278 | tp = &tev->point; |
2283 | if (ret == num_matched_functions) { | 2279 | if (ret == num_matched_functions) { |
@@ -2325,10 +2321,6 @@ static int find_probe_trace_events_from_map(struct perf_probe_event *pev, | |||
2325 | strdup_or_goto(pev->args[i].type, | 2321 | strdup_or_goto(pev->args[i].type, |
2326 | nomem_out); | 2322 | nomem_out); |
2327 | } | 2323 | } |
2328 | |||
2329 | sym = symbol__next_by_name(sym); | ||
2330 | if (sym == NULL || strcmp(sym->name, pp->function)) | ||
2331 | break; | ||
2332 | } | 2324 | } |
2333 | 2325 | ||
2334 | out: | 2326 | out: |