提交 5c261555 编写于 作者: T Taeung Song 提交者: Arnaldo Carvalho de Melo

perf config: Write a config file just once

Currently set_config() can be repeatedly called for each input config on
the below case:

  $ perf config kmem.default=slab report.children=false ...

But it's a waste, so only once write a config file gathering all given
config key=value pairs.
Signed-off-by: NTaeung Song <treeze.taeung@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1504754331-9776-1-git-send-email-treeze.taeung@gmail.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 ecdad24d
...@@ -34,8 +34,7 @@ static struct option config_options[] = { ...@@ -34,8 +34,7 @@ static struct option config_options[] = {
OPT_END() OPT_END()
}; };
static int set_config(struct perf_config_set *set, const char *file_name, static int set_config(struct perf_config_set *set, const char *file_name)
const char *var, const char *value)
{ {
struct perf_config_section *section = NULL; struct perf_config_section *section = NULL;
struct perf_config_item *item = NULL; struct perf_config_item *item = NULL;
...@@ -49,7 +48,6 @@ static int set_config(struct perf_config_set *set, const char *file_name, ...@@ -49,7 +48,6 @@ static int set_config(struct perf_config_set *set, const char *file_name,
if (!fp) if (!fp)
return -1; return -1;
perf_config_set__collect(set, file_name, var, value);
fprintf(fp, "%s\n", first_line); fprintf(fp, "%s\n", first_line);
/* overwrite configvariables */ /* overwrite configvariables */
...@@ -161,6 +159,7 @@ int cmd_config(int argc, const char **argv) ...@@ -161,6 +159,7 @@ int cmd_config(int argc, const char **argv)
struct perf_config_set *set; struct perf_config_set *set;
char *user_config = mkpath("%s/.perfconfig", getenv("HOME")); char *user_config = mkpath("%s/.perfconfig", getenv("HOME"));
const char *config_filename; const char *config_filename;
bool changed = false;
argc = parse_options(argc, argv, config_options, config_usage, argc = parse_options(argc, argv, config_options, config_usage,
PARSE_OPT_STOP_AT_NON_OPTION); PARSE_OPT_STOP_AT_NON_OPTION);
...@@ -231,15 +230,26 @@ int cmd_config(int argc, const char **argv) ...@@ -231,15 +230,26 @@ int cmd_config(int argc, const char **argv)
goto out_err; goto out_err;
} }
} else { } else {
if (set_config(set, config_filename, var, value) < 0) { if (perf_config_set__collect(set, config_filename,
pr_err("Failed to set '%s=%s' on %s\n", var, value) < 0) {
var, value, config_filename); pr_err("Failed to add '%s=%s'\n",
var, value);
free(arg); free(arg);
goto out_err; goto out_err;
} }
changed = true;
} }
free(arg); free(arg);
} }
if (!changed)
break;
if (set_config(set, config_filename) < 0) {
pr_err("Failed to set the configs on %s\n",
config_filename);
goto out_err;
}
} }
ret = 0; ret = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册