From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752398AbbEKCPi (ORCPT ); Sun, 10 May 2015 22:15:38 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]:33595 "EHLO mail-pa0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751870AbbEKCPf (ORCPT ); Sun, 10 May 2015 22:15:35 -0400 Message-ID: <555010B9.905@gmail.com> Date: Mon, 11 May 2015 11:15:21 +0900 From: taeung User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: Jiri Olsa CC: Arnaldo Carvalho de Melo , Namhyung Kim , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/4] perf tools: Add functions which can get or set perf config variables. References: <1430116466-14427-1-git-send-email-treeze.taeung@gmail.com> <1430116466-14427-2-git-send-email-treeze.taeung@gmail.com> <20150504191615.GA11223@krava> In-Reply-To: <20150504191615.GA11223@krava> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Jiri Olsa Thanks for your feedbacks on my patches. There are one thing I don't understand very well. I wrote a number 1) in the middle of the your feedbacks to mark it. I don't follow, could you elaborate it little more? On 05/05/2015 04:16 AM, Jiri Olsa wrote: > On Mon, Apr 27, 2015 at 03:34:24PM +0900, Taeung Song wrote: >> This patch consists of functions >> 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 > [jolsa@krava perf]$ ./perf config krava.krava > krava.krava=true > > ? > > some comments below > >> set specific config variables >> # perf config report.queue-size=100M report.children=true >> >> Signed-off-by: Taeung Song >> --- >> 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(-) > SNIP > >> +static int set_spec_config(const char *section_name, const char *subkey, >> + 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, "."); > should this check the config syntax? could be used for command line check as well >> +} >> + >> +static int collect_config(const char *var, const char *value, >> + void *cb __maybe_unused) >> +{ >> + struct config_section *section_node; >> + const char *section_name, *subkey; > SNIP > >> + } >> + 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; > you dont allow '-' in the key report.queue-size, I think we should support also _ > > also please put the name checks into separated function > >> + } >> + } >> + >> + if (num_equals > 1 || num_dot > 1) >> + goto out_err; >> + >> + given_value = strchr(key, '='); >> + if (given_value == NULL || given_value == key) >> + given_value = NULL; > SNIP > >> argc = parse_options(argc, argv, config_options, config_usage, >> 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]) > hum, so you let go in args like '=krava' ? > > why dont you completely check the name (assignment string) first > and decide later about the callback > 1) I understood that the name must be completely checked first. But I don't know the callback. What does it mean ? Could you elaborate it little more? Thanks, Taeung >> + ret = perf_configset_with_option(show_spec_config, argv[i]); >> + else >> + ret = perf_configset_with_option(set_spec_config, argv[i]); >> + if (ret < 0) >> + break; >> + } >> + goto out; >> + } >> + } > SNIP > >> @@ -502,6 +501,31 @@ out: >> 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."; > so you parse whole config, change it and write back.. > 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 >>