perf tools: Add 'perf-config' command
PATCH v2 1/4 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 | 375 ++++++++++++++++++++++++++++ tools/perf/Documentation/perfconfig.example | 70 +++++- tools/perf/builtin-config.c | 75 ++++++ tools/perf/builtin.h | 1 + tools/perf/command-list.txt | 1 + tools/perf/perf.c | 1 + 7 files changed, 512 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 +375 -0
375 lines not on this page · raw message
tools/perf/Documentation/perfconfig.example +58 -12
87 lines not on this page · raw message
tools/perf/builtin-config.c new file +75 -0
75 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 v2 2/4 perf tools: Add functions which can get or set perf config variables.
This 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 | 543 ++++++++++++++++++++++++++++++- tools/perf/util/cache.h | 17 + tools/perf/util/config.c | 30 +- 4 files changed, 587 insertions(+), 5 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' [section.name[=value] ...] +or 'perf config' -l | --list DESCRIPTION
tools/perf/builtin-config.c +541 -2
576 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 (void );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 +27 -3
@@ -21,7 +21,7 @@char buildid_dir[MAXPATHLEN ];/* root dir for buildid, binary cache */ static FILE *config_file; -static const char *config_file_name; +static char *config_file_name;static int config_linenr;static int config_file_eof;
@@ -420,12 +420,11 @@ static int perf_config_from_file(config_fn_t fn, const char *filename, void *dat ret =-1 ;if (f) { config_file = f; - config_file_name = filename; + config_file_name =strdup (filename); config_linenr =1 ; config_file_eof =0 ; ret =perf_parse_file (fn, data);fclose (f); - config_file_name =NULL ; }return ret; }
@@ -502,6 +501,31 @@ out:return ret; } +int perf_configset_write_in_full (void ) +{ +struct config_section *section_node; +struct config_element *element_node; +const char *first_line ="# this file is auto-generated." ; +FILE *fp =fopen (config_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 v2 3/4 perf tools: 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' [section.name[=value] ...] or 'perf config' -l | --list +or +'perf config' -a | --list-all DESCRIPTION -----------
@@ -23,6 +25,10 @@ OPTIONS --list:: Show current config variables with key and value into each sections. +-a:: +--list-all:: + Show current and all possible config variables with default values. + CONFIGURATION FILE ------------------
tools/perf/builtin-config.c +48 -0
70 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 4/4 perf tools: 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' -l | --list or 'perf config' -a | --list-all +or +'perf config' -r | --remove [section.name ...] DESCRIPTION -----------
@@ -29,6 +31,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
@@ -22,12 +22,14 @@ 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 ("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 ), +OPT_BIT ('r' ,"remove" , &actions,"remove specific variables: [section.name ...]" ,ACTION_REMOVE ),OPT_END () };
@@ -471,7 +473,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 */
@@ -490,6 +500,7 @@ static int set_config(const char *section_name, const char *name, char *value) element_node->value = value; } } +return perf_configset_write_in_full (); }
@@ -633,6 +644,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 && argc ==0 ) { ret =perf_config (show_config,NULL );
Signature · 1 line
1.9.1