perf options: Introduce OPT_U64

We have things like user_interval (-c/--count) in 'perf record' that
needs this.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent a9a4ab74
...@@ -60,6 +60,7 @@ static int get_value(struct parse_opt_ctx_t *p, ...@@ -60,6 +60,7 @@ static int get_value(struct parse_opt_ctx_t *p,
case OPTION_STRING: case OPTION_STRING:
case OPTION_INTEGER: case OPTION_INTEGER:
case OPTION_LONG: case OPTION_LONG:
case OPTION_U64:
default: default:
break; break;
} }
...@@ -141,6 +142,22 @@ static int get_value(struct parse_opt_ctx_t *p, ...@@ -141,6 +142,22 @@ static int get_value(struct parse_opt_ctx_t *p,
return opterror(opt, "expects a numerical value", flags); return opterror(opt, "expects a numerical value", flags);
return 0; return 0;
case OPTION_U64:
if (unset) {
*(u64 *)opt->value = 0;
return 0;
}
if (opt->flags & PARSE_OPT_OPTARG && !p->opt) {
*(u64 *)opt->value = opt->defval;
return 0;
}
if (get_arg(p, opt, flags, &arg))
return -1;
*(u64 *)opt->value = strtoull(arg, (char **)&s, 10);
if (*s)
return opterror(opt, "expects a numerical value", flags);
return 0;
case OPTION_END: case OPTION_END:
case OPTION_ARGUMENT: case OPTION_ARGUMENT:
case OPTION_GROUP: case OPTION_GROUP:
...@@ -487,6 +504,7 @@ int usage_with_options_internal(const char * const *usagestr, ...@@ -487,6 +504,7 @@ int usage_with_options_internal(const char * const *usagestr,
case OPTION_SET_INT: case OPTION_SET_INT:
case OPTION_SET_PTR: case OPTION_SET_PTR:
case OPTION_LONG: case OPTION_LONG:
case OPTION_U64:
break; break;
} }
......
...@@ -17,6 +17,7 @@ enum parse_opt_type { ...@@ -17,6 +17,7 @@ enum parse_opt_type {
OPTION_INTEGER, OPTION_INTEGER,
OPTION_LONG, OPTION_LONG,
OPTION_CALLBACK, OPTION_CALLBACK,
OPTION_U64,
}; };
enum parse_opt_flags { enum parse_opt_flags {
...@@ -101,6 +102,7 @@ struct option { ...@@ -101,6 +102,7 @@ struct option {
#define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) } #define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) }
#define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
#define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
#define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
#define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) } #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) }
#define OPT_DATE(s, l, v, h) \ #define OPT_DATE(s, l, v, h) \
{ .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb } { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment