From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964989AbcCNMRI (ORCPT ); Mon, 14 Mar 2016 08:17:08 -0400 Received: from mail-pa0-f65.google.com ([209.85.220.65]:34253 "EHLO mail-pa0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934280AbcCNMQe (ORCPT ); Mon, 14 Mar 2016 08:16:34 -0400 From: Taeung Song To: Arnaldo Carvalho de Melo Cc: linux-kernel@vger.kernel.org, Jiri Olsa , Namhyung Kim , Ingo Molnar , Peter Zijlstra , Taeung Song 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 Message-Id: <1457957769-3700-6-git-send-email-treeze.taeung@gmail.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1457957769-3700-1-git-send-email-treeze.taeung@gmail.com> References: <1457957769-3700-1-git-send-email-treeze.taeung@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org That show 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 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 Cc: Jiri Olsa Signed-off-by: Taeung Song --- 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' [] -l | --list +or +'perf config' [] -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