[6/7] trace-cmd,libtraceevent: Remove API for plugin print
diff mbox series

Message ID 20200122150002.763233-7-tz.stoyanov@gmail.com
State New, archived
Headers show
Series
  • trace-cmd,libtraceevent: Rework of plugin options APIs
Related show

Commit Message

Tzvetomir Stoyanov (VMware) Jan. 22, 2020, 3 p.m. UTC
The functionality for printing registered plugins
is moved from libtraceevent to the application.
A more generic walk API is introduced.

Removed
	tep_print_plugins()

Added
	tep_walk_plugins()

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 include/traceevent/event-parse.h |  8 ++++----
 lib/traceevent/event-plugin.c    | 23 +++++++++++------------
 tracecmd/trace-list.c            | 12 +++++++++---
 3 files changed, 24 insertions(+), 19 deletions(-)

Patch
diff mbox series

diff --git a/include/traceevent/event-parse.h b/include/traceevent/event-parse.h
index 3b4f3a5..a64482d 100644
--- a/include/traceevent/event-parse.h
+++ b/include/traceevent/event-parse.h
@@ -362,6 +362,10 @@  void tep_load_plugins_hook(struct tep_handle *tep, const char *suffix,
 					       const char *name,
 					       void *data),
 			   void *data);
+void tep_walk_plugins(const struct tep_plugin_list *list,
+		      int (*callback)(char *plugin_file, void *context),
+		      void *context);
+
 int tep_plugin_add_options(const char *name,
 			   struct tep_plugin_option *options);
 int tep_plugin_add_option(const char *name, const char *val);
@@ -370,10 +374,6 @@  void tep_plugin_walk_options(int (*callback)(struct tep_plugin_option *op,
 					     void *context),
 			     void *context);
 
-void tep_print_plugins(struct trace_seq *s,
-			const char *prefix, const char *suffix,
-			const struct tep_plugin_list *list);
-
 /* tep_handle */
 typedef char *(tep_func_resolver_t)(void *priv,
 				    unsigned long long *addrp, char **modp);
diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c
index 191b27b..1ea02e6 100644
--- a/lib/traceevent/event-plugin.c
+++ b/lib/traceevent/event-plugin.c
@@ -338,22 +338,21 @@  void tep_plugin_walk_options(int (*callback)(struct tep_plugin_option *op,
 }
 
 /**
- * tep_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 tep_load_plugins()
+ * tep_walk_plugins - walk through all plugins from the list
+ * @list: plugin list, returned by tep_load_plugins()
+ * @callback: a user function, called on each plugin from the list
+ * @context: user data, passed to @callback function
  *
- * Writes to the trace_seq @s the list of plugins (files) that is
- * returned by tep_load_plugins(). Use @prefix and @suffix for formating:
- * @prefix = "  ", @suffix = "\n".
+ * If the @callback returns non zero, the iteration stops.
  */
-void tep_print_plugins(struct trace_seq *s,
-		       const char *prefix, const char *suffix,
-		       const struct tep_plugin_list *list)
+void tep_walk_plugins(const struct tep_plugin_list *list,
+		      int (*callback)(char *plugin_file, void *context),
+		      void *context)
 {
+	if (!list || !callback)
+		return;
 	while (list) {
-		trace_seq_printf(s, "%s%s%s", prefix, list->name, suffix);
+		callback(list->name, context);
 		list = list->next;
 	}
 }
diff --git a/tracecmd/trace-list.c b/tracecmd/trace-list.c
index 496a83b..f7bef45 100644
--- a/tracecmd/trace-list.c
+++ b/tracecmd/trace-list.c
@@ -373,6 +373,14 @@  void trace_option(int argc, char **argv)
 	show_plugin_options();
 }
 
+static int plugins_walk(char *plugin_file, void *context)
+{
+	struct trace_seq *s = (struct trace_seq *)context;
+
+	if (plugin_file)
+		trace_seq_printf(s, "  %s\n", plugin_file);
+	return 0;
+}
 
 static void show_plugins(void)
 {
@@ -387,14 +395,12 @@  static void show_plugins(void)
 	trace_seq_init(&s);
 
 	list = trace_load_plugins(pevent);
-	tep_print_plugins(&s, "  ", "\n", list);
-
+	tep_walk_plugins(list, plugins_walk, &s);
 	trace_seq_do_printf(&s);
 	tep_unload_plugins(list, pevent);
 	tep_free(pevent);
 }
 
-
 void trace_list(int argc, char **argv)
 {
 	int events = 0;