On Mon, Apr 27, 2015 at 03:34:24PM +0900, Taeung Song wrote:1) I understood that the name must be completely checked first.
This patch consists of functions[jolsa@krava perf]$ ./perf config krava.krava
which can get, set specific config variables.
For the syntax examples,
perf config [options] [section.subkey[=value] ...]
display key-value pairs of specific config variables
# perf config report.queue-size report.children
krava.krava=true
?
some comments below
set specific config variablesSNIP
# perf config report.queue-size=100M report.children=true
Signed-off-by: Taeung Song <treeze.taeung@xxxxxxxxx>
---
tools/perf/Documentation/perf-config.txt | 2 +
tools/perf/builtin-config.c | 276 ++++++++++++++++++++++++++++++-
tools/perf/util/cache.h | 17 ++
tools/perf/util/config.c | 30 +++-
4 files changed, 320 insertions(+), 5 deletions(-)
+static int set_spec_config(const char *section_name, const char *subkey,should this check the config syntax? could be used for command line check as well
+ const char *value)
{
int ret = 0;
+ ret += set_config(section_name, subkey, value);
+ ret += perf_configset_write_in_full();
+
+ return ret;
+}
+
+static void parse_key(const char *var, const char **section_name, const char **subkey)
+{
+ char *key = strdup(var);
+
+ if (!key)
+ die("%s: strdup failed\n", __func__);
+
+ *section_name = strsep(&key, ".");
+ *subkey = strsep(&key, ".");
+}SNIP
+
+static int collect_config(const char *var, const char *value,
+ void *cb __maybe_unused)
+{
+ struct config_section *section_node;
+ const char *section_name, *subkey;
+ }you dont allow '-' in the key report.queue-size, I think we should support also _
+ for (i = 0; key[i]; i++) {
+ if (i == 0 && !isalpha(key[i++]))
+ goto out_err;
+
+ switch (key[i]) {
+ case '.':
+ num_dot += 1;
+ if (!isalpha(key[++i]))
+ goto out_err;
+ break;
+ case '=':
+ num_equals += 1;
+ break;
+ default:
+ if (!isalpha(key[i]) && !isalnum(key[i]))
+ goto out_err;
also please put the name checks into separated function
+ }SNIP
+ }
+
+ if (num_equals > 1 || num_dot > 1)
+ goto out_err;
+
+ given_value = strchr(key, '=');
+ if (given_value == NULL || given_value == key)
+ given_value = NULL;
argc = parse_options(argc, argv, config_options, config_usage,hum, so you let go in args like '=krava' ?
PARSE_OPT_STOP_AT_NON_OPTION);
+ if (origin_argc > argc)
+ is_option = true;
+ else
+ is_option = false;
+
+ if (!is_option && argc >= 0) {
+ switch (argc) {
+ case 0:
+ break;
+ default:
+ for (i = 0; argv[i]; i++) {
+ value = strrchr(argv[i], '=');
+ if (value == NULL || value == argv[i])
why dont you completely check the name (assignment string) first
and decide later about the callback
+ ret = perf_configset_with_option(show_spec_config, argv[i]);SNIP
+ else
+ ret = perf_configset_with_option(set_spec_config, argv[i]);
+ if (ret < 0)
+ break;
+ }
+ goto out;
+ }
+ }
@@ -502,6 +501,31 @@ out:so you parse whole config, change it and write back..
return ret;
}
+int perf_configset_write_in_full(void)
+{
+ struct config_section *section_node;
+ struct config_element *element_node;
+ const char *first_line = "# this file is auto-generated.";
hum, I dont see better way.. and I like the first line ;-)
+ FILE *fp = fopen(config_file_name, "w");
+
+ if (!fp)
+ return -1;
+
+ fprintf(fp, "%s\n", first_line);
+ /* overwrite configvariables */
+ list_for_each_entry(section_node, sections, list) {
+ fprintf(fp, "[%s]\n", section_node->name);
+ list_for_each_entry(element_node, §ion_node->element_head, list) {
+ if (element_node->value)
+ fprintf(fp, "\t%s = %s\n",
+ element_node->subkey, element_node->value);
+ }
+ }
+ fclose(fp);
+
+ return 0;
+}
+
/*
* Call this to report error for your variable that should not
* get a boolean value (i.e. "[my] var" means "true").
--
1.9.1