perf tools: Add 'perf-config' command
v4 cover perf tools: Add 'perf-config' command
So far, it is difficult that the state of perf configs is looked through
and there's no knowing what kind of other variables except variables in perfconfig.example. Also perf configs can't be changed without manually modifying $HOME/.perfconfig or $(sysconfdir)/perfconfig file. So I suggest this patchset of the perf-config command which can list, get, set, remove perf configs or list with default config values as below.
[PATCH v4 1/5] perf tools: Add 'perf-config' command
[PATCH v4 2/5] perf config: Add '--system' and '--global' options to
select which config file to be used
[PATCH v4 3/5] perf config: Add functions which can get or set perf config variables [PATCH v4 4/5] perf config: Add a option 'list-all' to perf-config [PATCH v4 5/5] perf config: Add a option 'remove' to perf-config
Changes in v4:
- If some config value is default value, notice it is '(default)' as suggested by Jirka. (PATCH v4 3/5)
- If there wasn't any perfconfig file, perf-config malfunctioned like Jirka pointed out. So add exception routine with '--global' and '--system' option which can select perf config file path. (PATCH v4 2/5)
Changes in v3:
- Add a config variable 'kmem.default' with a default value as suggested by Namhyung. (PATCH v3 2/5, PATCH v4 3/5)
Changes in v2:
- Change option name of listing all configs as '--list-all' instead of '--all' as suggested by Namhyung. (PATCH v2 3/4, PATCH v4 4/5)
- Correct small infelicities or typing errors in a perf-config documention as suggested by Arnaldo. (PATCH v2 1/4, PATCH v4 1/5)
- Declaration a global variable 'static struct default_configsets' has config variables with default values instead of using a 'util/PERFCONFIG-DEFAULT' file. (PATCH v2 3/4, PATCH v4 3/5)
- Add a function to normalize a value and check data type of it. (PATCH v2 2/4, PATCH v4 3/5)
- 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. (PATCH v2 2/4, PATCH v4 3/5)
- If run perf-config command without any option, perf-config work as '--list'. (PATCH v2 1/4, PATCH v4 1/5)
--- 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
Namhyung Kim
maintainerHi Taeung,
Quoted 15 lines · Taeung Song
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 | --listSigned-off-by Taeung Song <[email protected]>---
[SNIP]
tools/perf/Documentation/perf-config.txt line 377
Quoted 5 lines
tools/perf/Documentation/perf-config.txt new file +5
-0+kmem.*:: + kmem.default:: + This option can decide which allocator is analyzed between 'slab' and 'page' + without using options '--slab' and '--page'. + Default value is 'page'.
The default is 'slab'.
tools/perf/Documentation/perf-config.txt
Quoted 7 lines
tools/perf/Documentation/perf-config.txt new file +7
-0+ +SEE ALSO +-------- +linkperf:perf[1], linkperf:perf-report[1] + +[kmem] + default = page
Ditto.
Quoted 43 lines
tools/perf/builtin-config.c new file +37
-0@@ -0,0 +1,76 @@ +/* +* builtin-config.c +* +* Copyright (C) 2015, Taeung Song <[email protected]> +* +*/ +#include "builtin.h" + +#include "perf.h" + +#include "util/cache.h" +#include "util/parse-options.h" +#include "util/util.h" +#include "util/debug.h" + +static int actions; + +static const char *const config_usage[] = { +"perf config [options]" , +NULL +}; + +#define ACTION_LIST (1<<0) + +static const struct option config_options[] = { +OPT_GROUP ("Action" ), +OPT_BIT ('l' ,"list" , &actions, +"show current config variables" ,ACTION_LIST ), +OPT_END () +}; + +static int show_config (const char *key,const char *value, +void *cb__maybe_unused ) +{ +if (value) +printf ("%s=%s\n" , key, value); +else
tools/perf/builtin-config.c line 47
Quoted 10 lines
tools/perf/builtin-config.c new file +10
-0+printf ("%s\n" , key); + +return 0 ; +} + +int cmd_config (int argc,const char **argv,const char *prefix__maybe_unused ) +{ +int ret =0 ; +int origin_argc = argc -1 ; +bool has_option;
Why are these needed?
Quoted 12 lines
tools/perf/builtin-config.c new file +12
-0+ + argc =parse_options (argc, argv, config_options, config_usage, +PARSE_OPT_STOP_AT_NON_OPTION ); +if (origin_argc > argc) + has_option = true; +else + has_option = false; + +switch (actions) { +case ACTION_LIST : +if (argc ==0 ) + ret =perf_config (show_config,NULL );
tools/perf/builtin-config.c line 69
Quoted 10 lines
tools/perf/builtin-config.c new file +10
-0+else + goto out_err; + goto out; +default : +if (!has_option && argc ==0 ) { + ret =perf_config (show_config,NULL ); + goto out; + }else + goto out_err; + }
Why not simply doing below instead?
case ACTION_LIST: default: if (argc) error ...; perf_config(show_config, ...); break;
Thanks,
Namhyung
Quoted 7 lines
tools/perf/builtin-config.c new file +7
-0+ +out_err: +pr_err ("Error: Unknown argument\n" ); +usage_with_options (config_usage, config_options); +out: +return ret; +}
PATCH v4 2/5 perf config: Add '--system' and '--global' options to select which config file is 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
Namhyung Kim
maintainerRe: [PATCH v4 2/5] perf config: Add '--system' and '--global' options to select which config file is used
Quoted 6 lines · Taeung Song
Which config file is used is decided in only
perf_config(). And a perf-confg command depend onperf_config()getting config file path. So add '--system' and '--global' options to select which config file to be used withoutperf_config(). If file-options isn't used, default config file path is $HOME/.perfconfig.
I guess you borrowed the names from git config. But IMHO perf is different since we don't have the 'local' (repository) concept. I think we should use either system/user or global/local naming scheme.
Thanks,
Namhyung
Quoted 144 lines
Signed-off-by Taeung Song <[email protected]>--- 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
Namhyung Kim
maintainerRe: [PATCH v4 3/5] perf config: Add functions which can get or set perf config variables
Quoted 2 lines · Taeung Song
This patch consists of functions
which can get, set specific config variables.
I think you'd be better splitting this patch into pieces. I'd like to do it with 3 patches - one for adding default config set (possibly squash/reorder --list-all patch too), next is for adding 'get' functionality, and finally adding 'set' feature. It'll make the reviewer's life little easier. :)
Nitpicks below...
Quoted 12 lines
For the syntax examples,
perf config [options] [section.name[=value] ...]
display key-value pairs of specific config variables
# perf config report.queue-size report.childrenset specific config variables
# perf config report.queue-size=100M report.children=trueSigned-off-by Taeung Song <[email protected]>---
[SNIP]
tools/perf/builtin-config.c static const struct option config_options[] = { · line 307
Quoted 4 lines
tools/perf/builtin-config.c +4
-0+ { + .section_name = KMEM, + .name = "default", + .value = "page",
s/page/slab/
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+ .type = NULL, + }, + { + .section_name = NULL, + .name = NULL, + .value = NULL, + .type = NULL, + }, +}; +
[SNIP]
tools/perf/builtin-config.c static const struct option config_options[] = { · line 365
Quoted 6 lines
tools/perf/builtin-config.c +6
-0+static int add_element (struct list_head *head, +const char *name,const char *value) +{ +struct config_element *element_node; + + element_node =zalloc (sizeof (*element_node));
Need to check return value here.
Quoted 44 lines
tools/perf/builtin-config.c +37
-0+ element_node->name =strdup (name); +if (!element_node->name) { +pr_err ("%s: strdup failed\n" , __func__); + goto out_free; + } +if (value) + element_node->value = (char *)value; +else + element_node->value =NULL ; + +list_add_tail (&element_node->list, head); +return 0 ; + +out_free: +free (element_node); +return -1 ; +} +static int show_config (const char *key,const char *value,void *cb__maybe_unused ) {@@ -45,10 +392,203 @@ static int show_config(const char *key, const char *value,return 0 ; } +static void find_config (struct config_section **section_node, +struct config_element **element_node, +const char *section_name,const char *name) +{ + *section_node =find_section (section_name); + +if (*section_node !=NULL ) + *element_node =find_element (name, *section_node); +else + *element_node =NULL ; +} + +static int show_spec_config (const char *section_name,const char *name, +char *value__maybe_unused ) +{ +int i; +struct config_section *section_node =NULL ; +struct config_element *element_node =NULL ; +char key[BUFSIZ ];
tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 423
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+ +find_config (§ion_node, &element_node, section_name, name); + +if (section_node && element_node) { +scnprintf (key,sizeof (key),"%s.%s" , + section_node->name, element_node->name); +return show_config (key, element_node->value,NULL ); + } + +for (i =0 ; default_configsets[i].section_name !=NULL ; i++) {
I'd do this with a local variable:
struct default_configset *config = &default_configsets[i];
Review static int show_config(const char *key, const char *value, · line 425
Quoted 2 lines
(quoted diff) +2
-0+ if (!strcmp(default_configsets[i].section_name, section_name) + && !strcmp(default_configsets[i].name, name)) {
Please put the '&&' operator in the above line.
Quoted 9 lines
tools/perf/builtin-config.c +9
-0+printf ("%s.%s=%s (default)\n" , default_configsets[i].section_name, + default_configsets[i].name, default_configsets[i].value); +return 0 ; + } + } + +pr_err ("Error: Failed to find the variable.\n" ); + +return 0 ;
tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 444
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+} + +static char *normalize_value (const char *section_name,const char *name,const char *value) +{ +int i; +char key[BUFSIZ ]; +char *normalized; + +scnprintf (key,sizeof (key),"%s.%s" , section_name, name); +for (i =0 ; default_configsets[i].section_name !=NULL ; i++) {
Ditto for default_configsets[i].
tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 447
Quoted 3 lines
tools/perf/builtin-config.c +3
-0+if (!strcmp (default_configsets[i].section_name, section_name) + && !strcmp (default_configsets[i].name, name)) { + normalized =zalloc (BUFSIZ );
Instead of always allocating BUFSIZ memory, please use asprintf().
Quoted 42 lines
tools/perf/builtin-config.c +42
-0+if (!default_configsets[i].type) +scnprintf (normalized,BUFSIZ ,"%s" , value); +else if (!strcmp (default_configsets[i].type,TYPE_BOOL )) +scnprintf (normalized,BUFSIZ ,"%s" , +perf_config_bool (key, value) ?"true" :"false" ); +else if (!strcmp (default_configsets[i].type,TYPE_ON_OFF )) +scnprintf (normalized,BUFSIZ ,"%s" , +perf_config_bool (key, value) ?"on" :"off" ); +else if (!strcmp (default_configsets[i].type,TYPE_INT )) +scnprintf (normalized,BUFSIZ ,"%d" , +perf_config_int (key, value)); +else if (!strcmp (default_configsets[i].type,TYPE_LONG )) +scnprintf (normalized,BUFSIZ ,"%" PRId64, +perf_config_u64 (key, value)); +else if (!strcmp (default_configsets[i].type,TYPE_DIRNAME )) +scnprintf (normalized,BUFSIZ ,"%s" , +perf_config_dirname (key, value)); +return normalized; + } + } + + normalized =strdup (value); +if (!normalized) { +pr_err ("%s: strdup failed\n" , __func__); +return NULL ; + } + +return normalized; +} + +static int set_config (const char *section_name,const char *name,char *value) +{ +struct config_section *section_node =NULL ; +struct config_element *element_node =NULL ; + +find_config (§ion_node, &element_node, section_name, name); +if (value !=NULL ) { + value =normalize_value (section_name, name, value); + +/* if there isn't existent section, add a new section */ +if (!section_node) { + section_node =init_section (section_name);
tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 499
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+if (!section_node) +return -1 ; +list_add_tail (§ion_node->list, §ions); + } +/* if nothing to replace, add a new element which contains key-value pair. */ +if (!element_node) { +add_element (§ion_node->element_head, name, value); + }else { +if (!element_node->value) +free (element_node->value);
I guess you wanted to check NULL pointer before freeing the old value. It's inverted, but anyway you can skip the check since free() already ignored NULL pointers.
tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 506
Quoted 7 lines
tools/perf/builtin-config.c +7
-0+ element_node->value = value; + } + } + +if (access (config_file_name,W_OK ) ==-1 ) { +pr_err ("Error: %s: Can't write to this file or no such file\n" , + config_file_name);
Not sure we need to error out in the 'no such file' case. Maybe it's ok to create a new file..
tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 517
Quoted 11 lines
tools/perf/builtin-config.c +11
-0+return -1 ; + } + +return perf_configset_write_in_full (config_file_name); +} + +static int collect_current_config (const char *var,const char *value, +void *cb__maybe_unused ) +{ +struct config_section *section_node; +char *key =strdup (var);
Who does free the key?
Quoted 20 lines
tools/perf/builtin-config.c +20
-0+char *section_name, *name; + +if (!key) { +pr_err ("%s: strdup failed\n" , __func__); +return -1 ; + } + + section_name =strsep (&key,"." ); + name =strsep (&key,"." ); +if (name ==NULL ) +return -1 ; + + section_node =find_section (section_name); +if (!section_node) { + section_node =init_section (section_name); +if (!section_node) +return -1 ; +list_add_tail (§ion_node->list, §ions); + } +
tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 547
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+return add_element (§ion_node->element_head, name, +normalize_value (section_name, name, value)); +} + +static int perf_configset_with_option (configset_fn_t fn,const char *var,char *value) +{ +char *section_name; +char *name; +const char *last_dot; +char *key =strdup (var);
Ditto.
Thanks,
Namhyung
Quoted 38 lines
tools/perf/builtin-config.c +38
-0+ +if (!key) { +pr_err ("%s: strdup failed\n" , __func__); +return -1 ; + } + last_dot =strchr (key,'.' ); +/* +* Since "key" actually contains the section name and the real +* key name separated by a dot, we have to know where the dot is. +*/ +if (last_dot ==NULL || last_dot == key) { +pr_err ("The config variable does not contain a section: %s\n" , key); +return -1 ; + } +if (!last_dot[1 ]) { +pr_err ("The config varible does not contain variable name: %s\n" , key); +return -1 ; + } + + section_name =strsep (&key,"." ); + name =strsep (&key,"." ); + +if (!value) { +/* do nothing */ + }else if (!strcmp (value,"=" )) { +pr_err ("The config variable does not contain a value: %s.%s\n" , + section_name, name); +return -1 ; + }else { + value++; + name =strsep (&name,"=" ); + } + +return fn (section_name, name, value); + +pr_err ("invalid key: %s\n" , var); +return -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
Namhyung Kim
maintainerRe: [PATCH v4 4/5] perf config: Add a option 'list-all' to perf-config
Quoted 52 lines · Taeung Song
A option 'list-all' is to display both current config variables and all possible config variables with default values.
The syntax examples are like belowperf config [options]
display all perf config with default values.
# perf config -a | --list-allSigned-off-by Taeung Song <[email protected]>--- 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 +1
-0@@ -23,6 +23,7 @@ static const char * const config_usage[] = { };#define ACTION_LIST (1<<0) +#define ACTION_LIST_ALL (1<<1)static const struct option config_options[] = {OPT_GROUP ("Config file location" ),
tools/perf/builtin-config.c static const struct option config_options[] = { · line 36
Quoted 5 lines
tools/perf/builtin-config.c +2
-0@@ -31,6 +32,8 @@ static const struct option config_options[] = {OPT_GROUP ("Action" ),OPT_BIT ('l' ,"list" , &actions,"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),
Why did you use OPT_BIT? Do you want to support multiple 'actions' at the same time? I'd rather support just one action, but I won't insist it strongly.. Anyway, setting bits will confuse the switch statement in the cmd_config().
Thanks,
Namhyung
Quoted 65 lines
tools/perf/builtin-config.c +45
-0OPT_END() };@@ -539,6 +542,45 @@ static int collect_current_config(const char *var, const char *value, normalize_value(section_name, name, value)); } +static int show_all_config (void ) +{ +int i; +bool has_config; +struct config_section *section_node; +struct config_element *element_node; + +for (i =0 ; default_configsets[i].section_name !=NULL ; i++) { +find_config (§ion_node, &element_node, + default_configsets[i].section_name, default_configsets[i].name); + +if (!element_node) +printf ("%s.%s=%s\n" , default_configsets[i].section_name, + default_configsets[i].name, default_configsets[i].value); +else +printf ("%s.%s=%s\n" , section_node->name, + element_node->name, element_node->value); + } + +/* Print config variables the default configsets haven't */ +list_for_each_entry (section_node, §ions, list) { +list_for_each_entry (element_node, §ion_node->element_head, list) { + has_config = false; +for (i =0 ; default_configsets[i].section_name !=NULL ; i++) { +if (!strcmp (default_configsets[i].section_name, section_node->name) + && !strcmp (default_configsets[i].name, element_node->name)) { + has_config = true; +break ; + } + } +if (!has_config) +printf ("%s.%s=%s\n" , section_node->name, + element_node->name, element_node->value); + } + } + +return 0 ; +} +static int perf_configset_with_option (configset_fn_t fn,const char *var,char *value) {char *section_name;@@ -617,6 +659,12 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)else goto out_err; goto out; +case ACTION_LIST_ALL : +if (argc ==0 ) + ret =show_all_config (); +else + goto out_err; + goto out;default :if ((!has_option || use_global_config || use_system_config) && argc ==0 ) {Signature · 1 line
1.9.1
Re: [PATCH v4 4/5] perf config: Add a option 'list-all' to perf-config
Hi, Namhyung
Quoted 63 lines · Namhyung Kim
Quoted 52 lines · Taeung Song
A option 'list-all' is to display both current config variables and all possible config variables with default values.
The syntax examples are like belowperf config [options]
display all perf config with default values.
# perf config -a | --list-allSigned-off-by Taeung Song <[email protected]>--- 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 +1
-0@@ -23,6 +23,7 @@ static const char * const config_usage[] = { };#define ACTION_LIST (1<<0) +#define ACTION_LIST_ALL (1<<1)static const struct option config_options[] = {OPT_GROUP ("Config file location" ),tools/perf/builtin-config.c static const struct option config_options[] = { · line 36
Quoted 5 lines
tools/perf/builtin-config.c +2
-0@@ -31,6 +32,8 @@ static const struct option config_options[] = {OPT_GROUP ("Action" ),OPT_BIT ('l' ,"list" , &actions,"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),Why did you use
OPT_BIT? Do you want to support multiple 'actions' at the same time? I'd rather support just one action, but I won't insist it strongly.. Anyway, setting bits will confuse the switch statement in thecmd_config().
Quoted 3 lines
Thanks,
Namhyung
I don't understand why setting bits will confuse the switch statement. Is the reason about readability of source code ?
But I searched for other parse-option which can be replaced. Is it better to use OPT_SET_INT instead of OPT_BIT ?
Thanks,
Taeung
Quoted 65 lines
Quoted 65 lines
tools/perf/builtin-config.c +45
-0OPT_END() };@@ -539,6 +542,45 @@ static int collect_current_config(const char *var, const char *value, normalize_value(section_name, name, value)); } +static int show_all_config (void ) +{ +int i; +bool has_config; +struct config_section *section_node; +struct config_element *element_node; + +for (i =0 ; default_configsets[i].section_name !=NULL ; i++) { +find_config (§ion_node, &element_node, + default_configsets[i].section_name, default_configsets[i].name); + +if (!element_node) +printf ("%s.%s=%s\n" , default_configsets[i].section_name, + default_configsets[i].name, default_configsets[i].value); +else +printf ("%s.%s=%s\n" , section_node->name, + element_node->name, element_node->value); + } + +/* Print config variables the default configsets haven't */ +list_for_each_entry (section_node, §ions, list) { +list_for_each_entry (element_node, §ion_node->element_head, list) { + has_config = false; +for (i =0 ; default_configsets[i].section_name !=NULL ; i++) { +if (!strcmp (default_configsets[i].section_name, section_node->name) + && !strcmp (default_configsets[i].name, element_node->name)) { + has_config = true; +break ; + } + } +if (!has_config) +printf ("%s.%s=%s\n" , section_node->name, + element_node->name, element_node->value); + } + } + +return 0 ; +} +static int perf_configset_with_option (configset_fn_t fn,const char *var,char *value) {char *section_name;@@ -617,6 +659,12 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)else goto out_err; goto out; +case ACTION_LIST_ALL : +if (argc ==0 ) + ret =show_all_config (); +else + goto out_err; + goto out;default :if ((!has_option || use_global_config || use_system_config) && argc ==0 ) {Signature · 1 line
1.9.1
Signature · 2 lines
Thanks, Taeung
Re: [PATCH v4 4/5] perf config: Add a option 'list-all' to perf-config
Hi, Namhyung
Quoted 63 lines · taeung
Hi, Namhyung
Quoted 58 lines · Namhyung Kim
Quoted 47 lines · Taeung Song
A option 'list-all' is to display both current config variables and all possible config variables with default values.
The syntax examples are like belowperf config [options]
display all perf config with default values.
# perf config -a | --list-allSigned-off-by Taeung Song <[email protected]>--- tools/perf/Documentation/perf-config.txt | 6 ++++ tools/perf/builtin-config.c | 48 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)tools/perf/Documentation/perf-config.txt +5
-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 ------------------ diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.cindex 6d9f28c..f4a1569 100644
tools/perf/builtin-config.c +1
-0@@ -23,6 +23,7 @@ static const char * const config_usage[] = { };#define ACTION_LIST (1<<0) +#define ACTION_LIST_ALL (1<<1)static const struct option config_options[] = {OPT_GROUP ("Config file location" ),tools/perf/builtin-config.c static const struct option config_options[] = { · line 36
Quoted 5 lines
tools/perf/builtin-config.c +2
-0@@ -31,6 +32,8 @@ static const struct option config_options[] = {OPT_GROUP ("Action" ),OPT_BIT ('l' ,"list" , &actions,"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),Why did you use
OPT_BIT? Do you want to support multiple 'actions' at the same time? I'd rather support just one action, but I won't insist it strongly.. Anyway, setting bits will confuse the switch statement in thecmd_config().
Quoted 9 lines
Quoted 3 lines
Thanks,
NamhyungI don't understand why setting bits will confuse the switch statement. Is the reason about readability of source code ?
But I searched for other parse-option which can be replaced. Is it better to use
OPT_SET_INTinstead ofOPT_BIT?
I modified source code to use OPT_SET_UINT
but the problem is happened. I declared "enum actions” to use OPT_SET_UINT like this.
enum actions {
ACTION_LIST,
ACTION_LIST_ALL,
ACTION_REMOVE
} actions;
But default value of actions” variable is 0 and ACTION_LIST is also 0
so when ‘get’ or ’set’ feature is used, ‘default:' of the switch statement in cmd_config() can’t reached because of default value of ‘actions’ variable is 0.
Use other parse-option function instead of OPT_SET_UINT ?
Thanks,
Taeung
Quoted 71 lines
Thanks,
TaeungQuoted 63 lines
Quoted 63 lines
tools/perf/builtin-config.c +0
-0OPT_END () }; @@ -539,6 +542,45 @@ static int collect_current_config(const char *var, const char *value,tools/perf/builtin-config.c +44
-0normalize_value(section_name, name, value)); } +static int show_all_config(void) +{ +int i; +bool has_config; +struct config_section *section_node; +struct config_element *element_node; + +for (i =0 ; default_configsets[i].section_name !=NULL ; i++) { +find_config (§ion_node, &element_node, + default_configsets[i].section_name, default_configsets[i].name); + +if (!element_node) +printf ("%s.%s=%s\n" , default_configsets[i].section_name, + default_configsets[i].name, default_configsets[i].value); +else +printf ("%s.%s=%s\n" , section_node->name, + element_node->name, element_node->value); + } + +/* Print config variables the default configsets haven't */ +list_for_each_entry (section_node, §ions, list) { +list_for_each_entry (element_node, §ion_node->element_head, list) { + has_config = false; +for (i =0 ; default_configsets[i].section_name !=NULL ; i++) { +if (!strcmp (default_configsets[i].section_name, section_node->name) + && !strcmp (default_configsets[i].name, element_node->name)) { + has_config = true; +break ; + } + } +if (!has_config) +printf ("%s.%s=%s\n" , section_node->name, + element_node->name, element_node->value); + } + } + +return 0 ; +} +static int perf_configset_with_option (configset_fn_t fn,const char *var,char *value) {char *section_name;@@ -617,6 +659,12 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)else goto out_err; goto out; +case ACTION_LIST_ALL : +if (argc ==0 ) + ret =show_all_config (); +else + goto out_err; + goto out;default :if ((!has_option || use_global_config || use_system_config) && argc ==0 ) {Signature · 1 line
1.9.1Signature · 2 lines
Thanks, Taeung
Namhyung Kim
maintainerRe: [PATCH v4 4/5] perf config: Add a option 'list-all' to perf-config
Quoted 29 lines · Taewoong Song
Quoted 10 lines
Quoted 10 lines
tools/perf/builtin-config.c static const struct option config_options[] = { · line 36
Quoted 5 lines
tools/perf/builtin-config.c +2
-0OPT_GROUP ("Action" ),OPT_BIT ('l' ,"list" , &actions,"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),Why did you use
OPT_BIT? Do you want to support multiple 'actions' at the same time? I'd rather support just one action, but I won't insist it strongly.. Anyway, setting bits will confuse the switch statement in thecmd_config().Quoted 9 lines
Quoted 3 lines
Thanks,
NamhyungI don't understand why setting bits will confuse the switch statement. Is the reason about readability of source code ?
But I searched for other parse-option which can be replaced. Is it better to use
OPT_SET_INTinstead ofOPT_BIT?I modified source code to use
OPT_SET_UINT
but the problem is happened. I declared "enum actions” to useOPT_SET_UINTlike this.enum actions {
ACTION_LIST,
ACTION_LIST_ALL,
ACTION_REMOVE
} actions;
Quoted 3 lines
But default value of actions” variable is 0 and
ACTION_LISTis also 0
so when ‘get’ or ’set’ feature is used, ‘default:' of the switch statement incmd_config()can’t reached because of default value of ‘actions’ variable is 0.
I don't know what's the problem. You could either set default value to -1 or make ACTION_LIST start from 1.
Thanks,
Namhyung
Namhyung Kim
maintainerRe: [PATCH v4 4/5] perf config: Add a option 'list-all' to perf-config
In reply to taeungQuoted 61 lines · taeung
Hi, Namhyung
Quoted 58 lines · Namhyung Kim
Quoted 47 lines · Taeung Song
A option 'list-all' is to display both current config variables and all possible config variables with default values.
The syntax examples are like belowperf config [options]
display all perf config with default values.
# perf config -a | --list-allSigned-off-by Taeung Song <[email protected]>--- 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 +1
-0@@ -23,6 +23,7 @@ static const char * const config_usage[] = { };#define ACTION_LIST (1<<0) +#define ACTION_LIST_ALL (1<<1)static const struct option config_options[] = {OPT_GROUP ("Config file location" ),tools/perf/builtin-config.c static const struct option config_options[] = { · line 36
Quoted 5 lines
tools/perf/builtin-config.c +2
-0@@ -31,6 +32,8 @@ static const struct option config_options[] = {OPT_GROUP ("Action" ),OPT_BIT ('l' ,"list" , &actions,"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),Why did you use
OPT_BIT? Do you want to support multiple 'actions' at the same time? I'd rather support just one action, but I won't insist it strongly.. Anyway, setting bits will confuse the switch statement in thecmd_config().
Quoted 5 lines
Quoted 3 lines
Thanks,
NamhyungI don't understand why setting bits will confuse the switch statement. Is the reason about readability of source code ?
Supposed you set ADD as 1 and DEL as 2. If you want do both action, it'll have value of 3. But switch statement only have case 1 or 2 (unless you give all possible combinations - but I don't think we want it).
Quoted 3 lines
But I searched for other parse-option which can be replaced. Is it better to use
OPT_SET_INTinstead ofOPT_BIT?
Please just use OPT_INTEGER.
Thanks,
Namhyung
Re: [PATCH v4 4/5] perf config: Add a option 'list-all' to perf-config
Quoted 68 lines · Namhyung Kim
Quoted 64 lines · taeung
Hi, Namhyung
Quoted 61 lines · Namhyung Kim
Quoted 47 lines · Taeung Song
A option 'list-all' is to display both current config variables and all possible config variables with default values.
The syntax examples are like belowperf config [options]
display all perf config with default values.
# perf config -a | --list-allSigned-off-by Taeung Song <[email protected]>---
tools/perf/Documentation/perf-config.txt| 6 ++++tools/perf/builtin-config.c| 48 ++++++++++++++++++++++++++++++++2 files changed, 54 insertions(+)tools/perf/Documentation/perf-config.txt +0
-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
-----------tools/perf/Documentation/perf-config.txt +4
-0@@ -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 +1
-0@@ -23,6 +23,7 @@ static const char * const config_usage[] = { };#define ACTION_LIST (1<<0) +#define ACTION_LIST_ALL (1<<1)static const struct option config_options[] = {OPT_GROUP ("Config file location" ),tools/perf/builtin-config.c static const struct option config_options[] = { · line 36
Quoted 5 lines
tools/perf/builtin-config.c +2
-0@@ -31,6 +32,8 @@ static const struct option config_options[] = {OPT_GROUP ("Action" ),OPT_BIT ('l' ,"list" , &actions,"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),Why did you use
OPT_BIT? Do you want to support multiple 'actions' at the same time? I'd rather support just one action, but I won't insist it strongly.. Anyway, setting bits will confuse the switch statement in thecmd_config().Thanks,
Namhyung
Quoted 8 lines
Quoted 2 lines
I don't understand why setting bits will confuse the switch statement. Is the reason about readability of source code ?
Supposed you set ADD as 1 and DEL as 2. If you want do both action, it'll have value of 3. But switch statement only have case 1 or 2 (unless you give all possible combinations - but I don't think we want it).
I understood what you said. Combinations of actions isn’t needed. So we don’t need to use OPT_BIT in perf-config.
But I thought that if more than two separate or same actions is used error messages should be printed like “error: only one action at a time” like this.
# perf config -l -l error: only one action at a time
# perf config -l -a -r test.test error: only one action at a time
Then using more than two actions should be blocked.
I thought about 2 solutions
1) comparing original ‘argc' and ‘argc' after parse_options() work like this.
int origin_argc = arc -1;
argc = parse_options(argc, argv, config_options, config_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
if (origin_argc != argc -1)
pr_err(“error: only one action at a time\n");
2) using OPT_BIT and HAS_MULTI_BIT()
HAS_MULTI_BIT() can check whether more than two actions is used or not.
Is needed this exception handing ?
Or it isn’t needed ?
Quoted 6 lines
Quoted 4 lines
But I searched for other parse-option which can be replaced. Is it better to use
OPT_SET_INTinstead ofOPT_BIT?Please just use
OPT_INTEGER.
I modified source code to use OPT_INTEGER.
But OPT_INTEGER require entering integer value like this.
# perf config —list=1 or # perf config -l 1
So, I just use OPT_SET_UINT because it can have default value in contrast with OPT_INTEGER like this.
static const struct option config_options[] = {
OPT_GROUP(“Action”),
OPT_SET_UINT(‘l’, “list”, &actions,
“show current config variables”, ACTION_LIST),
And I declared enum variable to distinguish between default value 0 and value of ACTION_LIST like this.
enum actions {
ACTION_LIST = 1,
ACTION_LIST_ALL,
ACTION_REMOVE
} actions;
Aren’t there problems if using OPT_SET_UINT instead of OPT_INTEGER ?
Thanks,
Taeung
Quoted 3 lines
Thanks,
Namhyung
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