linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Taeung Song <treeze.taeung@gmail.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: linux-kernel@vger.kernel.org, jolsa@redhat.com,
	namhyung@kernel.org, linux-perf-users@vger.kernel.org,
	Taeung Song <treeze.taeung@gmail.com>
Subject: [PATCH v2 3/4] perf tools: Add a option 'list-all' to perf-config.
Date: Fri, 29 May 2015 14:42:47 +0900	[thread overview]
Message-ID: <1432878168-11278-3-git-send-email-treeze.taeung@gmail.com> (raw)
In-Reply-To: <1432878168-11278-1-git-send-email-treeze.taeung@gmail.com>

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 <treeze.taeung@gmail.com>
---
 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 f3dae23..e33e481 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
 -----------
@@ -23,6 +25,10 @@ OPTIONS
 --list::
 	Show current config variables with key and value into each sections.
 
+-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 175b125..cf7d61d 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -21,10 +21,13 @@ 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("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),
 	OPT_END()
 };
 
@@ -516,6 +519,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(&section_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, &sections, list) {
+		list_for_each_entry(element_node, &section_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;
@@ -585,6 +627,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 && argc == 0) {
 			ret = perf_config(show_config, NULL);
-- 
1.9.1

  parent reply	other threads:[~2015-05-29  5:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-29  5:42 [PATCH v2 1/4] perf tools: Add 'perf-config' command Taeung Song
2015-05-29  5:42 ` [PATCH v2 2/4] perf tools: Add functions which can get or set perf config variables Taeung Song
2015-05-29  5:42 ` Taeung Song [this message]
2015-05-29  5:42 ` [PATCH v2 4/4] perf tools: Add a option 'remove' to perf-config Taeung Song

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1432878168-11278-3-git-send-email-treeze.taeung@gmail.com \
    --to=treeze.taeung@gmail.com \
    --cc=acme@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).