public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Steven Rostedt <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: acme@redhat.com, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org, jolsa@redhat.com,
	tglx@linutronix.de, hpa@zytor.com, rostedt@goodmis.org,
	srostedt@redhat.com, mingo@kernel.org, namhyung@kernel.org
Subject: [tip:perf/core] tools lib traceevent: Make plugin options either string or boolean
Date: Tue, 24 Mar 2015 09:34:28 -0700	[thread overview]
Message-ID: <tip-5dbcfd930e430b33fb4dfded9c1af0cf432772b9@git.kernel.org> (raw)
In-Reply-To: <20150324135923.308372986@goodmis.org>

Commit-ID:  5dbcfd930e430b33fb4dfded9c1af0cf432772b9
Gitweb:     http://git.kernel.org/tip/5dbcfd930e430b33fb4dfded9c1af0cf432772b9
Author:     Steven Rostedt <srostedt@redhat.com>
AuthorDate: Tue, 24 Mar 2015 09:57:54 -0400
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Tue, 24 Mar 2015 12:20:09 -0300

tools lib traceevent: Make plugin options either string or boolean

When a plugin option is defined, by default it is a boolean (true or false).

If the option is something else, then it needs to set its "value" field to
a default string other than NULL (can be just "").

If the value is not set then the option is considered boolean, and the
updating of the option value will be handled accordingly.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150324135923.308372986@goodmis.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/traceevent/event-parse.h  |  6 +++-
 tools/lib/traceevent/event-plugin.c | 60 +++++++++++++++++++++++++++++++++----
 2 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h
index 8bd7c6a..8ca1b8e 100644
--- a/tools/lib/traceevent/event-parse.h
+++ b/tools/lib/traceevent/event-parse.h
@@ -116,7 +116,7 @@ struct pevent_plugin_option {
 	char				*name;
 	char				*plugin_alias;
 	char				*description;
-	char				*value;
+	const char			*value;
 	void				*priv;
 	int				set;
 };
@@ -154,6 +154,10 @@ struct pevent_plugin_option {
  *   .plugin_alias is used to give a shorter name to access
  *   the vairable. Useful if a plugin handles more than one event.
  *
+ *   If .value is not set, then it is considered a boolean and only
+ *   .set will be processed. If .value is defined, then it is considered
+ *   a string option and .set will be ignored.
+ *
  * PEVENT_PLUGIN_ALIAS: (optional)
  *   The name to use for finding options (uses filename if not defined)
  */
diff --git a/tools/lib/traceevent/event-plugin.c b/tools/lib/traceevent/event-plugin.c
index 136162c..a16756a 100644
--- a/tools/lib/traceevent/event-plugin.c
+++ b/tools/lib/traceevent/event-plugin.c
@@ -18,6 +18,7 @@
  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  */
 
+#include <ctype.h>
 #include <stdio.h>
 #include <string.h>
 #include <dlfcn.h>
@@ -49,6 +50,52 @@ struct plugin_list {
 	void			*handle;
 };
 
+static void lower_case(char *str)
+{
+	if (!str)
+		return;
+	for (; *str; str++)
+		*str = tolower(*str);
+}
+
+static int update_option_value(struct pevent_plugin_option *op, const char *val)
+{
+	char *op_val;
+
+	if (!val) {
+		/* toggle, only if option is boolean */
+		if (op->value)
+			/* Warn? */
+			return 0;
+		op->set ^= 1;
+		return 0;
+	}
+
+	/*
+	 * If the option has a value then it takes a string
+	 * otherwise the option is a boolean.
+	 */
+	if (op->value) {
+		op->value = val;
+		return 0;
+	}
+
+	/* Option is boolean, must be either "1", "0", "true" or "false" */
+
+	op_val = strdup(val);
+	if (!op_val)
+		return -1;
+	lower_case(op_val);
+
+	if (strcmp(val, "1") == 0 || strcmp(val, "true") == 0)
+		op->set = 1;
+	else if (strcmp(val, "0") == 0 || strcmp(val, "false") == 0)
+		op->set = 0;
+	free(op_val);
+
+	return 0;
+}
+
 /**
  * traceevent_plugin_list_options - get list of plugin options
  *
@@ -120,6 +167,7 @@ update_option(const char *file, struct pevent_plugin_option *option)
 {
 	struct trace_plugin_options *op;
 	char *plugin;
+	int ret = 0;
 
 	if (option->plugin_alias) {
 		plugin = strdup(option->plugin_alias);
@@ -144,9 +192,10 @@ update_option(const char *file, struct pevent_plugin_option *option)
 		if (strcmp(op->option, option->name) != 0)
 			continue;
 
-		option->value = op->value;
-		option->set ^= 1;
-		goto out;
+		ret = update_option_value(option, op->value);
+		if (ret)
+			goto out;
+		break;
 	}
 
 	/* first look for unnamed options */
@@ -156,14 +205,13 @@ update_option(const char *file, struct pevent_plugin_option *option)
 		if (strcmp(op->option, option->name) != 0)
 			continue;
 
-		option->value = op->value;
-		option->set ^= 1;
+		ret = update_option_value(option, op->value);
 		break;
 	}
 
  out:
 	free(plugin);
-	return 0;
+	return ret;
 }
 
 /**

  reply	other threads:[~2015-03-24 16:34 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-24 13:57 [PATCH 0/9] tools lib traceevent: Pulling in updates from trace-cmd Steven Rostedt
2015-03-24 13:57 ` [PATCH 1/9] tools lib traceevent: Handle NULL comm name Steven Rostedt
2015-03-24 16:33   ` [tip:perf/core] " tip-bot for Josef Bacik
2015-03-24 13:57 ` [PATCH 2/9] tools lib traceevent: Copy trace_clock and free it Steven Rostedt
2015-03-24 15:14   ` Arnaldo Carvalho de Melo
2015-03-24 15:43     ` Steven Rostedt
2015-03-24 16:33   ` [tip:perf/core] " tip-bot for Steven Rostedt (Red Hat)
2015-03-24 13:57 ` [PATCH 3/9] tools lib traceevent: Handle %z in bprint format Steven Rostedt
2015-03-24 16:33   ` [tip:perf/core] " tip-bot for Steven Rostedt (Red Hat)
2015-03-24 13:57 ` [PATCH 4/9] tools lib traceevent: Add pevent_data_pid_from_comm() Steven Rostedt
2015-03-24 15:16   ` Arnaldo Carvalho de Melo
2015-03-24 16:34   ` [tip:perf/core] " tip-bot for Steven Rostedt (Red Hat)
2015-03-24 13:57 ` [PATCH 5/9] tools lib traceevent: Fix whitespace error Steven Rostedt
2015-03-24 15:19   ` Arnaldo Carvalho de Melo
2015-03-24 15:37     ` Steven Rostedt
2015-03-24 13:57 ` [PATCH 6/9] tools lib traceevent: Make plugin options either string or boolean Steven Rostedt
2015-03-24 16:34   ` tip-bot for Steven Rostedt [this message]
2015-03-24 13:57 ` [PATCH 7/9] tools lib traceevent kbuffer: Remove extra update to data pointer in PADDING Steven Rostedt
2015-03-24 16:34   ` [tip:perf/core] " tip-bot for Steven Rostedt (Red Hat)
2015-03-24 13:57 ` [PATCH 8/9] tools lib traceevent: Add way to find sub buffer boundary Steven Rostedt
2015-03-24 16:35   ` [tip:perf/core] " tip-bot for Steven Rostedt (Red Hat)
2015-03-24 13:57 ` [PATCH 9/9] tools lib traceevent: Free filter tokens in process_filter() Steven Rostedt
2015-03-24 16:35   ` [tip:perf/core] " tip-bot for Steven Rostedt (Red Hat)
2015-03-24 14:57 ` [PATCH 0/9] tools lib traceevent: Pulling in updates from trace-cmd Arnaldo Carvalho de Melo
2015-03-24 15:04   ` Steven Rostedt
2015-03-24 15:25     ` Arnaldo Carvalho de Melo
2015-03-24 15:26     ` Arnaldo Carvalho de Melo
2015-03-24 15:44       ` Steven Rostedt
2015-03-24 15:45         ` Steven Rostedt
2015-03-24 15:51           ` Arnaldo Carvalho de Melo
2015-03-24 16:19             ` Steven Rostedt

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=tip-5dbcfd930e430b33fb4dfded9c1af0cf432772b9@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=acme@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=hpa@zytor.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=srostedt@redhat.com \
    --cc=tglx@linutronix.de \
    /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