From: Namhyung Kim <namhyung@kernel.org>
To: Jiri Olsa <jolsa@redhat.com>
Cc: linux-kernel@vger.kernel.org,
Corey Ashford <cjashfor@linux.vnet.ibm.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@elte.hu>, Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
Steven Rostedt <rostedt@goodmis.org>,
David Ahern <dsahern@gmail.com>
Subject: Re: [PATCH 01/22] tools lib traceevent: Add plugin support
Date: Fri, 22 Nov 2013 23:17:06 +0900 [thread overview]
Message-ID: <1385129826.1747.22.camel@leonhard> (raw)
In-Reply-To: <1385031680-9014-2-git-send-email-jolsa@redhat.com>
Hi Jiri,
2013-11-21 (목), 12:00 +0100, Jiri Olsa:
> Backporting plugin support for traceevent lib.
>
> Backported from Steven Rostedt's trace-cmd repo (HEAD 0f2c2fb):
> git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git
>
> It's now possible to use following interface to load plugins
> (shared objects) to enahnce pevent object functionality.
>
> The plugin interface/hooks are as follows:
> (taken from event-parse.h comments)
>
> - 'pevent_plugin_loader' (required)
> The function name to initialized the plugin.
>
> int pevent_plugin_loader(struct pevent *pevent)
>
> - 'pevent_plugin_unloader' (optional)
> The function called just before unloading
>
> int pevent_plugin_unloader(void)
>
> - 'pevent_plugin_options' (optional)
> Plugin options that can be set before loading
>
> struct plugin_option pevent_plugin_options[] = {
> {
> .name = "option-name",
> .plugin_alias = "overide-file-name", (optional)
> .description = "description of option to show users",
> },
> {
> .name = NULL,
> },
> };
>
> Array must end with .name = NULL;
>
> The plugin_alias (below) can be used to give a shorter
> name to access the vairable. Useful if a plugin handles
> more than one event.
>
> NOTE options support is not backported yet.
>
> - 'pevent_plugin_alias' (optional)
> The name to use for finding options (uses filename if not defined)
>
> New traceevent functions are added to search and load
> available plugins:
>
> struct plugin_list*
> traceevent_load_plugins(struct pevent *pevent)
> - loads plusing for 'struct pevent' object and returns
> loaded plugins list
>
> void traceevent_unload_plugins(struct plugin_list *plugin_list);
> - unload plugin list
First of all, thank you for your nice work! :)
>
[SNIP[
> +static void
> +load_plugin(struct pevent *pevent, const char *path,
> + const char *file, void *data)
> +{
> + struct plugin_list **plugin_list = data;
> + pevent_plugin_load_func func;
> + struct plugin_list *list;
> + const char *alias;
> + char *plugin;
> + void *handle;
> +
> + plugin = malloc_or_die(strlen(path) + strlen(file) + 2);
I'd like not to see this malloc_or_die() anymore in a new code. Just
returning after showing a warning looks enough here.
> +
> + strcpy(plugin, path);
> + strcat(plugin, "/");
> + strcat(plugin, file);
> +
> + handle = dlopen(plugin, RTLD_NOW | RTLD_GLOBAL);
Why RTLD_NOW and RTLD_GLOBAL? Hmm.. maybe using _NOW is needed to
prevent a runtime error, but not sure why _GLOBAL is needed.
IIUC _GLOBAL is for exporting symbols to *other libraries*. Is it
intended for this plugin support?
> + if (!handle) {
> + warning("could not load plugin '%s'\n%s\n",
> + plugin, dlerror());
> + goto out_free;
> + }
> +
> + alias = dlsym(handle, PEVENT_PLUGIN_ALIAS_NAME);
> + if (!alias)
> + alias = file;
So this 'alias' is not used anywhere in the current code, right?
Do you plan to add the option processing soon?
> +
> + func = dlsym(handle, PEVENT_PLUGIN_LOADER_NAME);
> + if (!func) {
> + warning("could not find func '%s' in plugin '%s'\n%s\n",
> + PEVENT_PLUGIN_LOADER_NAME, plugin, dlerror());
> + goto out_free;
> + }
> +
> + list = malloc_or_die(sizeof(*list));
Ditto. Please check return value and handle error properly.
> + list->next = *plugin_list;
> + list->handle = handle;
> + list->name = plugin;
> + *plugin_list = list;
> +
> + pr_stat("registering plugin: %s", plugin);
> + func(pevent);
> + return;
> +
> + out_free:
> + free(plugin);
> +}
> +
> +static void
> +load_plugins_dir(struct pevent *pevent, const char *suffix,
> + const char *path,
> + void (*load_plugin)(struct pevent *pevent,
> + const char *path,
> + const char *name,
> + void *data),
Doesn't gcc complain about the name shadows other function? Anyway I
think we should avoid using same name - probably using typedef for the
function might be helpful.
> + void *data)
[SNIP]
> + /*
> + * Now let the home directory override the environment
> + * or system defaults.
> + */
> + home = getenv("HOME");
> + if (!home)
> + return;
> +
> + path = malloc_or_die(strlen(home) + strlen(LOCAL_PLUGIN_DIR) + 2);
Ditto.
Thanks,
Namhyung
> +
> + strcpy(path, home);
> + strcat(path, "/");
> + strcat(path, LOCAL_PLUGIN_DIR);
> +
> + load_plugins_dir(pevent, suffix, path, load_plugin, data);
> +
> + free(path);
> +}
> +
> +struct plugin_list*
> +traceevent_load_plugins(struct pevent *pevent)
> +{
> + struct plugin_list *list = NULL;
> +
> + load_plugins(pevent, ".so", load_plugin, &list);
> + return list;
> +}
> +
> +void
> +traceevent_unload_plugins(struct plugin_list *plugin_list)
> +{
> + pevent_plugin_unload_func func;
> + struct plugin_list *list;
> +
> + while (plugin_list) {
> + list = plugin_list;
> + plugin_list = list->next;
> + func = dlsym(list->handle, PEVENT_PLUGIN_UNLOADER_NAME);
> + if (func)
> + func();
> + dlclose(list->handle);
> + free(list->name);
> + free(list);
> + }
> +}
next prev parent reply other threads:[~2013-11-22 14:17 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-21 11:00 [PATCH 00/22] perf tools: Add traceevent plugins support Jiri Olsa
2013-11-21 11:00 ` [PATCH 01/22] tools lib traceevent: Add plugin support Jiri Olsa
2013-11-21 11:58 ` Steven Rostedt
2013-11-22 14:17 ` Namhyung Kim [this message]
2013-11-23 8:12 ` Steven Rostedt
2013-11-25 7:33 ` Namhyung Kim
2013-11-25 9:30 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 02/22] tools lib traceevent: Add plugin build support Jiri Olsa
2013-11-21 11:01 ` [PATCH 03/22] tools lib traceevent: Add traceevent_host_bigendian function Jiri Olsa
2013-11-22 14:22 ` Namhyung Kim
2013-11-23 8:27 ` Steven Rostedt
2013-11-25 7:24 ` Namhyung Kim
2013-11-25 9:33 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 04/22] tools lib traceevent: Add jbd2 plugin Jiri Olsa
2013-11-21 13:09 ` Steven Rostedt
2013-11-22 14:27 ` Namhyung Kim
2013-11-23 8:52 ` Steven Rostedt
2013-11-25 7:38 ` Namhyung Kim
2013-11-25 9:46 ` Jiri Olsa
2013-11-25 10:03 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 05/22] tools lib traceevent: Add hrtimer plugin Jiri Olsa
2013-11-21 13:10 ` Steven Rostedt
2013-11-22 14:33 ` Namhyung Kim
2013-11-23 8:59 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 06/22] tools lib traceevent: Add kmem plugin Jiri Olsa
2013-11-21 13:14 ` Steven Rostedt
2013-11-22 14:38 ` Namhyung Kim
2013-11-23 9:06 ` Steven Rostedt
2013-11-25 7:43 ` Namhyung Kim
2013-11-21 11:01 ` [PATCH 07/22] tools lib traceevent: Add kvm plugin Jiri Olsa
2013-11-21 13:15 ` Steven Rostedt
2013-11-22 14:45 ` Namhyung Kim
2013-11-23 9:15 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 08/22] tools lib traceevent: Add mac80211 plugin Jiri Olsa
2013-11-21 11:01 ` [PATCH 09/22] tools lib traceevent: Add sched_switch plugin Jiri Olsa
2013-11-21 13:18 ` Steven Rostedt
[not found] ` <1385132034.1747.58.camel@leonhard>
2013-11-23 9:16 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 10/22] tools lib traceevent: Add function plugin Jiri Olsa
2013-11-21 13:20 ` Steven Rostedt
2013-11-22 15:03 ` Namhyung Kim
2013-11-23 9:22 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 11/22] tools lib traceevent: Add xen plugin Jiri Olsa
2013-11-22 15:06 ` Namhyung Kim
2013-11-25 13:38 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 12/22] tools lib traceevent: Add scsi plugin Jiri Olsa
2013-11-22 15:24 ` Namhyung Kim
2013-11-23 9:25 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 13/22] tools lib traceevent: Add cfg80211 plugin Jiri Olsa
2013-11-22 15:16 ` Namhyung Kim
2013-11-23 9:27 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 14/22] tools lib traceevent: Update kvm plugin with is_writable_pte helper Jiri Olsa
2013-11-22 15:19 ` Namhyung Kim
2013-11-23 9:28 ` Steven Rostedt
2013-11-21 11:01 ` [PATCH 15/22] tools lib traceevent: Change pevent_parse_event to return event format Jiri Olsa
2013-11-21 13:28 ` Steven Rostedt
2013-11-21 13:42 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 16/22] tools lib traceevent: Harmonize the install messages in lib-traceevent Jiri Olsa
2013-11-21 11:01 ` [PATCH 17/22] perf tools: Add build and install plugins targets Jiri Olsa
2013-11-22 15:27 ` Namhyung Kim
2013-11-25 14:51 ` Jiri Olsa
2013-11-27 8:13 ` Namhyung Kim
2013-11-21 11:01 ` [PATCH 18/22] perf tools: Add udis86 disassembler feature check Jiri Olsa
2013-11-22 15:38 ` Namhyung Kim
2013-11-25 15:02 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 19/22] perf tools: Add filename__read_str util function Jiri Olsa
2013-11-22 15:43 ` Namhyung Kim
2013-11-25 15:17 ` Jiri Olsa
2013-11-21 11:01 ` [PATCH 20/22] perf tools: Add trace-event object Jiri Olsa
2013-11-21 11:01 ` [PATCH 21/22] perf tools: Add trace-event global object for tracepoint interface Jiri Olsa
2013-11-22 15:47 ` Namhyung Kim
2013-11-25 16:03 ` Jiri Olsa
2013-11-27 13:46 ` Namhyung Kim
2013-11-27 15:10 ` Jiri Olsa
2013-11-27 15:27 ` Jiri Olsa
2013-11-27 15:49 ` Namhyung Kim
2013-11-21 11:01 ` [PATCH 22/22] perf tools: Overload pr_stat traceevent print function Jiri Olsa
2013-11-22 15:50 ` Namhyung Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1385129826.1747.22.camel@leonhard \
--to=namhyung@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=acme@redhat.com \
--cc=cjashfor@linux.vnet.ibm.com \
--cc=dsahern@gmail.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox