All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Ahern <dsahern@gmail.com>
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>, Namhyung Kim <namhyung@kernel.org>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>
Subject: Re: [PATCH 04/24] tools list traceevent: Add plugin support
Date: Sun, 15 Sep 2013 21:37:51 -0600	[thread overview]
Message-ID: <52367D0F.6070105@gmail.com> (raw)
In-Reply-To: <1378032529-18498-5-git-send-email-jolsa@redhat.com>

On 9/1/13 4:48 AM, Jiri Olsa wrote:
> Backporting plugin support for traceevent lib.

It would be worthwhile to not where the code is ported from -- 
repository and as of commit id.

David


>
> It's now possible to use following interface
> to load plugins for 'struct pevent' object:
>
> 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
>
> Adding -ldl dependency for perf which is needed
> due to plugins support.
>
> Signed-off-by: Jiri Olsa <jolsa@redhat.com>
> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
> Cc: Frederic Weisbecker <fweisbec@gmail.com>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Paul Mackerras <paulus@samba.org>
> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
> Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
> Cc: Steven Rostedt <rostedt@goodmis.org>
> Cc: David Ahern <dsahern@gmail.com>
> ---
>   tools/lib/traceevent/Makefile       |   2 +-
>   tools/lib/traceevent/event-parse.h  |   5 +
>   tools/lib/traceevent/event-plugin.c | 202 ++++++++++++++++++++++++++++++++++++
>   tools/perf/config/Makefile          |   2 +-
>   4 files changed, 209 insertions(+), 2 deletions(-)
>   create mode 100644 tools/lib/traceevent/event-plugin.c
>
> diff --git a/tools/lib/traceevent/Makefile b/tools/lib/traceevent/Makefile
> index ca6cb77..539f3e5 100644
> --- a/tools/lib/traceevent/Makefile
> +++ b/tools/lib/traceevent/Makefile
> @@ -180,7 +180,7 @@ $(obj)/%.o: $(src)/%.c
>   %.o: $(src)/%.c
>   	$(Q)$(call do_compile)
>
> -PEVENT_LIB_OBJS = event-parse.o trace-seq.o parse-filter.o parse-utils.o
> +PEVENT_LIB_OBJS = event-parse.o event-plugin.o trace-seq.o parse-filter.o parse-utils.o
>   PEVENT_LIB_OBJS += kbuffer-parse.o
>
>   ALL_OBJS = $(PEVENT_LIB_OBJS)
> diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
> index c37b202..8273c6e 100644
> --- a/tools/lib/traceevent/event-parse.h
> +++ b/tools/lib/traceevent/event-parse.h
> @@ -374,6 +374,11 @@ enum pevent_errno {
>   };
>   #undef _PE
>
> +struct plugin_list;
> +
> +struct plugin_list *traceevent_load_plugins(struct pevent *pevent);
> +void traceevent_unload_plugins(struct plugin_list *plugin_list);
> +
>   struct cmdline;
>   struct cmdline_list;
>   struct func_map;
> diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
> new file mode 100644
> index 0000000..d272d87
> --- /dev/null
> +++ b/tools/lib/traceevent/event-plugin.c
> @@ -0,0 +1,202 @@
> +/*
> + * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
> + *
> + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation;
> + * version 2.1 of the License (not later!)
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this program; if not,  see <http://www.gnu.org/licenses>
> + *
> + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + */
> +
> +#include <string.h>
> +#include <dlfcn.h>
> +#include <stdlib.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <unistd.h>
> +#include <dirent.h>
> +#include "event-parse.h"
> +#include "event-utils.h"
> +
> +#define LOCAL_PLUGIN_DIR ".traceevent/plugins"
> +
> +struct plugin_list {
> +	struct plugin_list	*next;
> +	char			*name;
> +	void			*handle;
> +};
> +
> +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);
> +
> +	strcpy(plugin, path);
> +	strcat(plugin, "/");
> +	strcat(plugin, file);
> +
> +	handle = dlopen(plugin, RTLD_NOW | RTLD_GLOBAL);
> +	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;
> +
> +	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));
> +	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),
> +		 void *data)
> +{
> +	struct dirent *dent;
> +	struct stat st;
> +	DIR *dir;
> +	int ret;
> +
> +	ret = stat(path, &st);
> +	if (ret < 0)
> +		return;
> +
> +	if (!S_ISDIR(st.st_mode))
> +		return;
> +
> +	dir = opendir(path);
> +	if (!dir)
> +		return;
> +
> +	while ((dent = readdir(dir))) {
> +		const char *name = dent->d_name;
> +
> +		if (strcmp(name, ".") == 0 ||
> +		    strcmp(name, "..") == 0)
> +			continue;
> +
> +		/* Only load plugins that end in suffix */
> +		if (strcmp(name + (strlen(name) - strlen(suffix)), suffix) != 0)
> +			continue;
> +
> +		load_plugin(pevent, path, name, data);
> +	}
> +
> +	closedir(dir);
> +}
> +
> +static void
> +load_plugins(struct pevent *pevent, const char *suffix,
> +	     void (*load_plugin)(struct pevent *pevent,
> +				 const char *path,
> +				 const char *name,
> +				 void *data),
> +	     void *data)
> +{
> +	char *home;
> +	char *path;
> +	char *envdir;
> +
> +	/*
> +	 * If a system plugin directory was defined,
> +	 * check that first.
> +	 */
> +#ifdef PLUGIN_DIR
> +	load_plugins_dir(pevent, suffix, PLUGIN_DIR, load_plugin, data);
> +#endif
> +
> +	/*
> +	 * Next let the environment-set plugin directory
> +	 * override the system defaults.
> +	 */
> +	envdir = getenv("TRACEEVENT_PLUGIN_DIR");
> +	if (envdir)
> +		load_plugins_dir(pevent, suffix, envdir, load_plugin, data);
> +
> +	/*
> +	 * 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);
> +
> +	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);
> +	}
> +}
> diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
> index 214e17e..f6d720d 100644
> --- a/tools/perf/config/Makefile
> +++ b/tools/perf/config/Makefile
> @@ -87,7 +87,7 @@ CFLAGS += -Wall
>   CFLAGS += -Wextra
>   CFLAGS += -std=gnu99
>
> -EXTLIBS = -lelf -lpthread -lrt -lm
> +EXTLIBS = -lelf -lpthread -lrt -lm -ldl
>
>   ifeq ($(call try-cc,$(SOURCE_HELLO),$(CFLAGS) -Werror -fstack-protector-all,-fstack-protector-all),y)
>     CFLAGS += -fstack-protector-all
>


  reply	other threads:[~2013-09-16  3:37 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-01 10:48 [RFC 00/24] perf tools: Add traceevent plugins support Jiri Olsa
2013-09-01 10:48 ` [PATCH 01/24] perf tools: Fix 'make install prefix=...' build rule Jiri Olsa
2013-09-04  8:35   ` Namhyung Kim
2013-09-01 10:48 ` [PATCH 02/24] perf tools: Remove unused trace-event-* code Jiri Olsa
2013-09-04  8:36   ` Namhyung Kim
2013-09-01 10:48 ` [PATCH 03/24] perf tools: Unify page_size usage Jiri Olsa
2013-09-04  8:37   ` Namhyung Kim
2013-09-01 10:48 ` [PATCH 04/24] tools list traceevent: Add plugin support Jiri Olsa
2013-09-16  3:37   ` David Ahern [this message]
2013-09-01 10:48 ` [PATCH 05/24] tools list traceevent: Add options support Jiri Olsa
2013-09-16  3:40   ` David Ahern
2013-09-01 10:48 ` [PATCH 06/24] tools list traceevent: Add plugin build support Jiri Olsa
2013-09-01 10:48 ` [PATCH 07/24] tools list traceevent: Add traceevent_host_bigendian function Jiri Olsa
2013-09-01 10:48 ` [PATCH 08/24] tools list traceevent: Add pevent_print_func_field function Jiri Olsa
2013-09-01 10:48 ` [PATCH 09/24] tools list traceevent: Add jbd2 plugin Jiri Olsa
2013-09-01 10:48 ` [PATCH 10/24] tools list traceevent: Add blk plugin Jiri Olsa
2013-09-01 10:48 ` [PATCH 11/24] tools list traceevent: Add hrtimer plugin Jiri Olsa
2013-09-01 10:48 ` [PATCH 12/24] tools list traceevent: Add kmem plugin Jiri Olsa
2013-09-01 10:48 ` [PATCH 13/24] tools list traceevent: Add kvm plugin Jiri Olsa
2013-09-01 10:48 ` [PATCH 14/24] tools list traceevent: Add mac80211 plugin Jiri Olsa
2013-09-01 10:48 ` [PATCH 15/24] tools list traceevent: Add sched_switch plugin Jiri Olsa
2013-09-01 10:48 ` [PATCH 16/24] tools list traceevent: Add function plugin Jiri Olsa
2013-09-01 10:48 ` [PATCH 17/24] tools list traceevent: Update kvm plugin with is_writable_pte helper Jiri Olsa
2013-09-01 10:48 ` [PATCH 18/24] tools list traceevent: Add xen plugin Jiri Olsa
2013-09-01 10:48 ` [PATCH 19/24] tools list traceevent: Add scsi plugin Jiri Olsa
2013-09-01 10:48 ` [PATCH 20/24] tools list traceevent: Change pevent_parse_event to return event format Jiri Olsa
2013-09-01 10:48 ` [PATCH 21/24] perf tools: Add traceevents Makefile install rule Jiri Olsa
2013-09-01 10:48 ` [PATCH 22/24] perf tools: Add trace-event object Jiri Olsa
2013-09-01 10:48 ` [PATCH 23/24] perf tools: Add traceevent object to interface traceevent lib Jiri Olsa
2013-09-01 10:48 ` [PATCH 24/24] perf tools: Overload pr_stat traceevent print function Jiri Olsa
2013-09-02  8:39 ` [RFC 00/24] perf tools: Add traceevent plugins support Jiri Olsa

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=52367D0F.6070105@gmail.com \
    --to=dsahern@gmail.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=namhyung@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.