aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorTaeung Song <treeze.taeung@gmail.com>2017-04-26 08:21:02 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-05-02 17:23:12 -0400
commit4341ec6b3db4c3e903d6c44958722918baec1e59 (patch)
treee0a42eaa23d86d7c4dec928bfb32702c7653c390 /tools/perf
parentd80406453ad4a69932dc17a617d5b7bc7ae80b8f (diff)
perf config: Refactor a duplicated code for obtaining config file name
We were doing the same sequence to figure out what is the config pathname to use, fix it by doing it before those two uses. 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/1493209268-5543-2-git-send-email-treeze.taeung@gmail.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-config.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index 55f04f85b049..80668fa7556e 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -159,6 +159,7 @@ int cmd_config(int argc, const char **argv)
159 int i, ret = 0; 159 int i, ret = 0;
160 struct perf_config_set *set; 160 struct perf_config_set *set;
161 char *user_config = mkpath("%s/.perfconfig", getenv("HOME")); 161 char *user_config = mkpath("%s/.perfconfig", getenv("HOME"));
162 const char *config_filename;
162 163
163 argc = parse_options(argc, argv, config_options, config_usage, 164 argc = parse_options(argc, argv, config_options, config_usage,
164 PARSE_OPT_STOP_AT_NON_OPTION); 165 PARSE_OPT_STOP_AT_NON_OPTION);
@@ -175,6 +176,11 @@ int cmd_config(int argc, const char **argv)
175 else if (use_user_config) 176 else if (use_user_config)
176 config_exclusive_filename = user_config; 177 config_exclusive_filename = user_config;
177 178
179 if (!config_exclusive_filename)
180 config_filename = user_config;
181 else
182 config_filename = config_exclusive_filename;
183
178 /* 184 /*
179 * At only 'config' sub-command, individually use the config set 185 * At only 'config' sub-command, individually use the config set
180 * because of reinitializing with options config file location. 186 * because of reinitializing with options config file location.
@@ -192,13 +198,9 @@ int cmd_config(int argc, const char **argv)
192 parse_options_usage(config_usage, config_options, "l", 1); 198 parse_options_usage(config_usage, config_options, "l", 1);
193 } else { 199 } else {
194 ret = show_config(set); 200 ret = show_config(set);
195 if (ret < 0) { 201 if (ret < 0)
196 const char * config_filename = config_exclusive_filename;
197 if (!config_exclusive_filename)
198 config_filename = user_config;
199 pr_err("Nothing configured, " 202 pr_err("Nothing configured, "
200 "please check your %s \n", config_filename); 203 "please check your %s \n", config_filename);
201 }
202 } 204 }
203 break; 205 break;
204 default: 206 default:
@@ -221,13 +223,8 @@ int cmd_config(int argc, const char **argv)
221 223
222 if (value == NULL) 224 if (value == NULL)
223 ret = show_spec_config(set, var); 225 ret = show_spec_config(set, var);
224 else { 226 else
225 const char *config_filename = config_exclusive_filename;
226
227 if (!config_exclusive_filename)
228 config_filename = user_config;
229 ret = set_config(set, config_filename, var, value); 227 ret = set_config(set, config_filename, var, value);
230 }
231 free(arg); 228 free(arg);
232 } 229 }
233 } else 230 } else