Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script options fix #80

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tools/perf/builtin-script.c
Original file line number Diff line number Diff line change
Expand Up @@ -1523,9 +1523,9 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
"show latency attributes (irqs/preemption disabled, etc)"),
OPT_CALLBACK_NOOPT('l', "list", NULL, NULL, "list available scripts",
list_available_scripts),
OPT_CALLBACK('s', "script", NULL, "name",
"script file name (lang:script name, script name, or *)",
parse_scriptname),
OPT_CALLBACK_FINAL_OPTION('s', "script", NULL, "name",
"script file name (lang:script name, script name, or *)",
parse_scriptname),
OPT_STRING('g', "gen-script", &generate_script_lang, "lang",
"generate perf-script.xx script in specified language"),
OPT_STRING('i', "input", &input_name, "file", "input file name"),
Expand Down Expand Up @@ -1578,7 +1578,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
setup_scripting();

argc = parse_options(argc, argv, options, script_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
PARSE_OPT_KEEP_UNKNOWN);

file.path = input_name;

Expand Down
4 changes: 4 additions & 0 deletions tools/perf/util/parse-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ static int get_value(struct parse_opt_ctx_t *p,
return (*opt->callback)(opt, NULL, 0) ? (-1) : 0;
if (get_arg(p, opt, flags, &arg))
return -1;
if (opt->flags & PARSE_OPT_FINAL_OPTION)
return (*opt->callback)(opt, arg, 0)?(-1) : (-3);
return (*opt->callback)(opt, arg, 0) ? (-1) : 0;

case OPTION_INTEGER:
Expand Down Expand Up @@ -366,6 +368,8 @@ int parse_options_step(struct parse_opt_ctx_t *ctx,
return parse_options_usage(usagestr, options, arg + 1, 1);
case -2:
goto unknown;
case -3:
return PARSE_OPT_DONE;
default:
break;
}
Expand Down
5 changes: 5 additions & 0 deletions tools/perf/util/parse-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum parse_opt_option_flags {
PARSE_OPT_NONEG = 4,
PARSE_OPT_HIDDEN = 8,
PARSE_OPT_LASTARG_DEFAULT = 16,
PARSE_OPT_FINAL_OPTION = 32,
};

struct option;
Expand Down Expand Up @@ -123,6 +124,10 @@ struct option {
{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }
#define OPT_CALLBACK(s, l, v, a, h, f) \
{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f) }
#define OPT_CALLBACK_FINAL_OPTION(s, l, v, a, h, f) \
{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l),\
.value = (v), (a), .help = (h), .callback = (f),\
.flags = PARSE_OPT_FINAL_OPTION}
#define OPT_CALLBACK_NOOPT(s, l, v, a, h, f) \
{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .flags = PARSE_OPT_NOARG }
#define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d) \
Expand Down