1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00

perf config: Add a function to set one variable in .perfconfig

To allow for setting a variable from some other tool, like with the
"wallclock" patchset needs to allow the user to opt-in to having
that key in the sort order for 'perf report'.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@linaro.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: https://lore.kernel.org/lkml/Z4akewi7UPXpagce@x1
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2025-01-14 15:05:56 -03:00
parent 1ab138febc
commit e9cbc854d8
2 changed files with 39 additions and 0 deletions

View file

@ -154,6 +154,44 @@ static int parse_config_arg(char *arg, char **var, char **value)
return 0;
}
int perf_config__set_variable(const char *var, const char *value)
{
char path[PATH_MAX];
char *user_config = mkpath(path, sizeof(path), "%s/.perfconfig", getenv("HOME"));
const char *config_filename;
struct perf_config_set *set;
int ret = -1;
if (use_system_config)
config_exclusive_filename = perf_etc_perfconfig();
else if (use_user_config)
config_exclusive_filename = user_config;
if (!config_exclusive_filename)
config_filename = user_config;
else
config_filename = config_exclusive_filename;
set = perf_config_set__new();
if (!set)
goto out_err;
if (perf_config_set__collect(set, config_filename, var, value) < 0) {
pr_err("Failed to add '%s=%s'\n", var, value);
goto out_err;
}
if (set_config(set, config_filename) < 0) {
pr_err("Failed to set the configs on %s\n", config_filename);
goto out_err;
}
ret = 0;
out_err:
perf_config_set__delete(set);
return ret;
}
int cmd_config(int argc, const char **argv)
{
int i, ret = -1;

View file

@ -50,6 +50,7 @@ int perf_config_set__collect(struct perf_config_set *set, const char *file_name,
const char *var, const char *value);
void perf_config__exit(void);
void perf_config__refresh(void);
int perf_config__set_variable(const char *var, const char *value);
/**
* perf_config_sections__for_each - iterate thru all the sections