diff options
| author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2025-01-14 21:05:56 +0300 | 
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2025-01-14 21:05:56 +0300 | 
| commit | e9cbc854d8b148e3491291fb615e94261970fb54 (patch) | |
| tree | 3e67e5c04957427b09371c0d20b99d4c68cbb143 | |
| parent | 1ab138febca6510881a0114fcfb329044fb4ed22 (diff) | |
| download | linux-e9cbc854d8b148e3491291fb615e94261970fb54.tar.xz | |
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>
| -rw-r--r-- | tools/perf/builtin-config.c | 38 | ||||
| -rw-r--r-- | tools/perf/util/config.h | 1 | 
2 files changed, 39 insertions, 0 deletions
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c index 2e8363778935..45b5312fbe83 100644 --- a/tools/perf/builtin-config.c +++ b/tools/perf/builtin-config.c @@ -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; diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h index 9971313d61c1..a727c95cb119 100644 --- a/tools/perf/util/config.h +++ b/tools/perf/util/config.h @@ -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  | 
