linux-kernel.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, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Taeung Song <treeze.taeung@gmail.com>
Subject: [PATCH v2 5/5] perf config: Add 'list-all' option to show all perf's configs
Date: Mon, 14 Mar 2016 21:16:09 +0900	[thread overview]
Message-ID: <1457957769-3700-6-git-send-email-treeze.taeung@gmail.com> (raw)
In-Reply-To: <1457957769-3700-1-git-send-email-treeze.taeung@gmail.com>

That show all possible config variables with
default values. The syntax examples are like below.

    perf config [<file-option>] [options]

    display all perf config with default values.
    # perf config -a | --list-all

But configs from user or system
config file have a high priority e.g.

    Default of report.children is true
    # cat ~/.perfconfig
    [report]
        children=false

    # perf config --list-all
    ..(omitted)..
    call-graph.threshold=0.500000
    call-graph.print-limit=0
    report.group=true
    report.children=false
    report.percent-limit=0.000000
    report.queue-size=0
    ..(omitted)..

Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 tools/perf/Documentation/perf-config.txt |  6 +++
 tools/perf/builtin-config.c              | 69 +++++++++++++++++++++++++++++++-
 2 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index 15949e2..d9fb8c3 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -9,6 +9,8 @@ SYNOPSIS
 --------
 [verse]
 'perf config' [<file-option>] -l | --list
+or
+'perf config' [<file-option>] -a | --list-all
 
 DESCRIPTION
 -----------
@@ -29,6 +31,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 1bc1121..7ceae55 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -22,17 +22,75 @@ static const char * const config_usage[] = {
 };
 
 enum actions {
-	ACTION_LIST = 1
+	ACTION_LIST = 1,
+	ACTION_LIST_ALL
 } actions;
 
 static struct option config_options[] = {
 	OPT_SET_UINT('l', "list", &actions,
 		     "show current config variables", ACTION_LIST),
+	OPT_SET_UINT('a', "list-all", &actions,
+		     "show current and all possible config"
+		     " variables with default values", ACTION_LIST_ALL),
 	OPT_BOOLEAN(0, "system", &use_system_config, "use system config file"),
 	OPT_BOOLEAN(0, "user", &use_user_config, "use user config file"),
 	OPT_END()
 };
 
+#define DEFAULT_VAL(_field) config->default_value._field
+
+static char *get_default_value(struct perf_config_item *config)
+{
+	int ret = 0;
+	char *value;
+
+	if (config->is_custom)
+		return NULL;
+
+	if (config->type == CONFIG_TYPE_BOOL)
+		ret = asprintf(&value, "%s",
+			       DEFAULT_VAL(b) ? "true" : "false");
+	else if (config->type == CONFIG_TYPE_INT)
+		ret = asprintf(&value, "%d", DEFAULT_VAL(i));
+	else if (config->type == CONFIG_TYPE_LONG)
+		ret = asprintf(&value, "%u", DEFAULT_VAL(l));
+	else if (config->type == CONFIG_TYPE_U64)
+		ret = asprintf(&value, "%"PRId64, DEFAULT_VAL(ll));
+	else if (config->type == CONFIG_TYPE_FLOAT)
+		ret = asprintf(&value, "%f", DEFAULT_VAL(f));
+	else if (config->type == CONFIG_TYPE_DOUBLE)
+		ret = asprintf(&value, "%f", DEFAULT_VAL(d));
+	else
+		ret = asprintf(&value, "%s", DEFAULT_VAL(s));
+
+	if (ret < 0)
+		return NULL;
+
+	return value;
+}
+
+static int show_all_config(struct perf_config_set *perf_configs)
+{
+	char *value, *default_value;
+	struct perf_config_item *config;
+	struct list_head *config_list = &perf_configs->config_list;
+
+	list_for_each_entry(config, config_list, list) {
+		value = config->value;
+		if (!value)
+			value = default_value = get_default_value(config);
+
+		if (value)
+			printf("%s.%s=%s\n", config->section,
+			       config->name, value);
+
+		free(default_value);
+		default_value = NULL;
+	}
+
+	return 0;
+}
+
 static int show_config(struct perf_config_set *perf_configs)
 {
 	bool has_value = false;
@@ -61,6 +119,9 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 	struct perf_config_set *perf_configs;
 	char *user_config = mkpath("%s/.perfconfig", getenv("HOME"));
 
+	set_option_flag(config_options, 'l', "list", PARSE_OPT_EXCLUSIVE);
+	set_option_flag(config_options, 'a', "list-all", PARSE_OPT_EXCLUSIVE);
+
 	argc = parse_options(argc, argv, config_options, config_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 
@@ -83,6 +144,12 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 	}
 
 	switch (actions) {
+	case ACTION_LIST_ALL:
+		if (argc)
+			parse_options_usage(config_usage, config_options, "a", 1);
+		else
+			ret = show_all_config(perf_configs);
+		break;
 	case ACTION_LIST:
 		if (argc) {
 			pr_err("Error: takes no arguments\n");
-- 
2.5.0

      parent reply	other threads:[~2016-03-14 12:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-14 12:16 [RFC][PATCH v2 0/5] perf config: Introduce perf_config_set class Taeung Song
2016-03-14 12:16 ` [PATCH v2 1/5] " Taeung Song
2016-03-17 12:31   ` Namhyung Kim
2016-03-17 14:10     ` Taeung Song
2016-03-17 23:27       ` Namhyung Kim
2016-03-18  0:52         ` Taeung Song
2016-03-14 12:16 ` [PATCH v2 2/5] perf config: Let show_config() work with perf_config_set Taeung Song
2016-03-14 12:16 ` [PATCH v2 3/5] perf config: Prepare all default configs Taeung Song
2016-03-14 12:16 ` [PATCH v2 4/5] perf config: Initialize perf_config_set with " Taeung Song
2016-03-14 12:16 ` Taeung Song [this message]

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=1457957769-3700-6-git-send-email-treeze.taeung@gmail.com \
    --to=treeze.taeung@gmail.com \
    --cc=acme@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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).