* [PATCH 0/3] tools lib traceevent: Options for plugins
@ 2014-04-22 19:48 Steven Rostedt
2014-04-22 19:48 ` [PATCH 1/3] tools lib traceevent: Add flag to not load event plugins Steven Rostedt
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Steven Rostedt @ 2014-04-22 19:48 UTC (permalink / raw)
To: linux-kernel
Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Jiri Olsa, Namhyung Kim,
Andrew Morton
trace-cmd has a way to set options for plugins, via the command
line parameter. For example, you can add or remove the parent
from being printed in function tracing by adding:
-O parent=1
-O parent=0
This is passed later to the plugin in. But the plugin itself requires
registering to the application what options it supplies.
This is a three patch series. The first is to set a flag in pevent
that would prevent plugins from being loaded. This can be supplied
by the command line as well to produce the old "raw" events.
The second patch adds the infrastructure to let plugins have options.
The third patch adds the options "parent" and "indent" to the
function plugin. The indent option lets the user print functions
with or without indenting by their parents.
All that needs to be done now is to add the options to the perf
command line. Namhyung? ;-)
-- Steve
Steven Rostedt (Red Hat) (3):
tools lib traceevent: Add flag to not load event plugins
tools lib traceevent: Add options to plugins
tools lib traceevent: Add options to function plugin
----
tools/lib/traceevent/event-parse.h | 16 ++-
tools/lib/traceevent/event-plugin.c | 204 ++++++++++++++++++++++++++++++++-
tools/lib/traceevent/plugin_function.c | 43 ++++++-
3 files changed, 253 insertions(+), 10 deletions(-)
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] tools lib traceevent: Add flag to not load event plugins
2014-04-22 19:48 [PATCH 0/3] tools lib traceevent: Options for plugins Steven Rostedt
@ 2014-04-22 19:48 ` Steven Rostedt
2014-04-22 19:48 ` [PATCH 2/3] tools lib traceevent: Add options to plugins Steven Rostedt
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2014-04-22 19:48 UTC (permalink / raw)
To: linux-kernel
Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Jiri Olsa, Namhyung Kim,
Andrew Morton
[-- Attachment #1: 0001-tools-lib-traceevent-Add-flag-to-not-load-event-plug.patch --]
[-- Type: text/plain, Size: 1635 bytes --]
From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
Add a flag to pevent that will let the callers be able to set it and
keep the system, and perhaps even normal plugins from being loaded.
This is useful when plugins might hide certain information and seeing
the raw events shows what may be going on.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
tools/lib/traceevent/event-parse.h | 2 ++
tools/lib/traceevent/event-plugin.c | 7 ++++++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index 791c539..b37e18e 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -354,6 +354,8 @@ enum pevent_func_arg_type {
enum pevent_flag {
PEVENT_NSEC_OUTPUT = 1, /* output in NSECS */
+ PEVENT_DISABLE_SYS_PLUGINS = 1 << 1,
+ PEVENT_DISABLE_PLUGINS = 1 << 2,
};
#define PEVENT_ERRORS \
diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index 0c8bf67..317466b 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -148,12 +148,17 @@ load_plugins(struct pevent *pevent, const char *suffix,
char *path;
char *envdir;
+ if (pevent->flags & PEVENT_DISABLE_PLUGINS)
+ return;
+
/*
* If a system plugin directory was defined,
* check that first.
*/
#ifdef PLUGIN_DIR
- load_plugins_dir(pevent, suffix, PLUGIN_DIR, load_plugin, data);
+ if (!(pevent->flags & PEVENT_DISABLE_SYS_PLUGINS))
+ load_plugins_dir(pevent, suffix, PLUGIN_DIR,
+ load_plugin, data);
#endif
/*
--
1.8.5.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/3] tools lib traceevent: Add options to plugins
2014-04-22 19:48 [PATCH 0/3] tools lib traceevent: Options for plugins Steven Rostedt
2014-04-22 19:48 ` [PATCH 1/3] tools lib traceevent: Add flag to not load event plugins Steven Rostedt
@ 2014-04-22 19:48 ` Steven Rostedt
2014-04-22 19:48 ` [PATCH 3/3] tools lib traceevent: Add options to function plugin Steven Rostedt
2014-04-23 6:07 ` [PATCH 0/3] tools lib traceevent: Options for plugins Namhyung Kim
3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2014-04-22 19:48 UTC (permalink / raw)
To: linux-kernel
Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Jiri Olsa, Namhyung Kim,
Andrew Morton
[-- Attachment #1: 0002-tools-lib-traceevent-Add-options-to-plugins.patch --]
[-- Type: text/plain, Size: 8381 bytes --]
From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
The traceevent plugins allows developers to have their events print out
information that is more advanced than what can be achieved by the
trace event format files.
As these plugins are used on the userspace side of the tracing tools, it
is only logical that the tools should be able to produce different types
of output for the events. The types of events still need to be defined by
the plugins thus we need a way to pass information from the tool to the
plugin to specify what type of information to be shown.
Not only does the information need to be passed by the tool to plugin, but
the plugin also requires a way to notify the tool of what options it can
provide.
This builds the plugin option infrastructure that is taken from trace-cmd
that is used to allow plugins to produce different output based on the
options specified by the tool.
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
tools/lib/traceevent/event-parse.h | 16 ++-
tools/lib/traceevent/event-plugin.c | 197 ++++++++++++++++++++++++++++++++++++
2 files changed, 209 insertions(+), 4 deletions(-)
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index b37e18e..9c38181 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -107,8 +107,8 @@ typedef int (*pevent_event_handler_func)(struct trace_seq *s,
typedef int (*pevent_plugin_load_func)(struct pevent *pevent);
typedef int (*pevent_plugin_unload_func)(struct pevent *pevent);
-struct plugin_option {
- struct plugin_option *next;
+struct pevent_plugin_option {
+ struct pevent_plugin_option *next;
void *handle;
char *file;
char *name;
@@ -135,7 +135,7 @@ struct plugin_option {
* PEVENT_PLUGIN_OPTIONS: (optional)
* Plugin options that can be set before loading
*
- * struct plugin_option PEVENT_PLUGIN_OPTIONS[] = {
+ * struct pevent_plugin_option PEVENT_PLUGIN_OPTIONS[] = {
* {
* .name = "option-name",
* .plugin_alias = "overide-file-name", (optional)
@@ -355,7 +355,7 @@ enum pevent_func_arg_type {
enum pevent_flag {
PEVENT_NSEC_OUTPUT = 1, /* output in NSECS */
PEVENT_DISABLE_SYS_PLUGINS = 1 << 1,
- PEVENT_DISABLE_PLUGINS = 1 << 2,
+ PEVENT_DISABLE_PLUGINS = 1 << 2
};
#define PEVENT_ERRORS \
@@ -415,6 +415,14 @@ struct plugin_list;
struct plugin_list *traceevent_load_plugins(struct pevent *pevent);
void traceevent_unload_plugins(struct plugin_list *plugin_list,
struct pevent *pevent);
+char **traceevent_plugin_list_options(void);
+void traceevent_plugin_free_options_list(char **list);
+int traceevent_plugin_add_options(const char *name,
+ struct pevent_plugin_option *options);
+void traceevent_plugin_remove_options(struct pevent_plugin_option *options);
+void traceevent_print_plugins(struct trace_seq *s,
+ const char *prefix, const char *suffix,
+ const struct plugin_list *list);
struct cmdline;
struct cmdline_list;
diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index 317466b..a244794 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -18,6 +18,7 @@
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
+#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <stdlib.h>
@@ -30,12 +31,208 @@
#define LOCAL_PLUGIN_DIR ".traceevent/plugins"
+static struct registered_plugin_options {
+ struct registered_plugin_options *next;
+ struct pevent_plugin_option *options;
+} *registered_options;
+
+static struct trace_plugin_options {
+ struct trace_plugin_options *next;
+ char *plugin;
+ char *option;
+ char *value;
+} *trace_plugin_options;
+
struct plugin_list {
struct plugin_list *next;
char *name;
void *handle;
};
+/**
+ * traceevent_plugin_list_options - get list of plugin options
+ *
+ * Returns an array of char strings that list the currently registered
+ * plugin options in the format of <plugin>:<option>. This list can be
+ * used by toggling the option.
+ *
+ * Returns NULL if there's no options registered. On error it returns
+ * an (char **)-1 (must check for that)
+ *
+ * Must be freed with traceevent_plugin_free_options_list().
+ */
+char **traceevent_plugin_list_options(void)
+{
+ struct registered_plugin_options *reg;
+ struct pevent_plugin_option *op;
+ char **list = NULL;
+ char *name;
+ int count = 0;
+
+ for (reg = registered_options; reg; reg = reg->next) {
+ for (op = reg->options; op->name; op++) {
+ char *alias = op->plugin_alias ? op->plugin_alias : op->file;
+
+ name = malloc(strlen(op->name) + strlen(alias) + 2);
+ if (!name)
+ goto err;
+
+ sprintf(name, "%s:%s", alias, op->name);
+ list = realloc(list, count + 2);
+ if (!list) {
+ free(name);
+ goto err;
+ }
+ list[count++] = name;
+ list[count] = NULL;
+ }
+ }
+ if (!count)
+ return NULL;
+ return list;
+
+ err:
+ while (--count > 0)
+ free(list[count]);
+ free(list);
+
+ return (char **)((unsigned long)-1);
+}
+
+void traceevent_plugin_free_options_list(char **list)
+{
+ int i;
+
+ if (!list)
+ return;
+
+ if (list == (char **)((unsigned long)-1))
+ return;
+
+ for (i = 0; list[i]; i++)
+ free(list[i]);
+
+ free(list);
+}
+
+static int
+update_option(const char *file, struct pevent_plugin_option *option)
+{
+ struct trace_plugin_options *op;
+ char *plugin;
+
+ if (option->plugin_alias) {
+ plugin = strdup(option->plugin_alias);
+ if (!plugin)
+ return -1;
+ } else {
+ char *p;
+ plugin = strdup(file);
+ if (!plugin)
+ return -1;
+ p = strstr(plugin, ".");
+ if (p)
+ *p = '\0';
+ }
+
+ /* first look for named options */
+ for (op = trace_plugin_options; op; op = op->next) {
+ if (!op->plugin)
+ continue;
+ if (strcmp(op->plugin, plugin) != 0)
+ continue;
+ if (strcmp(op->option, option->name) != 0)
+ continue;
+
+ option->value = op->value;
+ option->set ^= 1;
+ goto out;
+ }
+
+ /* first look for unnamed options */
+ for (op = trace_plugin_options; op; op = op->next) {
+ if (op->plugin)
+ continue;
+ if (strcmp(op->option, option->name) != 0)
+ continue;
+
+ option->value = op->value;
+ option->set ^= 1;
+ break;
+ }
+
+ out:
+ free(plugin);
+ return 0;
+}
+
+/**
+ * traceevent_plugin_add_options - Add a set of options by a plugin
+ * @name: The name of the plugin adding the options
+ * @options: The set of options being loaded
+ *
+ * Sets the options with the values that have been added by user.
+ */
+int traceevent_plugin_add_options(const char *name,
+ struct pevent_plugin_option *options)
+{
+ struct registered_plugin_options *reg;
+
+ reg = malloc(sizeof(*reg));
+ if (!reg)
+ return -1;
+ reg->next = registered_options;
+ reg->options = options;
+ registered_options = reg;
+
+ while (options->name) {
+ update_option(name, options);
+ options++;
+ }
+ return 0;
+}
+
+/**
+ * traceevent_plugin_remove_options - remove plugin options that were registered
+ * @options: Options to removed that were registered with traceevent_plugin_add_options
+ */
+void traceevent_plugin_remove_options(struct pevent_plugin_option *options)
+{
+ struct registered_plugin_options **last;
+ struct registered_plugin_options *reg;
+
+ for (last = ®istered_options; *last; last = &(*last)->next) {
+ if ((*last)->options == options) {
+ reg = *last;
+ *last = reg->next;
+ free(reg);
+ return;
+ }
+ }
+
+}
+
+/**
+ * traceevent_print_plugins - print out the list of plugins loaded
+ * @s: the trace_seq descripter to write to
+ * @prefix: The prefix string to add before listing the option name
+ * @suffix: The suffix string ot append after the option name
+ * @list: The list of plugins (usually returned by traceevent_load_plugins()
+ *
+ * Writes to the trace_seq @s the list of plugins (files) that is
+ * returned by traceevent_load_plugins(). Use @prefix and @suffix for formating:
+ * @prefix = " ", @suffix = "\n".
+ */
+void traceevent_print_plugins(struct trace_seq *s,
+ const char *prefix, const char *suffix,
+ const struct plugin_list *list)
+{
+ while (list) {
+ trace_seq_printf(s, "%s%s%s", prefix, list->name, suffix);
+ list = list->next;
+ }
+}
+
static void
load_plugin(struct pevent *pevent, const char *path,
const char *file, void *data)
--
1.8.5.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/3] tools lib traceevent: Add options to function plugin
2014-04-22 19:48 [PATCH 0/3] tools lib traceevent: Options for plugins Steven Rostedt
2014-04-22 19:48 ` [PATCH 1/3] tools lib traceevent: Add flag to not load event plugins Steven Rostedt
2014-04-22 19:48 ` [PATCH 2/3] tools lib traceevent: Add options to plugins Steven Rostedt
@ 2014-04-22 19:48 ` Steven Rostedt
2014-04-23 6:07 ` [PATCH 0/3] tools lib traceevent: Options for plugins Namhyung Kim
3 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2014-04-22 19:48 UTC (permalink / raw)
To: linux-kernel
Cc: Ingo Molnar, Arnaldo Carvalho de Melo, Jiri Olsa, Namhyung Kim,
Andrew Morton
[-- Attachment #1: 0003-tools-lib-traceevent-Add-options-to-function-plugin.patch --]
[-- Type: text/plain, Size: 4182 bytes --]
From: "Steven Rostedt (Red Hat)" <rostedt@goodmis.org>
Add the options "parent" and "indent" to the function plugin.
When parent is set, the output looks like this:
function: fsnotify_modify <-- vfs_write
function: zone_statistics <-- get_page_from_freelist
function: __inc_zone_state <-- zone_statistics
function: inotify_inode_queue_event <-- fsnotify_modify
function: fsnotify_parent <-- fsnotify_modify
function: __inc_zone_state <-- zone_statistics
function: __fsnotify_parent <-- fsnotify_parent
function: inotify_dentry_parent_queue_event <-- fsnotify_parent
function: add_to_page_cache_lru <-- do_read_cache_page
When it's not set, it looks like:
function: fsnotify_modify
function: zone_statistics
function: __inc_zone_state
function: inotify_inode_queue_event
function: fsnotify_parent
function: __inc_zone_state
function: __fsnotify_parent
function: inotify_dentry_parent_queue_event
function: add_to_page_cache_lru
When the otpion "indent" is not set, it looks like this:
function: fsnotify_modify <-- vfs_write
function: zone_statistics <-- get_page_from_freelist
function: __inc_zone_state <-- zone_statistics
function: inotify_inode_queue_event <-- fsnotify_modify
function: fsnotify_parent <-- fsnotify_modify
function: __inc_zone_state <-- zone_statistics
function: __fsnotify_parent <-- fsnotify_parent
function: inotify_dentry_parent_queue_event <-- fsnotify_parent
function: add_to_page_cache_lru <-- do_read_cache_page
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
tools/lib/traceevent/plugin_function.c | 43 +++++++++++++++++++++++++++++-----
1 file changed, 37 insertions(+), 6 deletions(-)
diff --git a/tools/lib/traceevent/plugin_function.c b/tools/lib/traceevent/plugin_function.c
index 80ba4ff..a00ec19 100644
--- a/tools/lib/traceevent/plugin_function.c
+++ b/tools/lib/traceevent/plugin_function.c
@@ -33,6 +33,29 @@ static int cpus = -1;
#define STK_BLK 10
+struct pevent_plugin_option plugin_options[] =
+{
+ {
+ .name = "parent",
+ .plugin_alias = "ftrace",
+ .description =
+ "Print parent of functions for function events",
+ },
+ {
+ .name = "indent",
+ .plugin_alias = "ftrace",
+ .description =
+ "Try to show function call indents, based on parents",
+ .set = 1,
+ },
+ {
+ .name = NULL,
+ }
+};
+
+static struct pevent_plugin_option *ftrace_parent = &plugin_options[0];
+static struct pevent_plugin_option *ftrace_indent = &plugin_options[1];
+
static void add_child(struct func_stack *stack, const char *child, int pos)
{
int i;
@@ -119,7 +142,8 @@ static int function_handler(struct trace_seq *s, struct pevent_record *record,
parent = pevent_find_function(pevent, pfunction);
- index = add_and_get_index(parent, func, record->cpu);
+ if (parent && ftrace_indent->set)
+ index = add_and_get_index(parent, func, record->cpu);
trace_seq_printf(s, "%*s", index*3, "");
@@ -128,11 +152,13 @@ static int function_handler(struct trace_seq *s, struct pevent_record *record,
else
trace_seq_printf(s, "0x%llx", function);
- trace_seq_printf(s, " <-- ");
- if (parent)
- trace_seq_printf(s, "%s", parent);
- else
- trace_seq_printf(s, "0x%llx", pfunction);
+ if (ftrace_parent->set) {
+ trace_seq_printf(s, " <-- ");
+ if (parent)
+ trace_seq_printf(s, "%s", parent);
+ else
+ trace_seq_printf(s, "0x%llx", pfunction);
+ }
return 0;
}
@@ -141,6 +167,9 @@ int PEVENT_PLUGIN_LOADER(struct pevent *pevent)
{
pevent_register_event_handler(pevent, -1, "ftrace", "function",
function_handler, NULL);
+
+ traceevent_plugin_add_options("ftrace", plugin_options);
+
return 0;
}
@@ -157,6 +186,8 @@ void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent)
free(fstack[i].stack);
}
+ traceevent_plugin_remove_options(plugin_options);
+
free(fstack);
fstack = NULL;
cpus = -1;
--
1.8.5.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] tools lib traceevent: Options for plugins
2014-04-22 19:48 [PATCH 0/3] tools lib traceevent: Options for plugins Steven Rostedt
` (2 preceding siblings ...)
2014-04-22 19:48 ` [PATCH 3/3] tools lib traceevent: Add options to function plugin Steven Rostedt
@ 2014-04-23 6:07 ` Namhyung Kim
3 siblings, 0 replies; 5+ messages in thread
From: Namhyung Kim @ 2014-04-23 6:07 UTC (permalink / raw)
To: Steven Rostedt
Cc: linux-kernel, Ingo Molnar, Arnaldo Carvalho de Melo, Jiri Olsa,
Andrew Morton
Hi Steven,
On Tue, 22 Apr 2014 15:48:24 -0400, Steven Rostedt wrote:
> trace-cmd has a way to set options for plugins, via the command
> line parameter. For example, you can add or remove the parent
> from being printed in function tracing by adding:
>
> -O parent=1
> -O parent=0
>
> This is passed later to the plugin in. But the plugin itself requires
> registering to the application what options it supplies.
>
> This is a three patch series. The first is to set a flag in pevent
> that would prevent plugins from being loaded. This can be supplied
> by the command line as well to produce the old "raw" events.
>
> The second patch adds the infrastructure to let plugins have options.
>
> The third patch adds the options "parent" and "indent" to the
> function plugin. The indent option lets the user print functions
> with or without indenting by their parents.
>
> All that needs to be done now is to add the options to the perf
> command line. Namhyung? ;-)
Well, I'll think about it, maybe next week (or later ;-p)?
Thanks,
Namhyung
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-04-23 6:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-22 19:48 [PATCH 0/3] tools lib traceevent: Options for plugins Steven Rostedt
2014-04-22 19:48 ` [PATCH 1/3] tools lib traceevent: Add flag to not load event plugins Steven Rostedt
2014-04-22 19:48 ` [PATCH 2/3] tools lib traceevent: Add options to plugins Steven Rostedt
2014-04-22 19:48 ` [PATCH 3/3] tools lib traceevent: Add options to function plugin Steven Rostedt
2014-04-23 6:07 ` [PATCH 0/3] tools lib traceevent: Options for plugins Namhyung Kim
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox