From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 6/7] trace-cmd,libtraceevent: Remove API for plugin print
Date: Wed, 22 Jan 2020 17:00:01 +0200 [thread overview]
Message-ID: <20200122150002.763233-7-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20200122150002.763233-1-tz.stoyanov@gmail.com>
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(-)
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;
--
2.24.1
next prev parent reply other threads:[~2020-01-22 15:00 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-22 14:59 [PATCH 0/7] trace-cmd,libtraceevent: Rework of plugin options APIs Tzvetomir Stoyanov (VMware)
2020-01-22 14:59 ` [PATCH 1/7] trace-cmd,libtraceevent: Plugin options rework Tzvetomir Stoyanov (VMware)
2020-01-22 14:59 ` [PATCH 2/7] trace-cmd,libtraceevent: Remove TEP_PLUGIN_OPTIONS Tzvetomir Stoyanov (VMware)
2020-01-22 14:59 ` [PATCH 3/7] trace-cmd,libtraceevent: Check for plugin options duplication Tzvetomir Stoyanov (VMware)
2020-01-22 14:59 ` [PATCH 4/7] trace-cmd,libtraceevent: Check for plugin duplication Tzvetomir Stoyanov (VMware)
2020-01-22 15:00 ` [PATCH 5/7] trace-cmd,libtraceevent: Remove API for plugin options print Tzvetomir Stoyanov (VMware)
2020-01-22 15:00 ` Tzvetomir Stoyanov (VMware) [this message]
2020-01-22 15:00 ` [PATCH 7/7] trace-cmd, kernelshark, libtraceevent: Changed tep_plugin_add_option() API Tzvetomir Stoyanov (VMware)
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=20200122150002.763233-7-tz.stoyanov@gmail.com \
--to=tz.stoyanov@gmail.com \
--cc=linux-trace-devel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).