diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2009-11-27 13:29:23 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-11-27 14:22:02 -0500 |
commit | 1ed091c45ae33b2179d387573c3fe3f3b4adf60a (patch) | |
tree | d2b689de158e5a11673b5f0d08b491d243768138 /tools/perf/util/event.c | |
parent | 62daacb51a2bf8480e6f6b3696b03f102fc15eb0 (diff) |
perf tools: Consolidate symbol resolving across all tools
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? :-)
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: John Kacur <jkacur@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1259346563-12568-12-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util/event.c')
-rw-r--r-- | tools/perf/util/event.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c index 70b4aa03b472..233d7ad9bd7f 100644 --- a/tools/perf/util/event.c +++ b/tools/perf/util/event.c | |||
@@ -249,3 +249,65 @@ int event__process_task(event_t *self) | |||
249 | 249 | ||
250 | return 0; | 250 | return 0; |
251 | } | 251 | } |
252 | |||
253 | void thread__find_addr_location(struct thread *self, u8 cpumode, | ||
254 | enum map_type type, u64 addr, | ||
255 | struct addr_location *al, | ||
256 | symbol_filter_t filter) | ||
257 | { | ||
258 | struct thread *thread = al->thread = self; | ||
259 | |||
260 | al->addr = addr; | ||
261 | |||
262 | if (cpumode & PERF_RECORD_MISC_KERNEL) { | ||
263 | al->level = 'k'; | ||
264 | thread = kthread; | ||
265 | } else if (cpumode & PERF_RECORD_MISC_USER) | ||
266 | al->level = '.'; | ||
267 | else { | ||
268 | al->level = 'H'; | ||
269 | al->map = NULL; | ||
270 | al->sym = NULL; | ||
271 | return; | ||
272 | } | ||
273 | try_again: | ||
274 | al->map = thread__find_map(thread, type, al->addr); | ||
275 | if (al->map == NULL) { | ||
276 | /* | ||
277 | * If this is outside of all known maps, and is a negative | ||
278 | * address, try to look it up in the kernel dso, as it might be | ||
279 | * a vsyscall or vdso (which executes in user-mode). | ||
280 | * | ||
281 | * XXX This is nasty, we should have a symbol list in the | ||
282 | * "[vdso]" dso, but for now lets use the old trick of looking | ||
283 | * in the whole kernel symbol list. | ||
284 | */ | ||
285 | if ((long long)al->addr < 0 && thread != kthread) { | ||
286 | thread = kthread; | ||
287 | goto try_again; | ||
288 | } | ||
289 | al->sym = NULL; | ||
290 | } else { | ||
291 | al->addr = al->map->map_ip(al->map, al->addr); | ||
292 | al->sym = map__find_symbol(al->map, al->addr, filter); | ||
293 | } | ||
294 | } | ||
295 | |||
296 | int event__preprocess_sample(const event_t *self, struct addr_location *al, | ||
297 | symbol_filter_t filter) | ||
298 | { | ||
299 | u8 cpumode = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; | ||
300 | struct thread *thread = threads__findnew(self->ip.pid); | ||
301 | |||
302 | if (thread == NULL) | ||
303 | return -1; | ||
304 | |||
305 | dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid); | ||
306 | |||
307 | thread__find_addr_location(thread, cpumode, MAP__FUNCTION, | ||
308 | self->ip.ip, al, filter); | ||
309 | dump_printf(" ...... dso: %s\n", | ||
310 | al->map ? al->map->dso->long_name : | ||
311 | al->level == 'H' ? "[hypervisor]" : "<not found>"); | ||
312 | return 0; | ||
313 | } | ||