mirror of https://lore.kernel.org/lkml/
 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, Taeung Song <treeze.taeung@gmail.com>
Subject: [PATCH 3/4] perf tools: Add a option 'all' to perf-config.
Date: Mon, 27 Apr 2015 15:34:25 +0900	[thread overview]
Message-ID: <1430116466-14427-3-git-send-email-treeze.taeung@gmail.com> (raw)
In-Reply-To: <1430116466-14427-1-git-send-email-treeze.taeung@gmail.com>

A option '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
    or
    # perf config -a | --all

Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 tools/perf/Documentation/perf-config.txt |  6 +++
 tools/perf/builtin-config.c              | 49 ++++++++++++++++++++++++
 tools/perf/util/PERFCONFIG-DEFAULT       | 65 ++++++++++++++++++++++++++++++++
 tools/perf/util/cache.h                  |  1 +
 tools/perf/util/config.c                 |  2 +-
 5 files changed, 122 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/util/PERFCONFIG-DEFAULT

diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index b2b3321..1c9027e 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -11,6 +11,8 @@ SYNOPSIS
 'perf config' [section.subkey[=value] ...]
 or
 'perf config' -l | --list
+or
+'perf config' -a | --all
 
 DESCRIPTION
 -----------
@@ -23,6 +25,10 @@ OPTIONS
 --list::
 	Show current config variables with key and value into each sections.
 
+-a::
+--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 99292f6..a67aea3 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -17,6 +17,7 @@ static struct {
 	bool list_action;
 	bool get_action;
 	bool set_action;
+	bool all_action;
 } params;
 
 struct list_head *sections;
@@ -28,6 +29,8 @@ static const char * const config_usage[] = {
 static const struct option config_options[] = {
 	OPT_GROUP("Action"),
 	OPT_BOOLEAN('l', "list", &params.list_action, "show current config variables"),
+	OPT_BOOLEAN('a', "all", &params.all_action,
+		    "show current and all possible config variables with default values"),
 	OPT_END()
 };
 
@@ -204,6 +207,49 @@ static int collect_config(const char *var, const char *value,
 	return add_config_element(&section_node->element_head, subkey, value);
 }
 
+static int merge_config(const char *var, const char *value,
+			void *cb __maybe_unused)
+{
+	const char *section_name, *subkey;
+	parse_key(var, &section_name, &subkey);
+	return set_config(section_name, subkey, value);
+}
+
+static int show_all_config(void)
+{
+	int ret = 0;
+	struct config_section *section_node;
+	struct config_element *element_node;
+	char *pwd, *all_config;
+
+	pwd = getenv("PWD");
+	all_config = strdup(mkpath("%s/util/PERFCONFIG-DEFAULT", pwd));
+
+	if (!all_config) {
+		pr_err("%s: strdup failed\n", __func__);
+		return -1;
+	}
+
+	sections = zalloc(sizeof(*sections));
+	if (!sections)
+		return -1;
+	INIT_LIST_HEAD(sections);
+
+	ret += perf_config_from_file(collect_config, all_config, NULL);
+	ret += perf_config(merge_config, NULL);
+
+	list_for_each_entry(section_node, sections, list) {
+		list_for_each_entry(element_node, &section_node->element_head, list) {
+			if (element_node->value)
+				printf("%s.%s = %s\n", section_node->name,
+				       element_node->subkey, element_node->value);
+			else
+				printf("%s.%s =\n", section_node->name, element_node->subkey);
+		}
+	}
+	return ret;
+}
+
 static int perf_configset_with_option(configset_fn_t fn, const char *var)
 {
 	int i, num_dot = 0, num_equals = 0;
@@ -301,6 +347,7 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (!is_option && argc >= 0) {
 		switch (argc) {
 		case 0:
+			params.all_action = true;
 			break;
 		default:
 			for (i = 0; argv[i]; i++) {
@@ -318,6 +365,8 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	if (params.list_action && argc == 0)
 		ret = perf_config(show_config, NULL);
+	else if (params.all_action && argc == 0)
+		ret = show_all_config();
 	else {
 		pr_warning("Error: Unknown argument.\n");
 		usage_with_options(config_usage, config_options);
diff --git a/tools/perf/util/PERFCONFIG-DEFAULT b/tools/perf/util/PERFCONFIG-DEFAULT
new file mode 100644
index 0000000..ddb67db
--- /dev/null
+++ b/tools/perf/util/PERFCONFIG-DEFAULT
@@ -0,0 +1,65 @@
+[colors]
+	top = red, default
+	medium = green, default
+	normal = lightgray, default
+	selected = white, lightgray
+	code = blue, default
+	addr = magenta, default
+	root = white, blue
+
+[tui]
+	report = on
+	annotate = on
+	top = on
+
+[buildid]
+	dir = /root/.debug
+
+[annotate]
+	hide_src_code = false
+	use_offset = true
+	jump_arrows = true
+	show_nr_jumps = false
+
+[gtk]
+	annotate = off
+	report = off
+	top = off
+
+[pager]
+	cmd = true
+	report = true
+	annotate = true
+	report = true
+	top = true
+	diff = true
+
+[help]
+	format = man
+	autocorrect = 0
+
+[hist]
+	percentage = absolute
+
+[ui]
+	show-headers = true
+
+[call-graph]
+	record-mode = fp
+	dump-size =
+	print-type = fractal
+	order = caller
+	sort-key = function
+	threshold =
+	print-limit =
+
+[report]
+	children = false
+	percent-limit = 1
+	queue-size =
+
+[top]
+	children = false
+
+[man]
+	viewer = man
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index d333753..b2c427c 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -39,6 +39,7 @@ extern int perf_configset_write_in_full(void);
 typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int perf_default_config(const char *, const char *, void *);
 extern int perf_config(config_fn_t fn, void *);
+extern int perf_config_from_file(config_fn_t fn, const char *filename, void *data);
 extern int perf_config_int(const char *, const char *);
 extern u64 perf_config_u64(const char *, const char *);
 extern int perf_config_bool(const char *, const char *);
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 71294ef..9c1d5aa 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -412,7 +412,7 @@ int perf_default_config(const char *var, const char *value,
 	return 0;
 }
 
-static int perf_config_from_file(config_fn_t fn, const char *filename, void *data)
+int perf_config_from_file(config_fn_t fn, const char *filename, void *data)
 {
 	int ret;
 	FILE *f = fopen(filename, "r");
-- 
1.9.1


  parent reply	other threads:[~2015-04-27  6:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27  6:34 [PATCH 1/4] perf tools: Add 'perf-config' command Taeung Song
2015-04-27  6:34 ` [PATCH 2/4] perf tools: Add functions which can get or set perf config variables Taeung Song
2015-05-04  8:41   ` Jiri Olsa
2015-05-04 19:16   ` Jiri Olsa
2015-05-11  2:15     ` taeung
2015-04-27  6:34 ` Taeung Song [this message]
2015-05-04  8:56   ` [PATCH 3/4] perf tools: Add a option 'all' to perf-config Jiri Olsa
2015-05-04 19:16   ` Jiri Olsa
2015-05-04 19:16   ` Jiri Olsa
2015-05-04 19:16   ` Jiri Olsa
2015-04-27  6:34 ` [PATCH 4/4] perf tools: Add a option 'remove' " Taeung Song
2015-04-27 22:17 ` [PATCH 1/4] perf tools: Add 'perf-config' command Arnaldo Carvalho de Melo

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=1430116466-14427-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=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

all inboxes | Powered by JetHome®