Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+39
+38
tools/perf/builtin-config.c
··· 154 154 return 0; 155 155 } 156 156 157 + int perf_config__set_variable(const char *var, const char *value) 158 + { 159 + char path[PATH_MAX]; 160 + char *user_config = mkpath(path, sizeof(path), "%s/.perfconfig", getenv("HOME")); 161 + const char *config_filename; 162 + struct perf_config_set *set; 163 + int ret = -1; 164 + 165 + if (use_system_config) 166 + config_exclusive_filename = perf_etc_perfconfig(); 167 + else if (use_user_config) 168 + config_exclusive_filename = user_config; 169 + 170 + if (!config_exclusive_filename) 171 + config_filename = user_config; 172 + else 173 + config_filename = config_exclusive_filename; 174 + 175 + set = perf_config_set__new(); 176 + if (!set) 177 + goto out_err; 178 + 179 + if (perf_config_set__collect(set, config_filename, var, value) < 0) { 180 + pr_err("Failed to add '%s=%s'\n", var, value); 181 + goto out_err; 182 + } 183 + 184 + if (set_config(set, config_filename) < 0) { 185 + pr_err("Failed to set the configs on %s\n", config_filename); 186 + goto out_err; 187 + } 188 + 189 + ret = 0; 190 + out_err: 191 + perf_config_set__delete(set); 192 + return ret; 193 + } 194 + 157 195 int cmd_config(int argc, const char **argv) 158 196 { 159 197 int i, ret = -1;
+1
tools/perf/util/config.h
··· 50 50 const char *var, const char *value); 51 51 void perf_config__exit(void); 52 52 void perf_config__refresh(void); 53 + int perf_config__set_variable(const char *var, const char *value); 53 54 54 55 /** 55 56 * perf_config_sections__for_each - iterate thru all the sections