Skip to content

Commit 5dbcfd9

Browse files
Steven Rostedtacmel
authored andcommitted
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>
1 parent 2771984 commit 5dbcfd9

2 files changed

Lines changed: 59 additions & 7 deletions

File tree

‎tools/lib/traceevent/event-parse.h‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ struct pevent_plugin_option {
116116
char *name;
117117
char *plugin_alias;
118118
char *description;
119-
char *value;
119+
const char *value;
120120
void *priv;
121121
int set;
122122
};
@@ -154,6 +154,10 @@ struct pevent_plugin_option {
154154
* .plugin_alias is used to give a shorter name to access
155155
* the vairable. Useful if a plugin handles more than one event.
156156
*
157+
* If .value is not set, then it is considered a boolean and only
158+
* .set will be processed. If .value is defined, then it is considered
159+
* a string option and .set will be ignored.
160+
*
157161
* PEVENT_PLUGIN_ALIAS: (optional)
158162
* The name to use for finding options (uses filename if not defined)
159163
*/

‎tools/lib/traceevent/event-plugin.c‎

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1919
*/
2020

21+
#include <ctype.h>
2122
#include <stdio.h>
2223
#include <string.h>
2324
#include <dlfcn.h>
@@ -49,6 +50,52 @@ struct plugin_list {
4950
void *handle;
5051
};
5152

53+
static void lower_case(char *str)
54+
{
55+
if (!str)
56+
return;
57+
for (; *str; str++)
58+
*str = tolower(*str);
59+
}
60+
61+
static int update_option_value(struct pevent_plugin_option *op, const char *val)
62+
{
63+
char *op_val;
64+
65+
if (!val) {
66+
/* toggle, only if option is boolean */
67+
if (op->value)
68+
/* Warn? */
69+
return 0;
70+
op->set ^= 1;
71+
return 0;
72+
}
73+
74+
/*
75+
* If the option has a value then it takes a string
76+
* otherwise the option is a boolean.
77+
*/
78+
if (op->value) {
79+
op->value = val;
80+
return 0;
81+
}
82+
83+
/* Option is boolean, must be either "1", "0", "true" or "false" */
84+
85+
op_val = strdup(val);
86+
if (!op_val)
87+
return -1;
88+
lower_case(op_val);
89+
90+
if (strcmp(val, "1") == 0 || strcmp(val, "true") == 0)
91+
op->set = 1;
92+
else if (strcmp(val, "0") == 0 || strcmp(val, "false") == 0)
93+
op->set = 0;
94+
free(op_val);
95+
96+
return 0;
97+
}
98+
5299
/**
53100
* traceevent_plugin_list_options - get list of plugin options
54101
*
@@ -120,6 +167,7 @@ update_option(const char *file, struct pevent_plugin_option *option)
120167
{
121168
struct trace_plugin_options *op;
122169
char *plugin;
170+
int ret = 0;
123171

124172
if (option->plugin_alias) {
125173
plugin = strdup(option->plugin_alias);
@@ -144,9 +192,10 @@ update_option(const char *file, struct pevent_plugin_option *option)
144192
if (strcmp(op->option, option->name) != 0)
145193
continue;
146194

147-
option->value = op->value;
148-
option->set ^= 1;
149-
goto out;
195+
ret = update_option_value(option, op->value);
196+
if (ret)
197+
goto out;
198+
break;
150199
}
151200

152201
/* first look for unnamed options */
@@ -156,14 +205,13 @@ update_option(const char *file, struct pevent_plugin_option *option)
156205
if (strcmp(op->option, option->name) != 0)
157206
continue;
158207

159-
option->value = op->value;
160-
option->set ^= 1;
208+
ret = update_option_value(option, op->value);
161209
break;
162210
}
163211

164212
out:
165213
free(plugin);
166-
return 0;
214+
return ret;
167215
}
168216

169217
/**

0 commit comments

Comments
 (0)