aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorTaeung Song <treeze.taeung@gmail.com>2016-11-04 02:44:20 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-11-14 11:08:11 -0500
commitc6fc018a7a64c2c3ea56529fd8d0ca0f43408b0f (patch)
treeaa04093a5c7428ccca5cb8b8b5c498cb537445a4 /tools/perf
parent36662794bb520be828df8e2f3404264f5e7a7973 (diff)
perf config: Add support setting variables in a config file
Add setting feature that can add config variables with their values to a config file (i.e. user or system config file) or modify config key-value pairs in a config file. For the syntax examples: perf config [<file-option>] [section.name[=value] ...] e.g. You can set the ui.show-headers to false with # perf config ui.show-headers=false If you want to add or modify several config items, you can do like # perf config annotate.show_nr_jumps=false kmem.default=slab Committer notes: Testing it: $ perf config -l top.children=true report.children=false $ $ perf config top.children=false $ perf config -l top.children=false report.children=false $ $ perf config kmem.default=slab $ perf config -l top.children=false report.children=false kmem.default=slab $ 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-5-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>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/Documentation/perf-config.txt19
-rw-r--r--tools/perf/builtin-config.c68
-rw-r--r--tools/perf/util/config.c6
-rw-r--r--tools/perf/util/config.h2
4 files changed, 88 insertions, 7 deletions
diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index 1714b0c8c8e1..9365b75fd04f 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.
8SYNOPSIS 8SYNOPSIS
9-------- 9--------
10[verse] 10[verse]
11'perf config' [<file-option>] [section.name ...] 11'perf config' [<file-option>] [section.name[=value] ...]
12or 12or
13'perf config' [<file-option>] -l | --list 13'perf config' [<file-option>] -l | --list
14 14
@@ -120,6 +120,23 @@ Given a $HOME/.perfconfig like this:
120 children = true 120 children = true
121 group = true 121 group = true
122 122
123You can hide source code of annotate feature setting the config to false with
124
125 % perf config annotate.hide_src_code=true
126
127If you want to add or modify several config items, you can do like
128
129 % perf config ui.show-headers=false kmem.default=slab
130
131To modify the sort order of report functionality in user config file(i.e. `~/.perfconfig`), do
132
133 % perf config --user report sort-order=srcline
134
135To change colors of selected line to other foreground and background colors
136in system config file (i.e. `$(sysconf)/perfconfig`), do
137
138 % perf config --system colors.selected=yellow,green
139
123To query the record mode of call graph, do 140To query the record mode of call graph, do
124 141
125 % perf config call-graph.record-mode 142 % perf config call-graph.record-mode
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index 88a43fe4963c..7c861b54f3a6 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] [section.name ...]", 20 "perf config [<file-option>] [options] [section.name[=value] ...]",
21 NULL 21 NULL
22}; 22};
23 23
@@ -33,6 +33,39 @@ static struct option config_options[] = {
33 OPT_END() 33 OPT_END()
34}; 34};
35 35
36static int set_config(struct perf_config_set *set, const char *file_name,
37 const char *var, const char *value)
38{
39 struct perf_config_section *section = NULL;
40 struct perf_config_item *item = NULL;
41 const char *first_line = "# this file is auto-generated.";
42 FILE *fp;
43
44 if (set == NULL)
45 return -1;
46
47 fp = fopen(file_name, "w");
48 if (!fp)
49 return -1;
50
51 perf_config_set__collect(set, var, value);
52 fprintf(fp, "%s\n", first_line);
53
54 /* overwrite configvariables */
55 perf_config_items__for_each_entry(&set->sections, section) {
56 fprintf(fp, "[%s]\n", section->name);
57
58 perf_config_items__for_each_entry(&section->items, item) {
59 if (item->value)
60 fprintf(fp, "\t%s = %s\n",
61 item->name, item->value);
62 }
63 }
64 fclose(fp);
65
66 return 0;
67}
68
36static int show_spec_config(struct perf_config_set *set, const char *var) 69static int show_spec_config(struct perf_config_set *set, const char *var)
37{ 70{
38 struct perf_config_section *section; 71 struct perf_config_section *section;
@@ -82,7 +115,7 @@ static int show_config(struct perf_config_set *set)
82 return 0; 115 return 0;
83} 116}
84 117
85static int parse_config_arg(char *arg, char **var) 118static int parse_config_arg(char *arg, char **var, char **value)
86{ 119{
87 const char *last_dot = strchr(arg, '.'); 120 const char *last_dot = strchr(arg, '.');
88 121
@@ -99,7 +132,21 @@ static int parse_config_arg(char *arg, char **var)
99 return -1; 132 return -1;
100 } 133 }
101 134
102 *var = arg; 135 *value = strchr(arg, '=');
136 if (*value == NULL)
137 *var = arg;
138 else if (!strcmp(*value, "=")) {
139 pr_err("The config variable does not contain a value: %s\n", arg);
140 return -1;
141 } else {
142 *value = *value + 1; /* excluding a first character '=' */
143 *var = strsep(&arg, "=");
144 if (*var[0] == '\0') {
145 pr_err("invalid config variable: %s\n", arg);
146 return -1;
147 }
148 }
149
103 return 0; 150 return 0;
104} 151}
105 152
@@ -153,7 +200,8 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
153 default: 200 default:
154 if (argc) { 201 if (argc) {
155 for (i = 0; argv[i]; i++) { 202 for (i = 0; argv[i]; i++) {
156 char *var, *arg = strdup(argv[i]); 203 char *var, *value;
204 char *arg = strdup(argv[i]);
157 205
158 if (!arg) { 206 if (!arg) {
159 pr_err("%s: strdup failed\n", __func__); 207 pr_err("%s: strdup failed\n", __func__);
@@ -161,13 +209,21 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
161 break; 209 break;
162 } 210 }
163 211
164 if (parse_config_arg(arg, &var) < 0) { 212 if (parse_config_arg(arg, &var, &value) < 0) {
165 free(arg); 213 free(arg);
166 ret = -1; 214 ret = -1;
167 break; 215 break;
168 } 216 }
169 217
170 ret = show_spec_config(set, var); 218 if (value == NULL)
219 ret = show_spec_config(set, var);
220 else {
221 const char *config_filename = config_exclusive_filename;
222
223 if (!config_exclusive_filename)
224 config_filename = user_config;
225 ret = set_config(set, config_filename, var, value);
226 }
171 free(arg); 227 free(arg);
172 } 228 }
173 } else 229 } else
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 18dae745034f..c8fb65d923cb 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -602,6 +602,12 @@ out_free:
602 return -1; 602 return -1;
603} 603}
604 604
605int perf_config_set__collect(struct perf_config_set *set,
606 const char *var, const char *value)
607{
608 return collect_config(var, value, set);
609}
610
605static int perf_config_set__init(struct perf_config_set *set) 611static int perf_config_set__init(struct perf_config_set *set)
606{ 612{
607 int ret = -1; 613 int ret = -1;
diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h
index 6f813d46045e..0fcdb8c594b0 100644
--- a/tools/perf/util/config.h
+++ b/tools/perf/util/config.h
@@ -33,6 +33,8 @@ const char *perf_etc_perfconfig(void);
33 33
34struct perf_config_set *perf_config_set__new(void); 34struct perf_config_set *perf_config_set__new(void);
35void perf_config_set__delete(struct perf_config_set *set); 35void perf_config_set__delete(struct perf_config_set *set);
36int perf_config_set__collect(struct perf_config_set *set,
37 const char *var, const char *value);
36void perf_config__init(void); 38void perf_config__init(void);
37void perf_config__exit(void); 39void perf_config__exit(void);
38void perf_config__refresh(void); 40void perf_config__refresh(void);