From: Arnaldo Carvalho de Melo Date: Tue, 14 Jan 2025 18:05:56 +0000 (-0300) Subject: perf config: Add a function to set one variable in .perfconfig X-Git-Tag: v6.14-rc1~120^2~16 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e9cbc854d8b148e3491291fb615e94261970fb54;p=thirdparty%2Flinux.git 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 Cc: Dmitriy Vyukov Cc: Ian Rogers Cc: Ingo Molnar Cc: James Clark Cc: Jiri Olsa Cc: Kan Liang Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Stephane Eranian Link: https://lore.kernel.org/lkml/Z4akewi7UPXpagce@x1 Signed-off-by: Arnaldo Carvalho de Melo --- diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c index 2e8363778935e..45b5312fbe837 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 9971313d61c1e..a727c95cb1195 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