perf tools: Add 'perf-config' command
v4 cover perf tools: Add 'perf-config' command
Changes in v4:
- If some config value is default value, notice it is '(default)'as below.
# perf config colors.normal colors.normal=lightgray, default (default)
- A config file path is only decided in perf_config().
And a perf-config command depend on perf_config() deciding a config file path. So if the config file path is NULL because of some reason like no such file, a perf-config command can't write to the file. So, I added new options which are '--global' and '--system' to be enable to select config file path to be used without perf_config().
Changes in v3:
- Add a config variable 'kmem.default' with a default value
into 'struct default_configset' which has default config variables and values.
- Add a option '--global' and '--local' to enable config file location to be selected
Changes in v2:
- Renaming variables a more suitable name
1. '--list-all' instead of '--all'
2. 'name' instead of 'subkey'
3. 'section, name, value' instead of 'given_section, subkey, value'
- Correct small infelicities or typing errors in a perf-config documention.
- Remove a part description of report.children
because it was duplicated in Documentation/callchain-overhead-calculation.txt
- Use a variable 'int actions' instead of struct params which has 'bool list_action' , 'bool get_action’ and etc. , to simplify a branching statement for perf-config options.
- Declaration a global variable 'static struct default_configsets' has config variables with default values instead of using a 'util/PERFCONFIG-DEFAULT' file and remove functions merge() and perse_key() to get perf config default values.
- Add a function to normalize a value and check data type of it.
- Simplify parsing arguments as arguments is just divided by '=' and then in front of '.' is a section, between '.' and '=' is a name, and behind '=' is a value.
- Print config variables 'struct default_configsets' haven't
- Make a command ’perf config' without a option work as with a option '—list' instead of '--list-all’.
Taeung Song (5):
perf tools: Add 'perf-config' command
perf config: Add '--system' and '--global' options to be able to
select which config file to be used
perf config: Add functions which can get or set perf config variables perf config: Add a option 'list-all' to perf-config
perf config: Add a option 'remove' to perf-config
tools/perf/Build | 1 + tools/perf/Documentation/perf-config.txt | 407 ++++++++++++++++ tools/perf/Documentation/perfconfig.example | 73 ++- tools/perf/builtin-config.c | 718 ++++++++++++++++++++++++++++ tools/perf/builtin.h | 1 + tools/perf/command-list.txt | 1 + tools/perf/perf.c | 1 + tools/perf/util/cache.h | 19 + tools/perf/util/config.c | 29 +- 9 files changed, 1236 insertions(+), 14 deletions(-) create mode 100644 tools/perf/Documentation/perf-config.txt create mode 100644 tools/perf/builtin-config.c
Signature · 1 line
1.9.1
PATCH v4 1/5 perf tools: Add 'perf-config' command
The perf configuration file contains many variables which can make
the perf command's action more effective.
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 'perf-config' command with '--list' option and a document for it.
perf config [options]
display current perf config variables.
# perf config
or
# perf config -l | --list
--- tools/perf/Build | 1 + tools/perf/Documentation/perf-config.txt | 381 ++++++++++++++++++++++++++++ tools/perf/Documentation/perfconfig.example | 73 +++++- tools/perf/builtin-config.c | 76 ++++++ tools/perf/builtin.h | 1 + tools/perf/command-list.txt | 1 + tools/perf/perf.c | 1 + 7 files changed, 522 insertions(+), 12 deletions(-) create mode 100644 tools/perf/Documentation/perf-config.txt create mode 100644 tools/perf/builtin-config.c
tools/perf/Build +1 -0
@@ -1,5 +1,6 @@ perf-y += builtin-bench.o perf-y += builtin-annotate.o +perf-y += builtin-config.o perf-y += builtin-diff.o perf-y += builtin-evlist.o perf-y += builtin-help.o
tools/perf/Documentation/perf-config.txt new file +381 -0
381 lines not on this page · raw message
tools/perf/Documentation/perfconfig.example +61 -12
90 lines not on this page · raw message
tools/perf/builtin-config.c new file +76 -0
76 lines not on this page · raw message
tools/perf/builtin.h +1 -0
@@ -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);
tools/perf/command-list.txt +1 -0
@@ -9,6 +9,7 @@ perf-buildid-cache mainporcelain common perf-buildid-list mainporcelain common perf-data mainporcelain common perf-diff mainporcelain common +perf-config mainporcelain common perf-evlist mainporcelain common perf-inject mainporcelain common perf-kmem mainporcelain common
tools/perf/perf.c +1 -0
@@ -37,6 +37,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 },
Signature · 1 line
1.9.1
PATCH v4 2/5 perf config: Add '--system' and '--global' options to be able to select which config file to be used
In reply to Taeung SongWhich config file is used is decided in only perf_config(). And a perf-confg command depend on perf_config() getting config file path. So add '--system' and '--global' options to select which config file to be used without perf_config(). If file-options isn't used, default config file path is $HOME/.perfconfig.
--- tools/perf/Documentation/perf-config.txt | 14 +++++++++++++- tools/perf/builtin-config.c | 21 ++++++++++++++++++--- tools/perf/util/cache.h | 2 ++ tools/perf/util/config.c | 4 ++-- 4 files changed, 35 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-config.txt +13 -1
@@ -8,7 +8,7 @@ perf-config - Get and set variables in a configuration file. SYNOPSIS -------- [verse] -'perf config' -l | --list +'perf config' [<file-option>] -l | --list DESCRIPTION -----------
@@ -21,6 +21,14 @@ OPTIONS --list:: Show current config variables with key and value into each sections. +--global:: + For writing and reading options: write to global + '$HOME/.perfconfig' file or read it. + +--system:: + For writing and reading options: write to system-wide + '$(sysconfdir)/perfconfig' or read it. + CONFIGURATION FILE ------------------
@@ -33,6 +41,10 @@ store a system-wide default configuration. The variables are divided into sections. In each section, the variables can are composed of a key and value. +When reading or writing, the values are read from the system and global +configuration files by default, and options '--system' and '--global' +can be used to tell the command to read from or write to only that location. + Syntax ~~~~~~
tools/perf/builtin-config.c +18 -3
@@ -14,6 +14,8 @@#include "util/debug.h" static int actions; +static bool use_system_config, use_global_config; +static const char *config_file_name;static const char *const config_usage[] = {"perf config [options]" ,
@@ -23,6 +25,9 @@ static const char * const config_usage[] = {#define ACTION_LIST (1<<0)static const struct option config_options[] = { +OPT_GROUP ("Config file location" ), +OPT_BOOLEAN (0 ,"system" , &use_system_config,"use system config file" ), +OPT_BOOLEAN (0 ,"global" , &use_global_config,"use global config file" ),OPT_GROUP ("Action" ),OPT_BIT ('l' ,"list" , &actions,"show current config variables" ,ACTION_LIST ),
@@ -53,16 +58,26 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)else has_option = false; +if (use_system_config && use_global_config) { +pr_err ("Error: only one config file at a time\n" ); +usage_with_options (config_usage, config_options); +return -1 ; + }else if (use_global_config || (!use_system_config && !use_global_config)) + config_file_name =mkpath ("%s/.perfconfig" ,getenv ("HOME" )); +else if (use_system_config) + config_file_name =perf_etc_perfconfig (); +switch (actions) {case ACTION_LIST :if (argc ==0 ) - ret =perf_config (show_config,NULL ); + ret =perf_config_from_file (show_config, config_file_name,NULL );else goto out_err; goto out;default : -if (!has_option && argc ==0 ) { - ret =perf_config (show_config,NULL ); +if ((!has_option || use_global_config || use_system_config) + && argc ==0 ) { + ret =perf_config_from_file (show_config, config_file_name,NULL ); goto out; }else goto out_err;
tools/perf/util/cache.h +2 -0
@@ -22,11 +22,13 @@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 *);extern int config_error_nonbool (const char *);extern const char *perf_config_dirname (const char *,const char *); +extern const char *perf_etc_perfconfig (void );/* pager.c */ extern void setup_pager (void );
tools/perf/util/config.c +2 -2
@@ -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" );
@@ -430,7 +430,7 @@ static int perf_config_from_file(config_fn_t fn, const char *filename, void *datreturn ret; } -static const char *perf_etc_perfconfig (void ) +const char *perf_etc_perfconfig (void ) {static const char *system_wide;if (!system_wide)
Signature · 1 line
1.9.1
PATCH v4 3/5 perf config: Add functions which can get or set perf config variables
In reply to Taeung SongThis patch consists of functions
which can get, set specific config variables.
For the syntax examples,
perf config [options] [section.name[=value] ...]
display key-value pairs of specific config variables
# perf config report.queue-size report.children
set specific config variables
# perf config report.queue-size=100M report.children=true
--- tools/perf/Documentation/perf-config.txt | 2 + tools/perf/builtin-config.c | 560 ++++++++++++++++++++++++++++++- tools/perf/util/cache.h | 17 + tools/perf/util/config.c | 25 ++ 4 files changed, 602 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-config.txt +2 -0
@@ -8,6 +8,8 @@ perf-config - Get and set variables in a configuration file. SYNOPSIS -------- [verse] +'perf config' [<file-option>] [section.name[=value] ...] +or 'perf config' [<file-option>] -l | --list DESCRIPTION
tools/perf/builtin-config.c +558 -2
593 lines not on this page · raw message
tools/perf/util/cache.h +17 -0
@@ -1,6 +1,7 @@#ifndef __PERF_CACHE_H#define __PERF_CACHE_H +#include <linux/list.h> #include <stdbool.h> #include "util.h" #include "strbuf.h"
@@ -19,6 +20,22 @@#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" +struct config_element { +char *name; +char *value; +struct list_head list; +}; + +struct config_section { +char *name; +struct list_head element_head; +struct list_head list; +}; + +struct list_head sections; + +typedef int (*configset_fn_t )(const char *,const char *,char *); +extern int perf_configset_write_in_full (const char *file_name);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 *);
tools/perf/util/config.c +25 -0
@@ -502,6 +502,31 @@ out:return ret; } +int perf_configset_write_in_full (const char *file_name) +{ +struct config_section *section_node; +struct config_element *element_node; +const char *first_line ="# this file is auto-generated." ; +FILE *fp =fopen (file_name,"w" ); + +if (!fp) +return -1 ; + +fprintf (fp,"%s\n" , first_line); +/* overwrite configvariables */ +list_for_each_entry (section_node, §ions, list) { +fprintf (fp,"[%s]\n" , section_node->name); +list_for_each_entry (element_node, §ion_node->element_head, list) { +if (element_node->value) +fprintf (fp,"\t%s = %s\n" , + element_node->name, element_node->value); + } + } +fclose (fp); + +return 0 ; +} +/* * Call this to report error for your variable that should not * get a boolean value (i.e. "[my] var" means "true").
Signature · 1 line
1.9.1
PATCH v4 4/5 perf config: Add a option 'list-all' to perf-config
In reply to Taeung SongA option 'list-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 -a | --list-all
--- tools/perf/Documentation/perf-config.txt | 6 ++++ tools/perf/builtin-config.c | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
tools/perf/Documentation/perf-config.txt +6 -0
@@ -11,6 +11,8 @@ SYNOPSIS 'perf config' [<file-option>] [section.name[=value] ...] or 'perf config' [<file-option>] -l | --list +or +'perf config' [<file-option>] -a | --list-all DESCRIPTION -----------
@@ -31,6 +33,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 ------------------
tools/perf/builtin-config.c +48 -0
72 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v4 5/5 perf config: Add a option 'remove' to perf-config
In reply to Taeung SongA option 'remove' is to remove specific config variables. For the syntax examples,
# perf config -r | --remove [section.name ...]
--- tools/perf/Documentation/perf-config.txt | 6 ++++++ tools/perf/builtin-config.c | 25 ++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-config.txt +6 -0
@@ -13,6 +13,8 @@ or 'perf config' [<file-option>] -l | --list or 'perf config' [<file-option>] -a | --list-all +or +'perf config' [<file-option>] -r | --remove [section.name ...] DESCRIPTION -----------
@@ -37,6 +39,10 @@ OPTIONS --list-all:: Show current and all possible config variables with default values. +-r:: +--remove:: + Remove specific config variables. + CONFIGURATION FILE ------------------
tools/perf/builtin-config.c +24 -1
@@ -24,6 +24,7 @@ static const char * const config_usage[] = {#define ACTION_LIST (1<<0)#define ACTION_LIST_ALL (1<<1) +#define ACTION_REMOVE (1<<2)static const struct option config_options[] = {OPT_GROUP ("Config file location" ),
@@ -34,6 +35,8 @@ static const struct option config_options[] = { "show current config variables", ACTION_LIST),OPT_BIT ('a' ,"list-all" , &actions,"show current and all possible config variables with default values" ,ACTION_LIST_ALL ), +OPT_BIT ('r' ,"remove" , &actions, +"remove specific variables: [section.name ...]" ,ACTION_REMOVE ), OPT_END() };
@@ -484,7 +487,15 @@ static int set_config(const char *section_name, const char *name, char *value)struct config_element *element_node =NULL ;find_config (§ion_node, &element_node, section_name, name); -if (value !=NULL ) { +if (!value) { +/* value == NULL means remove the variable */ +if (section_node && element_node) { +if (!element_node->value) +free (element_node->value); + element_node->value =NULL ; + }else +pr_err ("Error: Failed to find the variable.\n" ); + }else { value =normalize_value (section_name, name, value);/* if there isn't existent section, add a new section */
@@ -665,6 +676,18 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)else goto out_err; goto out; +case ACTION_REMOVE : +for (i =0 ; argv[i]; i++) { +if (value ==NULL ) + ret =perf_configset_with_option (set_config, argv[i],NULL ); +else { +pr_err ("invalid key: %s\n" , argv[i]); +return -1 ; + } +if (ret <0 ) + goto out; + } + goto out;default :if ((!has_option || use_global_config || use_system_config) && argc ==0 ) {
Signature · 1 line
1.9.1
Namhyung Kim
maintainerHi Taeung,
Quoted 40 lines · Taeung Song
Changes in v4:
- If some config value is default value, notice it is '(default)'as below.# perf config colors.normal colors.normal=lightgray, default (default)
- A config file path is only decided in
perf_config().
And a perf-config command depend onperf_config()deciding a config file path. So if the config file path is NULL because of some reason like no such file, a perf-config command can't write to the file. So, I added new options which are '--global' and '--system' to be enable to select config file path to be used withoutperf_config().Changes in v3:
- Add a config variable 'kmem.default' with a default value
into 'structdefault_configset' which has default config variables and values.- Add a option '--global' and '--local' to enable config file location to be selected
Changes in v2:
- Renaming variables a more suitable name
1. '--list-all' instead of '--all'
2. 'name' instead of 'subkey'
3. 'section, name, value' instead of 'given_section, subkey, value'- Correct small infelicities or typing errors in a perf-config documention.
- Remove a part description of report.children
because it was duplicated inDocumentation/callchain-overhead-calculation.txt- Use a variable 'int actions' instead of struct params which has 'bool
list_action' , 'bool get_action’ and etc. , to simplify a branching statement for perf-config options.- Declaration a global variable 'static struct
default_configsets' has config variables with default values instead of using a 'util/PERFCONFIG-DEFAULT' file and remove functionsmerge()andperse_key()to get perf config default values.- Add a function to normalize a value and check data type of it.
Quoted 7 lines
- Simplify parsing arguments as arguments is just divided by '=' and then in front of '.' is a section, between '.' and '=' is a name, and behind '=' is a value.
- Print config variables 'struct
default_configsets' haven't- Make a command ’perf config' without a option work as with a option '—list' instead of '--list-all’.
It seems the changelog itself is too big. I suggest make it more compact and put the details in the corresponding patches. Also you'd be better keeping the general description for the patchset here.
Thanks,
Namhyung
Quoted 25 lines
Taeung Song (5):
perf tools: Add 'perf-config' command
perf config: Add '--system' and '--global' options to be able to
select which config file to be used
perf config: Add functions which can get or set perf config variables perf config: Add a option 'list-all' to perf-config
perf config: Add a option 'remove' to perf-configtools/perf/Build | 1 + tools/perf/Documentation/perf-config.txt | 407 ++++++++++++++++ tools/perf/Documentation/perfconfig.example | 73 ++- tools/perf/builtin-config.c | 718 ++++++++++++++++++++++++++++ tools/perf/builtin.h | 1 + tools/perf/command-list.txt | 1 + tools/perf/perf.c | 1 + tools/perf/util/cache.h | 19 + tools/perf/util/config.c | 29 +- 9 files changed, 1236 insertions(+), 14 deletions(-) create mode 100644 tools/perf/Documentation/perf-config.txt create mode 100644 tools/perf/builtin-config.cSignature · 1 line
1.9.1