[PATCH 3/4] perf tools: Add a option 'all' to perf-config.
From: Taeung Song
Date: Mon Apr 27 2015 - 02:35:38 EST
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@xxxxxxxxx>
---
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", ¶ms.list_action, "show current config variables"),
+ OPT_BOOLEAN('a', "all", ¶ms.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(§ion_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, §ion_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, §ion_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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/