tools lib traceevent: Options for plugins
cover tools lib traceevent: Options for plugins
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(-)
PATCH 1/3 tools lib traceevent: Add flag to not load event plugins
From: "Steven Rostedt (Red Hat)" <[email protected]>
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.
--- tools/lib/traceevent/event-parse.h | 2 ++ tools/lib/traceevent/event-plugin.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-)
tools/lib/traceevent/event-parse.h +2 -0
@@ -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 \
tools/lib/traceevent/event-plugin.c +6 -1
@@ -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 /*
Signature · 1 line
1.8.5.3
PATCH 2/3 tools lib traceevent: Add options to plugins
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
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.
--- tools/lib/traceevent/event-parse.h | 16 ++- tools/lib/traceevent/event-plugin.c | 197 ++++++++++++++++++++++++++++++++++++ 2 files changed, 209 insertions(+), 4 deletions(-)
tools/lib/traceevent/event-parse.h +12 -4
@@ -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 ;
tools/lib/traceevent/event-plugin.c +197 -0
215 lines not on this page · raw message
Signature · 1 line
1.8.5.3
PATCH 3/3 tools lib traceevent: Add options to function plugin
In reply to Steven RostedtFrom: "Steven Rostedt (Red Hat)" <[email protected]>
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
--- tools/lib/traceevent/plugin_function.c | 43 +++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 6 deletions(-)
tools/lib/traceevent/plugin_function.c +37 -6
@@ -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 ;
Signature · 1 line
1.8.5.3
Hi Steven,
Quoted 14 lines · Steven Rostedt
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=0This 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.
Quoted 8 lines
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