From: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org
Subject: [PATCH 7/7] trace-cmd, kernelshark, libtraceevent: Changed tep_plugin_add_option() API
Date: Wed, 22 Jan 2020 17:00:02 +0200 [thread overview]
Message-ID: <20200122150002.763233-8-tz.stoyanov@gmail.com> (raw)
In-Reply-To: <20200122150002.763233-1-tz.stoyanov@gmail.com>
The API
tep_plugin_add_option()
is renamed to
tep_plugin_set_option()
The new name describes more closely the purpose of the API -
it lets us update the option's value. The logic of the API is
slightly changed: If no plugin is given, all options that match
the option name will be updated.
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
include/traceevent/event-parse.h | 2 +-
kernel-shark/src/libkshark.c | 4 ++--
lib/traceevent/event-plugin.c | 30 +++++++++++++++++++++++-------
tracecmd/trace-read.c | 2 +-
4 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/include/traceevent/event-parse.h b/include/traceevent/event-parse.h
index a64482d..538dd94 100644
--- a/include/traceevent/event-parse.h
+++ b/include/traceevent/event-parse.h
@@ -368,7 +368,7 @@ void tep_walk_plugins(const struct tep_plugin_list *list,
int tep_plugin_add_options(const char *name,
struct tep_plugin_option *options);
-int tep_plugin_add_option(const char *name, const char *val);
+int tep_plugin_set_option(const char *name, const char *val);
void tep_plugin_remove_options(struct tep_plugin_option *options);
void tep_plugin_walk_options(int (*callback)(struct tep_plugin_option *op,
void *context),
diff --git a/kernel-shark/src/libkshark.c b/kernel-shark/src/libkshark.c
index a361578..34fa007 100644
--- a/kernel-shark/src/libkshark.c
+++ b/kernel-shark/src/libkshark.c
@@ -160,8 +160,8 @@ bool kshark_open(struct kshark_context *kshark_ctx, const char *file)
* Turn off function trace indent and turn on show parent
* if possible.
*/
- tep_plugin_add_option("ftrace:parent", "1");
- tep_plugin_add_option("ftrace:indent", "0");
+ tep_plugin_set_option("ftrace:parent", "1");
+ tep_plugin_set_option("ftrace:indent", "0");
return true;
}
diff --git a/lib/traceevent/event-plugin.c b/lib/traceevent/event-plugin.c
index 1ea02e6..4af85de 100644
--- a/lib/traceevent/event-plugin.c
+++ b/lib/traceevent/event-plugin.c
@@ -219,7 +219,10 @@ static void parse_option_name(char **option, char **plugin)
*plugin = NULL;
if ((p = strstr(*option, ":"))) {
- *plugin = *option;
+ if (**option == ':')
+ *plugin = NULL;
+ else
+ *plugin = *option;
*p = '\0';
*option = strdup(p + 1);
if (!*option)
@@ -229,25 +232,38 @@ static void parse_option_name(char **option, char **plugin)
static int process_option(const char *plugin, const char *option, const char *val)
{
+ struct registered_plugin_options *reg;
struct tep_plugin_option *op;
+ int ret;
- op = find_registered_option(plugin, option);
- if (!op)
- return 0;
+ for (reg = registered_options; reg; reg = reg->next) {
+ for (op = reg->options; op->name; op++) {
+ if (plugin && strcmp(plugin, op->plugin) != 0)
+ continue;
+ if (strcmp(option, op->name) != 0)
+ continue;
- return update_option_value(op, val);
+ ret = update_option_value(op, val);
+ if (ret)
+ return ret;
+ }
+ }
+
+ return 0;
}
/**
- * tep_plugin_add_option - add an option/val pair to set plugin options
+ * tep_plugin_set_option - update the value of plugin option
* @name: The name of the option (format: <plugin>:<option> or just <option>)
* @val: (optiona) the value for the option
*
* Modify a plugin option. If @val is given than the value of the option
* is set (note, some options just take a boolean, so @val must be either
* "1" or "0" or "true" or "false").
+ * If there is no <plugin> in the @name, all options with name <option> will
+ * be updated.
*/
-int tep_plugin_add_option(const char *name, const char *val)
+int tep_plugin_set_option(const char *name, const char *val)
{
struct trace_plugin_options *op;
char *option_str;
diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c
index c0d640d..7b41d72 100644
--- a/tracecmd/trace-read.c
+++ b/tracecmd/trace-read.c
@@ -1381,7 +1381,7 @@ static void process_plugin_option(char *option)
*p = '\0';
val = p+1;
}
- tep_plugin_add_option(name, val);
+ tep_plugin_set_option(name, val);
}
static void set_event_flags(struct tep_handle *pevent, struct event_str *list,
--
2.24.1
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 ` [PATCH 6/7] trace-cmd,libtraceevent: Remove API for plugin print Tzvetomir Stoyanov (VMware)
2020-01-22 15:00 ` Tzvetomir Stoyanov (VMware) [this message]
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-8-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).