diff options
Diffstat (limited to 'tools/perf/builtin-config.c')
-rw-r--r-- | tools/perf/builtin-config.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c index f04e804a9fad..c42448ed5dfe 100644 --- a/tools/perf/builtin-config.c +++ b/tools/perf/builtin-config.c | |||
@@ -13,8 +13,10 @@ | |||
13 | #include "util/util.h" | 13 | #include "util/util.h" |
14 | #include "util/debug.h" | 14 | #include "util/debug.h" |
15 | 15 | ||
16 | static bool use_system_config, use_user_config; | ||
17 | |||
16 | static const char * const config_usage[] = { | 18 | static const char * const config_usage[] = { |
17 | "perf config [options]", | 19 | "perf config [<file-option>] [options]", |
18 | NULL | 20 | NULL |
19 | }; | 21 | }; |
20 | 22 | ||
@@ -25,6 +27,8 @@ enum actions { | |||
25 | static struct option config_options[] = { | 27 | static struct option config_options[] = { |
26 | OPT_SET_UINT('l', "list", &actions, | 28 | OPT_SET_UINT('l', "list", &actions, |
27 | "show current config variables", ACTION_LIST), | 29 | "show current config variables", ACTION_LIST), |
30 | OPT_BOOLEAN(0, "system", &use_system_config, "use system config file"), | ||
31 | OPT_BOOLEAN(0, "user", &use_user_config, "use user config file"), | ||
28 | OPT_END() | 32 | OPT_END() |
29 | }; | 33 | }; |
30 | 34 | ||
@@ -42,10 +46,23 @@ static int show_config(const char *key, const char *value, | |||
42 | int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused) | 46 | int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused) |
43 | { | 47 | { |
44 | int ret = 0; | 48 | int ret = 0; |
49 | char *user_config = mkpath("%s/.perfconfig", getenv("HOME")); | ||
45 | 50 | ||
46 | argc = parse_options(argc, argv, config_options, config_usage, | 51 | argc = parse_options(argc, argv, config_options, config_usage, |
47 | PARSE_OPT_STOP_AT_NON_OPTION); | 52 | PARSE_OPT_STOP_AT_NON_OPTION); |
48 | 53 | ||
54 | if (use_system_config && use_user_config) { | ||
55 | pr_err("Error: only one config file at a time\n"); | ||
56 | parse_options_usage(config_usage, config_options, "user", 0); | ||
57 | parse_options_usage(NULL, config_options, "system", 0); | ||
58 | return -1; | ||
59 | } | ||
60 | |||
61 | if (use_system_config) | ||
62 | config_exclusive_filename = perf_etc_perfconfig(); | ||
63 | else if (use_user_config) | ||
64 | config_exclusive_filename = user_config; | ||
65 | |||
49 | switch (actions) { | 66 | switch (actions) { |
50 | case ACTION_LIST: | 67 | case ACTION_LIST: |
51 | if (argc) { | 68 | if (argc) { |
@@ -53,9 +70,13 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused) | |||
53 | parse_options_usage(config_usage, config_options, "l", 1); | 70 | parse_options_usage(config_usage, config_options, "l", 1); |
54 | } else { | 71 | } else { |
55 | ret = perf_config(show_config, NULL); | 72 | ret = perf_config(show_config, NULL); |
56 | if (ret < 0) | 73 | if (ret < 0) { |
74 | const char * config_filename = config_exclusive_filename; | ||
75 | if (!config_exclusive_filename) | ||
76 | config_filename = user_config; | ||
57 | pr_err("Nothing configured, " | 77 | pr_err("Nothing configured, " |
58 | "please check your ~/.perfconfig file\n"); | 78 | "please check your %s \n", config_filename); |
79 | } | ||
59 | } | 80 | } |
60 | break; | 81 | break; |
61 | default: | 82 | default: |