Commit c3ca8d44 authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

perf tools: Add perf_config_scan()

To simplify getting a single config value, add a function to scan a config
variable.
Reviewed-by: default avatarAndi Kleen <ak@linux.intel.com>
Reviewed-by: default avatarNamhyung Kim <namhyung@kernel.org>
Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20220905073424.3971-2-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 016f2f98
......@@ -908,3 +908,34 @@ void set_buildid_dir(const char *dir)
/* for communicating with external commands */
setenv("PERF_BUILDID_DIR", buildid_dir, 1);
}
struct perf_config_scan_data {
const char *name;
const char *fmt;
va_list args;
int ret;
};
static int perf_config_scan_cb(const char *var, const char *value, void *data)
{
struct perf_config_scan_data *d = data;
if (!strcmp(var, d->name))
d->ret = vsscanf(value, d->fmt, d->args);
return 0;
}
int perf_config_scan(const char *name, const char *fmt, ...)
{
struct perf_config_scan_data d = {
.name = name,
.fmt = fmt,
};
va_start(d.args, fmt);
perf_config(perf_config_scan_cb, &d);
va_end(d.args);
return d.ret;
}
......@@ -29,6 +29,7 @@ typedef int (*config_fn_t)(const char *, const char *, void *);
int perf_default_config(const char *, const char *, void *);
int perf_config(config_fn_t fn, void *);
int perf_config_scan(const char *name, const char *fmt, ...) __scanf(2, 3);
int perf_config_set(struct perf_config_set *set,
config_fn_t fn, void *data);
int perf_config_int(int *dest, const char *, const char *);
......
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