forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf tools: Add general function to parse sublevel options
This factors out a general function perf_parse_sublevel_options() to parse sublevel options. The 'sublevel' options is something like the '--debug' options which allow more sublevel options. Signed-off-by: Changbin Du <[email protected]> Acked-by: Namhyung Kim <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt (VMware) <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
- Loading branch information
1 parent
5b34747
commit a80abe2
Showing
4 changed files
with
99 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <stdlib.h> | ||
#include <stdint.h> | ||
#include <string.h> | ||
#include <stdio.h> | ||
|
||
#include "util/debug.h" | ||
#include "util/parse-sublevel-options.h" | ||
|
||
static int parse_one_sublevel_option(const char *str, | ||
struct sublevel_option *opts) | ||
{ | ||
struct sublevel_option *opt = opts; | ||
char *vstr, *s = strdup(str); | ||
int v = 1; | ||
|
||
if (!s) { | ||
pr_err("no memory\n"); | ||
return -1; | ||
} | ||
|
||
vstr = strchr(s, '='); | ||
if (vstr) | ||
*vstr++ = 0; | ||
|
||
while (opt->name) { | ||
if (!strcmp(s, opt->name)) | ||
break; | ||
opt++; | ||
} | ||
|
||
if (!opt->name) { | ||
pr_err("Unknown option name '%s'\n", s); | ||
free(s); | ||
return -1; | ||
} | ||
|
||
if (vstr) | ||
v = atoi(vstr); | ||
|
||
*opt->value_ptr = v; | ||
free(s); | ||
return 0; | ||
} | ||
|
||
/* parse options like --foo a=<n>,b,c... */ | ||
int perf_parse_sublevel_options(const char *str, struct sublevel_option *opts) | ||
{ | ||
char *s = strdup(str); | ||
char *p = NULL; | ||
int ret; | ||
|
||
if (!s) { | ||
pr_err("no memory\n"); | ||
return -1; | ||
} | ||
|
||
p = strtok(s, ","); | ||
while (p) { | ||
ret = parse_one_sublevel_option(p, opts); | ||
if (ret) { | ||
free(s); | ||
return ret; | ||
} | ||
|
||
p = strtok(NULL, ","); | ||
} | ||
|
||
free(s); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef _PERF_PARSE_SUBLEVEL_OPTIONS_H | ||
#define _PERF_PARSE_SUBLEVEL_OPTIONS_H | ||
|
||
struct sublevel_option { | ||
const char *name; | ||
int *value_ptr; | ||
}; | ||
|
||
int perf_parse_sublevel_options(const char *str, struct sublevel_option *opts); | ||
|
||
#endif |