Re: [PATCH] perf config : Adding a command 'config' with a option '--list' and a document for it.

From: Namhyung Kim
Date: Sun Feb 08 2015 - 21:33:41 EST


Hi Taeung,

On Thu, Feb 05, 2015 at 05:05:17PM +0900, Taeung Song wrote:
> The perf configuration file contain many variables which can make
> the perf command's action more effective and more skilful.
> But looking through state of configuration is difficult and
> there's no knowing what kind of other variables except variables in perfconfig.example exist.
>
> So This patch adds a command 'config --list' and a document for it.
>
> Signed-off-by: Taeung Song <treeze.taeung@xxxxxxxxx>
> ---
> tools/perf/Documentation/perf-config.txt | 140 +++++++++++++++++++++++++++++++
> tools/perf/Makefile.perf | 1 +
> tools/perf/builtin-config.c | 56 +++++++++++++
> tools/perf/builtin.h | 1 +
> tools/perf/command-list.txt | 1 +
> tools/perf/perf.c | 1 +
> 6 files changed, 200 insertions(+)
> create mode 100644 tools/perf/Documentation/perf-config.txt
> create mode 100644 tools/perf/builtin-config.c
>
> diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
> new file mode 100644
> index 0000000..c88b8e1
> --- /dev/null
> +++ b/tools/perf/Documentation/perf-config.txt
> @@ -0,0 +1,140 @@
> +perf-config(1)
> +==============
> +
> +NAME
> +----
> +perf-config - Get and set variables in configuration file.

So do you also plan to add support for setting config variables like
git-config with this? :)


> +
> +SYNOPSIS
> +--------
> +[verse]
> +'perf config' --list
> +
> +DESCRIPTION
> +-----------
> +You can manage variables in configuration file with this command.
> +
> +OPTIONS
> +-------
> +
> +-l::
> +--list::
> + Show all variables with key and value into each sections.
> +
> +CONFIGURATION FILE
> +------------------
> +
> +The Perf configuration file contain many variables which can make
> +the perf command's action more effective, more skilful.
> +The '$HOME/.perfconfig' file is used to store a per-user configuration.
> +The file 'etc/perfconfig' or '$(sysconfdir)/.perfconf' can be used to

I think it's '/etc/perfconfig' or '$(sysconfdir)/perfconfig'.


> +store a system-wide default configuration.
> +
> +The variables are divided into sections. In each sections, the variables
> +can contain a key and values.
> +
> +EXAMPLES
> +------------
> +
> +Given a $HOME/.perfconfig like this:
> +
> +#
> +# This is the config file, and
> +# a '#' character indicates a comment
> +#
> +
> +[colors]
> + # There are types of color which are red,
> + # green, default, black, blue,
> + # white, magenta, lightgray
> + top = red, lightgray
> + medium = green, lightgray
> + normal = black, lightgray
> + selected = lightgray, magenta
> + code = blue, lightgray
> + addr = magenta, lightgray
> + root = default
> +
> +[tui]
> + # Defaults if linked with libslang
> + report = on
> + annotate = on
> + top = on
> +
> +[gtk]
> + report = on
> + annotate = on
> + top = on
> +
> +[buildid]
> + # Default, disable using /dev/null
> + dir = /root/.debug
> +
> +[annotate]
> + # Defaults
> + hide_src_code = false
> + use_offset = true
> + jump_arrows = true
> + show_nr_jumps = false
> +
> +[pager]
> + # That a 'cmd' is true mean to use pager
> + cmd = true
> +
> +[alias]
> +
> +[help]
> + # Format can be man, info, web or html
> + format = web
> + autocorrect = 3
> +
> +[core]
> + # fall through
> +
> +[hist]
> + # a value of 'percentage' can be 'relative' or 'absolute'
> + percentage = relative
> +
> +[ui]
> + show-headers= true
> +
> +[call-graph]
> + # fp (framepointer), dwarf
> + # If you use 'Dwarf style',
> + # you can add ', (dump-size)' to record-mode such as ', 24'
> + record-mode = fp
> +
> + dump-size = 24
> +
> + # graph (graph absolute), flat, fractal (graph relative)
> + print-type = graph
> +
> + # caller, callee
> + order = caller
> +
> + # function, address
> + sort-key = function
> +
> + threshold = 13.3
> + print-limit = 54.3
> +
> +[report]
> + group = true
> + percent-limit = 70.54
> + children = true
> + queue-size = 32
> +
> +[man]
> + cmd =
> + path =
> + viewer =
> +
> +[record]
> + # fall through
> + call-graph =
> +
> +[top]
> + # a 'call-graph' is fall through
> + call-graph =
> + children = true

While it's nice to list up all config variables in the example
section, it'd be much greater if you could describe them in more
detail like git-config manual page.

Thanks,
Namhyung


> +
> diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
> index aa6a504..e2083f4 100644
> --- a/tools/perf/Makefile.perf
> +++ b/tools/perf/Makefile.perf
> @@ -475,6 +475,7 @@ BUILTIN_OBJS += $(OUTPUT)bench/futex-hash.o
> BUILTIN_OBJS += $(OUTPUT)bench/futex-wake.o
> BUILTIN_OBJS += $(OUTPUT)bench/futex-requeue.o
>
> +BUILTIN_OBJS += $(OUTPUT)builtin-config.o
> BUILTIN_OBJS += $(OUTPUT)builtin-diff.o
> BUILTIN_OBJS += $(OUTPUT)builtin-evlist.o
> BUILTIN_OBJS += $(OUTPUT)builtin-help.o
> diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
> new file mode 100644
> index 0000000..04a17d9
> --- /dev/null
> +++ b/tools/perf/builtin-config.c
> @@ -0,0 +1,56 @@
> +/*
> + * builtin-config.c
> + *
> + * Copyright (C) 2015, Taeung Song <treeze.taeung@xxxxxxxxx>
> + *
> + */
> +#include "builtin.h"
> +
> +#include "perf.h"
> +
> +#include "util/cache.h"
> +#include "util/parse-options.h"
> +#include "util/util.h"
> +
> +static struct {
> + bool list_action;
> +} params;
> +
> +static int show_all_config(const char *key, const char *value,
> + void *cb __maybe_unused)
> +{
> + if (value)
> + printf("%s=%s\n", key, value);
> + else
> + printf("%s\n", key);
> +
> + return 0;
> +}
> +
> +static int
> +cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
> +{
> + int ret = 0;
> + const char * const config_usage[] = {
> + "perf config --list",
> + NULL
> + };
> + const struct option options[] = {
> + OPT_BOOLEAN('l', "list", &params.list_action, "list up current configurations"),
> + OPT_END()
> + };
> +
> + argc = parse_options(argc, argv, options, config_usage,
> + PARSE_OPT_STOP_AT_NON_OPTION);
> + if (argc > 0) {
> + if (strcmp(argv[0], "-") == 0)
> + pr_warn(" Error: '-' is not supported.\n");
> +
> + usage_with_options(config_usage, options);
> + }
> +
> + if (params.list_action)
> + ret = perf_config(show_all_config, NULL);
> +
> + return ret;
> +}
> diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h
> index b210d62..65aef3d 100644
> --- a/tools/perf/builtin.h
> +++ b/tools/perf/builtin.h
> @@ -17,6 +17,7 @@ extern int cmd_annotate(int argc, const char **argv, const char *prefix);
> extern int cmd_bench(int argc, const char **argv, const char *prefix);
> extern int cmd_buildid_cache(int argc, const char **argv, const char *prefix);
> extern int cmd_buildid_list(int argc, const char **argv, const char *prefix);
> +extern int cmd_config(int argc, const char **argv, const char *prefix);
> extern int cmd_diff(int argc, const char **argv, const char *prefix);
> extern int cmd_evlist(int argc, const char **argv, const char *prefix);
> extern int cmd_help(int argc, const char **argv, const char *prefix);
> diff --git a/tools/perf/command-list.txt b/tools/perf/command-list.txt
> index 0906fc4..37138c2 100644
> --- a/tools/perf/command-list.txt
> +++ b/tools/perf/command-list.txt
> @@ -7,6 +7,7 @@ perf-archive mainporcelain common
> perf-bench mainporcelain common
> perf-buildid-cache mainporcelain common
> perf-buildid-list mainporcelain common
> +perf-config mainporcelain common
> perf-diff mainporcelain common
> perf-evlist mainporcelain common
> perf-inject mainporcelain common
> diff --git a/tools/perf/perf.c b/tools/perf/perf.c
> index 3700a7f..943e54c 100644
> --- a/tools/perf/perf.c
> +++ b/tools/perf/perf.c
> @@ -36,6 +36,7 @@ struct cmd_struct {
> static struct cmd_struct commands[] = {
> { "buildid-cache", cmd_buildid_cache, 0 },
> { "buildid-list", cmd_buildid_list, 0 },
> + { "config", cmd_config, 0 },
> { "diff", cmd_diff, 0 },
> { "evlist", cmd_evlist, 0 },
> { "help", cmd_help, 0 },
> --
> 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/
--
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/