Skip to content

Commit e9cbc85

Browse files
committed
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>
1 parent 1ab138f commit e9cbc85

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tools/perf/builtin-config.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,44 @@ static int parse_config_arg(char *arg, char **var, char **value)
154154
return 0;
155155
}
156156

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+
157195
int cmd_config(int argc, const char **argv)
158196
{
159197
int i, ret = -1;

tools/perf/util/config.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ int perf_config_set__collect(struct perf_config_set *set, const char *file_name,
5050
const char *var, const char *value);
5151
void perf_config__exit(void);
5252
void perf_config__refresh(void);
53+
int perf_config__set_variable(const char *var, const char *value);
5354

5455
/**
5556
* perf_config_sections__for_each - iterate thru all the sections

0 commit comments

Comments
 (0)