Skip to content

Commit

Permalink
tracing: Break out hist trigger assignment parsing
Browse files Browse the repository at this point in the history
This will make it easier to add variables, and makes the parsing code
cleaner regardless.

Link: http://lkml.kernel.org/r/e574b3291bbe15e35a4dfc87e5395aa715701c98.1516069914.git.tom.zanussi@linux.intel.com

Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Rajvi Jingar <rajvi.jingar@intel.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
  • Loading branch information
Tom Zanussi authored and Steven Rostedt (VMware) committed Mar 10, 2018
1 parent fbd302c commit 9b1ae03
Showing 1 changed file with 51 additions and 21 deletions.
72 changes: 51 additions & 21 deletions kernel/trace/trace_events_hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,51 @@ static void destroy_hist_trigger_attrs(struct hist_trigger_attrs *attrs)
kfree(attrs);
}

static int parse_assignment(char *str, struct hist_trigger_attrs *attrs)
{
int ret = 0;

if ((strncmp(str, "key=", strlen("key=")) == 0) ||
(strncmp(str, "keys=", strlen("keys=")) == 0)) {
attrs->keys_str = kstrdup(str, GFP_KERNEL);
if (!attrs->keys_str) {
ret = -ENOMEM;
goto out;
}
} else if ((strncmp(str, "val=", strlen("val=")) == 0) ||
(strncmp(str, "vals=", strlen("vals=")) == 0) ||
(strncmp(str, "values=", strlen("values=")) == 0)) {
attrs->vals_str = kstrdup(str, GFP_KERNEL);
if (!attrs->vals_str) {
ret = -ENOMEM;
goto out;
}
} else if (strncmp(str, "sort=", strlen("sort=")) == 0) {
attrs->sort_key_str = kstrdup(str, GFP_KERNEL);
if (!attrs->sort_key_str) {
ret = -ENOMEM;
goto out;
}
} else if (strncmp(str, "name=", strlen("name=")) == 0) {
attrs->name = kstrdup(str, GFP_KERNEL);
if (!attrs->name) {
ret = -ENOMEM;
goto out;
}
} else if (strncmp(str, "size=", strlen("size=")) == 0) {
int map_bits = parse_map_size(str);

if (map_bits < 0) {
ret = map_bits;
goto out;
}
attrs->map_bits = map_bits;
} else
ret = -EINVAL;
out:
return ret;
}

static struct hist_trigger_attrs *parse_hist_trigger_attrs(char *trigger_str)
{
struct hist_trigger_attrs *attrs;
Expand All @@ -263,33 +308,18 @@ static struct hist_trigger_attrs *parse_hist_trigger_attrs(char *trigger_str)
while (trigger_str) {
char *str = strsep(&trigger_str, ":");

if ((strncmp(str, "key=", strlen("key=")) == 0) ||
(strncmp(str, "keys=", strlen("keys=")) == 0))
attrs->keys_str = kstrdup(str, GFP_KERNEL);
else if ((strncmp(str, "val=", strlen("val=")) == 0) ||
(strncmp(str, "vals=", strlen("vals=")) == 0) ||
(strncmp(str, "values=", strlen("values=")) == 0))
attrs->vals_str = kstrdup(str, GFP_KERNEL);
else if (strncmp(str, "sort=", strlen("sort=")) == 0)
attrs->sort_key_str = kstrdup(str, GFP_KERNEL);
else if (strncmp(str, "name=", strlen("name=")) == 0)
attrs->name = kstrdup(str, GFP_KERNEL);
else if (strcmp(str, "pause") == 0)
if (strchr(str, '=')) {
ret = parse_assignment(str, attrs);
if (ret)
goto free;
} else if (strcmp(str, "pause") == 0)
attrs->pause = true;
else if ((strcmp(str, "cont") == 0) ||
(strcmp(str, "continue") == 0))
attrs->cont = true;
else if (strcmp(str, "clear") == 0)
attrs->clear = true;
else if (strncmp(str, "size=", strlen("size=")) == 0) {
int map_bits = parse_map_size(str);

if (map_bits < 0) {
ret = map_bits;
goto free;
}
attrs->map_bits = map_bits;
} else {
else {
ret = -EINVAL;
goto free;
}
Expand Down

0 comments on commit 9b1ae03

Please sign in to comment.