aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTaeung Song <treeze.taeung@gmail.com>2016-11-04 02:44:17 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-11-14 10:52:17 -0500
commit909236083ee58399b371d085fef5cfac9bce3ec8 (patch)
treeb996bab823eca9beeaf66fcf22231df017db0511
parent8c9c3d2f950cca57f5fa9330c4d15d8f0dfda092 (diff)
perf config: Add support for getting config key-value pairs
Add a functionality getting specific config key-value pairs. For the syntax examples, perf config [<file-option>] [section.name ...] e.g. To query config items 'report.queue-size' and 'report.children', do # perf config report.queue-size report.children Signed-off-by: Taeung Song <treeze.taeung@gmail.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Nambong Ha <over3025@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Wang Nan <wangnan0@huawei.com> Cc: Wookje Kwon <aweee0@gmail.com> Link: http://lkml.kernel.org/r/1478241862-31230-2-git-send-email-treeze.taeung@gmail.com [ Combined patch with docs update with this one ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/Documentation/perf-config.txt18
-rw-r--r--tools/perf/builtin-config.c40
2 files changed, 55 insertions, 3 deletions
diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index cb081ac59fd1..1714b0c8c8e1 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -8,6 +8,8 @@ perf-config - Get and set variables in a configuration file.
8SYNOPSIS 8SYNOPSIS
9-------- 9--------
10[verse] 10[verse]
11'perf config' [<file-option>] [section.name ...]
12or
11'perf config' [<file-option>] -l | --list 13'perf config' [<file-option>] -l | --list
12 14
13DESCRIPTION 15DESCRIPTION
@@ -118,6 +120,22 @@ Given a $HOME/.perfconfig like this:
118 children = true 120 children = true
119 group = true 121 group = true
120 122
123To query the record mode of call graph, do
124
125 % perf config call-graph.record-mode
126
127If you want to know multiple config key/value pairs, you can do like
128
129 % perf config report.queue-size call-graph.order report.children
130
131To query the config value of sort order of call graph in user config file (i.e. `~/.perfconfig`), do
132
133 % perf config --user call-graph.sort-order
134
135To query the config value of buildid directory in system config file (i.e. `$(sysconf)/perfconfig`), do
136
137 % perf config --system buildid.dir
138
121Variables 139Variables
122~~~~~~~~~ 140~~~~~~~~~
123 141
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index e4207a23b52c..df3fa1c18e55 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -17,7 +17,7 @@
17static bool use_system_config, use_user_config; 17static bool use_system_config, use_user_config;
18 18
19static const char * const config_usage[] = { 19static const char * const config_usage[] = {
20 "perf config [<file-option>] [options]", 20 "perf config [<file-option>] [options] [section.name ...]",
21 NULL 21 NULL
22}; 22};
23 23
@@ -33,6 +33,36 @@ static struct option config_options[] = {
33 OPT_END() 33 OPT_END()
34}; 34};
35 35
36static int show_spec_config(struct perf_config_set *set, const char *var)
37{
38 struct perf_config_section *section;
39 struct perf_config_item *item;
40
41 if (set == NULL)
42 return -1;
43
44 perf_config_items__for_each_entry(&set->sections, section) {
45 if (prefixcmp(var, section->name) != 0)
46 continue;
47
48 perf_config_items__for_each_entry(&section->items, item) {
49 const char *name = var + strlen(section->name) + 1;
50
51 if (strcmp(name, item->name) == 0) {
52 char *value = item->value;
53
54 if (value) {
55 printf("%s=%s\n", var, value);
56 return 0;
57 }
58 }
59
60 }
61 }
62
63 return 0;
64}
65
36static int show_config(struct perf_config_set *set) 66static int show_config(struct perf_config_set *set)
37{ 67{
38 struct perf_config_section *section; 68 struct perf_config_section *section;
@@ -54,7 +84,7 @@ static int show_config(struct perf_config_set *set)
54 84
55int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused) 85int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
56{ 86{
57 int ret = 0; 87 int i, ret = 0;
58 struct perf_config_set *set; 88 struct perf_config_set *set;
59 char *user_config = mkpath("%s/.perfconfig", getenv("HOME")); 89 char *user_config = mkpath("%s/.perfconfig", getenv("HOME"));
60 90
@@ -100,7 +130,11 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
100 } 130 }
101 break; 131 break;
102 default: 132 default:
103 usage_with_options(config_usage, config_options); 133 if (argc)
134 for (i = 0; argv[i]; i++)
135 ret = show_spec_config(set, argv[i]);
136 else
137 usage_with_options(config_usage, config_options);
104 } 138 }
105 139
106 perf_config_set__delete(set); 140 perf_config_set__delete(set);