]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
perf config: Add a function to set one variable in .perfconfig
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 14 Jan 2025 18:05:56 +0000 (15:05 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 14 Jan 2025 18:05:56 +0000 (15:05 -0300)
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>
tools/perf/builtin-config.c
tools/perf/util/config.h

index 2e8363778935e8d576a4ddac7798020a3fbe3887..45b5312fbe8370e84986a8f0ab8641fc1a4eec6d 100644 (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;
index 9971313d61c1e5c6769a1a8dd0c75eab81d7af7c..a727c95cb1195e063fd475f7b4be42533107baad 100644 (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