diff options
author | Taeung Song <treeze.taeung@gmail.com> | 2016-02-10 12:51:17 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-02-12 08:54:46 -0500 |
commit | c7ac24178c50a01f14eebcddf5c7b7a2e54676cc (patch) | |
tree | 0b9b6aa39456b4e83b91dc6c8a0648a6ea849ce7 | |
parent | a7636d9ecfa3ab7800a7c04c1f89378229eff609 (diff) |
perf config: Add '--system' and '--user' options to select which config file is used
The '--system' option means $(sysconfdir)/perfconfig and '--user' means
$HOME/.perfconfig. If none is used, both system and user config file are
read. E.g.:
# perf config [<file-option>] [options]
With an specific config file:
# perf config --user | --system
or both user and system config file:
# perf config
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1455126685-32367-2-git-send-email-treeze.taeung@gmail.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/Documentation/perf-config.txt | 14 | ||||
-rw-r--r-- | tools/perf/builtin-config.c | 27 | ||||
-rw-r--r-- | tools/perf/util/cache.h | 3 | ||||
-rw-r--r-- | tools/perf/util/config.c | 4 |
4 files changed, 42 insertions, 6 deletions
diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt index c7158bfb1649..15949e2a7805 100644 --- a/tools/perf/Documentation/perf-config.txt +++ b/tools/perf/Documentation/perf-config.txt | |||
@@ -8,7 +8,7 @@ perf-config - Get and set variables in a configuration file. | |||
8 | SYNOPSIS | 8 | SYNOPSIS |
9 | -------- | 9 | -------- |
10 | [verse] | 10 | [verse] |
11 | 'perf config' -l | --list | 11 | 'perf config' [<file-option>] -l | --list |
12 | 12 | ||
13 | DESCRIPTION | 13 | DESCRIPTION |
14 | ----------- | 14 | ----------- |
@@ -21,6 +21,14 @@ OPTIONS | |||
21 | --list:: | 21 | --list:: |
22 | Show current config variables, name and value, for all sections. | 22 | Show current config variables, name and value, for all sections. |
23 | 23 | ||
24 | --user:: | ||
25 | For writing and reading options: write to user | ||
26 | '$HOME/.perfconfig' file or read it. | ||
27 | |||
28 | --system:: | ||
29 | For writing and reading options: write to system-wide | ||
30 | '$(sysconfdir)/perfconfig' or read it. | ||
31 | |||
24 | CONFIGURATION FILE | 32 | CONFIGURATION FILE |
25 | ------------------ | 33 | ------------------ |
26 | 34 | ||
@@ -30,6 +38,10 @@ The '$HOME/.perfconfig' file is used to store a per-user configuration. | |||
30 | The file '$(sysconfdir)/perfconfig' can be used to | 38 | The file '$(sysconfdir)/perfconfig' can be used to |
31 | store a system-wide default configuration. | 39 | store a system-wide default configuration. |
32 | 40 | ||
41 | When reading or writing, the values are read from the system and user | ||
42 | configuration files by default, and options '--system' and '--user' | ||
43 | can be used to tell the command to read from or write to only that location. | ||
44 | |||
33 | Syntax | 45 | Syntax |
34 | ~~~~~~ | 46 | ~~~~~~ |
35 | 47 | ||
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: |
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h index 07b5d63947b1..3ca453f0c51f 100644 --- a/tools/perf/util/cache.h +++ b/tools/perf/util/cache.h | |||
@@ -23,6 +23,8 @@ | |||
23 | #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" | 23 | #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" |
24 | #define PERF_PAGER_ENVIRONMENT "PERF_PAGER" | 24 | #define PERF_PAGER_ENVIRONMENT "PERF_PAGER" |
25 | 25 | ||
26 | extern const char *config_exclusive_filename; | ||
27 | |||
26 | typedef int (*config_fn_t)(const char *, const char *, void *); | 28 | typedef int (*config_fn_t)(const char *, const char *, void *); |
27 | extern int perf_default_config(const char *, const char *, void *); | 29 | extern int perf_default_config(const char *, const char *, void *); |
28 | extern int perf_config(config_fn_t fn, void *); | 30 | extern int perf_config(config_fn_t fn, void *); |
@@ -31,6 +33,7 @@ extern u64 perf_config_u64(const char *, const char *); | |||
31 | extern int perf_config_bool(const char *, const char *); | 33 | extern int perf_config_bool(const char *, const char *); |
32 | extern int config_error_nonbool(const char *); | 34 | extern int config_error_nonbool(const char *); |
33 | extern const char *perf_config_dirname(const char *, const char *); | 35 | extern const char *perf_config_dirname(const char *, const char *); |
36 | extern const char *perf_etc_perfconfig(void); | ||
34 | 37 | ||
35 | char *alias_lookup(const char *alias); | 38 | char *alias_lookup(const char *alias); |
36 | int split_cmdline(char *cmdline, const char ***argv); | 39 | int split_cmdline(char *cmdline, const char ***argv); |
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c index d3e12e30e1d5..4e727635476e 100644 --- a/tools/perf/util/config.c +++ b/tools/perf/util/config.c | |||
@@ -26,7 +26,7 @@ static const char *config_file_name; | |||
26 | static int config_linenr; | 26 | static int config_linenr; |
27 | static int config_file_eof; | 27 | static int config_file_eof; |
28 | 28 | ||
29 | static const char *config_exclusive_filename; | 29 | const char *config_exclusive_filename; |
30 | 30 | ||
31 | static int get_next_char(void) | 31 | static int get_next_char(void) |
32 | { | 32 | { |
@@ -434,7 +434,7 @@ static int perf_config_from_file(config_fn_t fn, const char *filename, void *dat | |||
434 | return ret; | 434 | return ret; |
435 | } | 435 | } |
436 | 436 | ||
437 | static const char *perf_etc_perfconfig(void) | 437 | const char *perf_etc_perfconfig(void) |
438 | { | 438 | { |
439 | static const char *system_wide; | 439 | static const char *system_wide; |
440 | if (!system_wide) | 440 | if (!system_wide) |