From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752134AbbG0IvQ (ORCPT ); Mon, 27 Jul 2015 04:51:16 -0400 Received: from mail-pd0-f179.google.com ([209.85.192.179]:36133 "EHLO mail-pd0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750883AbbG0IvP (ORCPT ); Mon, 27 Jul 2015 04:51:15 -0400 Date: Mon, 27 Jul 2015 17:48:47 +0900 From: Namhyung Kim To: Taeung Song Cc: Arnaldo Carvalho de Melo , linux-kernel@vger.kernel.org, jolsa@redhat.com, Ingo Molnar Subject: Re: [PATCH v4 4/5] perf config: Add a option 'list-all' to perf-config Message-ID: <20150727084847.GD22022@danjae.kornet> References: <1437926311-16226-1-git-send-email-treeze.taeung@gmail.com> <1437926311-16226-5-git-send-email-treeze.taeung@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1437926311-16226-5-git-send-email-treeze.taeung@gmail.com> User-Agent: Mutt/1.5.23+102 (2ca89bed6448) (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 27, 2015 at 12:58:30AM +0900, Taeung Song wrote: > A option 'list-all' is to display both current config variables and > all possible config variables with default values. > The syntax examples are like below > > perf config [options] > > display all perf config with default values. > # perf config -a | --list-all > > Signed-off-by: Taeung Song > --- > tools/perf/Documentation/perf-config.txt | 6 ++++ > tools/perf/builtin-config.c | 48 ++++++++++++++++++++++++++++++++ > 2 files changed, 54 insertions(+) > > diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt > index cd4b1a6..d8b3acc 100644 > --- a/tools/perf/Documentation/perf-config.txt > +++ b/tools/perf/Documentation/perf-config.txt > @@ -11,6 +11,8 @@ SYNOPSIS > 'perf config' [] [section.name[=value] ...] > or > 'perf config' [] -l | --list > +or > +'perf config' [] -a | --list-all > > DESCRIPTION > ----------- > @@ -31,6 +33,10 @@ OPTIONS > For writing and reading options: write to system-wide > '$(sysconfdir)/perfconfig' or read it. > > +-a:: > +--list-all:: > + Show current and all possible config variables with default values. > + > CONFIGURATION FILE > ------------------ > > diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c > index 6d9f28c..f4a1569 100644 > --- a/tools/perf/builtin-config.c > +++ b/tools/perf/builtin-config.c > @@ -23,6 +23,7 @@ static const char * const config_usage[] = { > }; > > #define ACTION_LIST (1<<0) > +#define ACTION_LIST_ALL (1<<1) > > static const struct option config_options[] = { > OPT_GROUP("Config file location"), > @@ -31,6 +32,8 @@ static const struct option config_options[] = { > OPT_GROUP("Action"), > OPT_BIT('l', "list", &actions, > "show current config variables", ACTION_LIST), > + OPT_BIT('a', "list-all", &actions, > + "show current and all possible config variables with default values", ACTION_LIST_ALL), Why did you use OPT_BIT? Do you want to support multiple 'actions' at the same time? I'd rather support just one action, but I won't insist it strongly.. Anyway, setting bits will confuse the switch statement in the cmd_config(). Thanks, Namhyung > OPT_END() > }; > > @@ -539,6 +542,45 @@ static int collect_current_config(const char *var, const char *value, > normalize_value(section_name, name, value)); > } > > +static int show_all_config(void) > +{ > + int i; > + bool has_config; > + struct config_section *section_node; > + struct config_element *element_node; > + > + for (i = 0; default_configsets[i].section_name != NULL; i++) { > + find_config(§ion_node, &element_node, > + default_configsets[i].section_name, default_configsets[i].name); > + > + if (!element_node) > + printf("%s.%s=%s\n", default_configsets[i].section_name, > + default_configsets[i].name, default_configsets[i].value); > + else > + printf("%s.%s=%s\n", section_node->name, > + element_node->name, element_node->value); > + } > + > + /* Print config variables the default configsets haven't */ > + list_for_each_entry(section_node, §ions, list) { > + list_for_each_entry(element_node, §ion_node->element_head, list) { > + has_config = false; > + for (i = 0; default_configsets[i].section_name != NULL; i++) { > + if (!strcmp(default_configsets[i].section_name, section_node->name) > + && !strcmp(default_configsets[i].name, element_node->name)) { > + has_config = true; > + break; > + } > + } > + if (!has_config) > + printf("%s.%s=%s\n", section_node->name, > + element_node->name, element_node->value); > + } > + } > + > + return 0; > +} > + > static int perf_configset_with_option(configset_fn_t fn, const char *var, char *value) > { > char *section_name; > @@ -617,6 +659,12 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused) > else > goto out_err; > goto out; > + case ACTION_LIST_ALL: > + if (argc == 0) > + ret = show_all_config(); > + else > + goto out_err; > + goto out; > default: > if ((!has_option || use_global_config || use_system_config) > && argc == 0) { > -- > 1.9.1 >