Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf symbols: Provide libtraceevent callback to resolve kernel symbols

That provides the function signature expected by libtraceevent's
pevent_set_function_resolver().

Acked-by: David Ahern <dsahern@gmail.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Borislav Petkov <bp@suse.de>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Link: http://lkml.kernel.org/n/tip-ie6hvlb6u15y4ulg9j1612zg@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+49 -15
+14
tools/perf/util/machine.c
··· 1993 1993 { 1994 1994 return dsos__findnew(&machine->dsos, filename); 1995 1995 } 1996 + 1997 + char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp) 1998 + { 1999 + struct machine *machine = vmachine; 2000 + struct map *map; 2001 + struct symbol *sym = map_groups__find_symbol(&machine->kmaps, MAP__FUNCTION, *addrp, &map, NULL); 2002 + 2003 + if (sym == NULL) 2004 + return NULL; 2005 + 2006 + *modp = __map__is_kmodule(map) ? (char *)map->dso->short_name : NULL; 2007 + *addrp = map->unmap_ip(map, sym->start); 2008 + return sym->name; 2009 + }
+4
tools/perf/util/machine.h
··· 237 237 pid_t machine__get_current_tid(struct machine *machine, int cpu); 238 238 int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, 239 239 pid_t tid); 240 + /* 241 + * For use with libtraceevent's pevent_set_function_resolver() 242 + */ 243 + char *machine__resolve_kernel_addr(void *vmachine, unsigned long long *addrp, char **modp); 240 244 241 245 #endif /* __PERF_MACHINE_H */
+30 -15
tools/perf/util/trace-event.c
··· 9 9 #include <linux/kernel.h> 10 10 #include <traceevent/event-parse.h> 11 11 #include "trace-event.h" 12 + #include "machine.h" 12 13 #include "util.h" 13 14 14 15 /* ··· 20 19 * there. 21 20 */ 22 21 static struct trace_event tevent; 22 + static bool tevent_initialized; 23 23 24 24 int trace_event__init(struct trace_event *t) 25 25 { ··· 32 30 } 33 31 34 32 return pevent ? 0 : -1; 33 + } 34 + 35 + static int trace_event__init2(void) 36 + { 37 + int be = traceevent_host_bigendian(); 38 + struct pevent *pevent; 39 + 40 + if (trace_event__init(&tevent)) 41 + return -1; 42 + 43 + pevent = tevent.pevent; 44 + pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT); 45 + pevent_set_file_bigendian(pevent, be); 46 + pevent_set_host_bigendian(pevent, be); 47 + tevent_initialized = true; 48 + return 0; 49 + } 50 + 51 + int trace_event__register_resolver(struct machine *machine) 52 + { 53 + if (!tevent_initialized && trace_event__init2()) 54 + return -1; 55 + 56 + return pevent_set_function_resolver(tevent.pevent, 57 + machine__resolve_kernel_addr, 58 + machine); 35 59 } 36 60 37 61 void trace_event__cleanup(struct trace_event *t) ··· 90 62 struct event_format* 91 63 trace_event__tp_format(const char *sys, const char *name) 92 64 { 93 - static bool initialized; 94 - 95 - if (!initialized) { 96 - int be = traceevent_host_bigendian(); 97 - struct pevent *pevent; 98 - 99 - if (trace_event__init(&tevent)) 100 - return NULL; 101 - 102 - pevent = tevent.pevent; 103 - pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT); 104 - pevent_set_file_bigendian(pevent, be); 105 - pevent_set_host_bigendian(pevent, be); 106 - initialized = true; 107 - } 65 + if (!tevent_initialized && trace_event__init2()) 66 + return NULL; 108 67 109 68 return tp_format(sys, name); 110 69 }
+1
tools/perf/util/trace-event.h
··· 18 18 19 19 int trace_event__init(struct trace_event *t); 20 20 void trace_event__cleanup(struct trace_event *t); 21 + int trace_event__register_resolver(struct machine *machine); 21 22 struct event_format* 22 23 trace_event__tp_format(const char *sys, const char *name); 23 24