lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 14 Mar 2016 21:16:09 +0900
From:	Taeung Song <treeze.taeung@...il.com>
To:	Arnaldo Carvalho de Melo <acme@...nel.org>
Cc:	linux-kernel@...r.kernel.org, Jiri Olsa <jolsa@...nel.org>,
	Namhyung Kim <namhyung@...nel.org>,
	Ingo Molnar <mingo@...nel.org>,
	Peter Zijlstra <peterz@...radead.org>,
	Taeung Song <treeze.taeung@...il.com>
Subject: [PATCH v2 5/5] perf config: Add 'list-all' option to show all perf's configs

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@...nel.org>
Cc: Jiri Olsa <jolsa@...nel.org>
Signed-off-by: Taeung Song <treeze.taeung@...il.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ