From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754512AbbGWR0D (ORCPT ); Thu, 23 Jul 2015 13:26:03 -0400 Received: from mail.kernel.org ([198.145.29.136]:56344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754197AbbGWRZ7 (ORCPT ); Thu, 23 Jul 2015 13:25:59 -0400 Date: Thu, 23 Jul 2015 14:25:54 -0300 From: Arnaldo Carvalho de Melo To: Steven Rostedt Cc: David Ahern , Adrian Hunter , Borislav Petkov , Frederic Weisbecker , Jiri Olsa , Namhyung Kim , Stephane Eranian , Ingo Molnar , Linux Kernel Mailing List Subject: Re: [RFC PATCH] tools lib traceevent: Allow setting an alternative symbol resolver Message-ID: <20150723172554.GC3154@kernel.org> References: <20150723150433.GA3154@kernel.org> <20150723122130.716df9fe@gandalf.local.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150723122130.716df9fe@gandalf.local.home> X-Url: http://acmel.wordpress.com User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Em Thu, Jul 23, 2015 at 12:21:30PM -0400, Steven Rostedt escreveu: > On Thu, 23 Jul 2015 12:04:33 -0300 Arnaldo Carvalho de Melo wrote: > > +static struct func_map * > > +find_func(struct pevent *pevent, unsigned long long addr) > > +{ > > + static struct func_map map; > I know there's other cases of static variables in functions, but I plan > on cleaning that up in the future. > Can you make that map belong to the pevent itself? In case there's two > pevent's going parallel, I don't want one to overwrite the other. The > pevent code is not re-entrant, but I would like to make it so for > different pevents. Sure, see if this one is better, had to use malloc so as not to expose the func_map definition, i.e. at 'struct pevent' definition we only have a forward declaration of struct func_map: commit 228160130180a7868b73b755e86e263fcaba1468 Author: Arnaldo Carvalho de Melo Date: Wed Jul 22 12:36:55 2015 -0300 tools lib traceevent: Allow setting an alternative symbol resolver The perf tools have a symbol resolver that includes solving kernel symbols using either kallsyms or ELF symtabs, and it also is using libtraceevent to format the trace events fields, including via subsystem specific plugins, like the "timer" one. To solve fields like "timer:hrtimer_start"'s "function", libtraceevent needs a way to map from its value to a function name and addr. This patch provides a way for tools that already have symbol resolving facilities to ask libtraceevent to use it when needing to resolve kernel symbols. Acked-by: David Ahern Cc: Adrian Hunter Cc: Borislav Petkov Cc: Frederic Weisbecker Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Cc: Steven Rostedt Link: http://lkml.kernel.org/n/tip-fdx1fazols17w5py26ia3bwh@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index cc25f059ab3d..2750e7e7efff 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c @@ -418,7 +418,7 @@ static int func_map_init(struct pevent *pevent) } static struct func_map * -find_func(struct pevent *pevent, unsigned long long addr) +__find_func(struct pevent *pevent, unsigned long long addr) { struct func_map *func; struct func_map key; @@ -434,6 +434,51 @@ find_func(struct pevent *pevent, unsigned long long addr) return func; } +static struct { + pevent_function_resolver_t *function; + void *priv; +} function_resolver; + +/** + * pevent_set_function_resolver - set an alternative function resolver + * @resolver - function to be used + * @priv - resolver function private state. + * + * Some tools may have already a way to resolve kernel functions, allow them + * to keep using it instead of duplicating all the entries inside pevent->funclist. + */ +void pevent_set_function_resolver(pevent_function_resolver_t *resolver, void *priv) +{ + function_resolver.function = resolver; + function_resolver.priv = priv; +} + +static struct func_map * +find_func(struct pevent *pevent, unsigned long long addr) +{ + struct func_map *map; + + if (!function_resolver.function) + return __find_func(pevent, addr); + + if (pevent->func_map_resolver == NULL) { + pevent->func_map_resolver = malloc(sizeof(*map)); + if (pevent->func_map_resolver == NULL) { + do_warning("Not enough memory for resolving addresses to functions!\n"); + return NULL; + } + } + + map = pevent->func_map_resolver; + map->mod = NULL; + map->addr = addr; + map->func = function_resolver.function(function_resolver.priv, &map->addr, &map->mod); + if (map->func == NULL) + return NULL; + + return map; +} + /** * pevent_find_function - find a function by a given address * @pevent: handle for the pevent @@ -6564,6 +6609,7 @@ void pevent_free(struct pevent *pevent) free(pevent->trace_clock); free(pevent->events); free(pevent->sort_events); + free(pevent->func_map_resolver); free(pevent); } diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h index 063b1971eb35..6bd526f0d17a 100644 --- a/tools/lib/traceevent/event-parse.h +++ b/tools/lib/traceevent/event-parse.h @@ -481,6 +481,7 @@ struct pevent { int cmdline_count; struct func_map *func_map; + struct func_map *func_map_resolver; struct func_list *funclist; unsigned int func_count; @@ -611,6 +612,10 @@ enum trace_flag_type { TRACE_FLAG_SOFTIRQ = 0x10, }; +typedef char *(pevent_function_resolver_t)(void *priv, unsigned long long *addrp, char **modp); + +void pevent_set_function_resolver(pevent_function_resolver_t *resolver, void *priv); + int pevent_register_comm(struct pevent *pevent, const char *comm, int pid); int pevent_register_trace_clock(struct pevent *pevent, const char *trace_clock); int pevent_register_function(struct pevent *pevent, char *name,