aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-top.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2009-11-27 13:29:23 -0500
committerIngo Molnar <mingo@elte.hu>2009-11-27 14:22:02 -0500
commit1ed091c45ae33b2179d387573c3fe3f3b4adf60a (patch)
treed2b689de158e5a11673b5f0d08b491d243768138 /tools/perf/builtin-top.c
parent62daacb51a2bf8480e6f6b3696b03f102fc15eb0 (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/builtin-top.c')
-rw-r--r--tools/perf/builtin-top.c44
1 files changed, 9 insertions, 35 deletions
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 7a3c0c7aad3d..e0a374d0e43a 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -929,55 +929,28 @@ static int symbol_filter(struct map *map, struct symbol *sym)
929static void event__process_sample(const event_t *self, int counter) 929static void event__process_sample(const event_t *self, int counter)
930{ 930{
931 u64 ip = self->ip.ip; 931 u64 ip = self->ip.ip;
932 struct map *map;
933 struct sym_entry *syme; 932 struct sym_entry *syme;
934 struct symbol *sym; 933 struct addr_location al;
935 u8 origin = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK; 934 u8 origin = self->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
936 935
937 switch (origin) { 936 switch (origin) {
938 case PERF_RECORD_MISC_USER: { 937 case PERF_RECORD_MISC_USER:
939 struct thread *thread;
940
941 if (hide_user_symbols) 938 if (hide_user_symbols)
942 return; 939 return;
943 940 break;
944 thread = threads__findnew(self->ip.pid);
945 if (thread == NULL)
946 return;
947
948 map = thread__find_map(thread, MAP__FUNCTION, ip);
949 if (map != NULL) {
950 ip = map->map_ip(map, ip);
951 sym = map__find_symbol(map, ip, symbol_filter);
952 if (sym == NULL)
953 return;
954 userspace_samples++;
955 break;
956 }
957 }
958 /*
959 * If this is outside of all known maps,
960 * and is a negative address, try to look it
961 * up in the kernel dso, as it might be a
962 * vsyscall or vdso (which executes in user-mode).
963 */
964 if ((long long)ip >= 0)
965 return;
966 /* Fall thru */
967 case PERF_RECORD_MISC_KERNEL: 941 case PERF_RECORD_MISC_KERNEL:
968 if (hide_kernel_symbols) 942 if (hide_kernel_symbols)
969 return; 943 return;
970
971 sym = kernel_maps__find_function(ip, &map, symbol_filter);
972 if (sym == NULL)
973 return;
974 break; 944 break;
975 default: 945 default:
976 return; 946 return;
977 } 947 }
978 948
979 syme = symbol__priv(sym); 949 if (event__preprocess_sample(self, &al, symbol_filter) < 0 ||
950 al.sym == NULL)
951 return;
980 952
953 syme = symbol__priv(al.sym);
981 if (!syme->skip) { 954 if (!syme->skip) {
982 syme->count[counter]++; 955 syme->count[counter]++;
983 syme->origin = origin; 956 syme->origin = origin;
@@ -986,8 +959,9 @@ static void event__process_sample(const event_t *self, int counter)
986 if (list_empty(&syme->node) || !syme->node.next) 959 if (list_empty(&syme->node) || !syme->node.next)
987 __list_insert_active_sym(syme); 960 __list_insert_active_sym(syme);
988 pthread_mutex_unlock(&active_symbols_lock); 961 pthread_mutex_unlock(&active_symbols_lock);
962 if (origin == PERF_RECORD_MISC_USER)
963 ++userspace_samples;
989 ++samples; 964 ++samples;
990 return;
991 } 965 }
992} 966}
993 967