perf tools: Add 'perf-config' command
PATCH 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 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 'perf-config' command with '--list' option and a document for it.
--- tools/perf/Build | 1 + tools/perf/Documentation/perf-config.txt | 436 ++++++++++++++++++++++++++++ tools/perf/Documentation/perfconfig.example | 68 ++++- tools/perf/builtin-config.c | 56 ++++ tools/perf/builtin.h | 1 + tools/perf/command-list.txt | 1 + tools/perf/perf.c | 1 + 7 files changed, 553 insertions(+), 11 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 +436 -0
436 lines not on this page · raw message
tools/perf/Documentation/perfconfig.example +57 -11
86 lines not on this page · raw message
tools/perf/builtin-config.c new file +56 -0
56 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 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.subkey[=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 | 276 ++++++++++++++++++++++++++++++- tools/perf/util/cache.h | 17 ++ tools/perf/util/config.c | 30 +++- 4 files changed, 320 insertions(+), 5 deletions(-)
tools/perf/Documentation/perf-config.txt +2 -0
@@ -8,6 +8,8 @@ perf-config - Get and set variables in configuration file. SYNOPSIS -------- [verse] +'perf config' [section.subkey[=value] ...] +or 'perf config' -l | --list DESCRIPTION
tools/perf/builtin-config.c +274 -2
307 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 *subkey; +char *value; +struct list_head list; +}; + +struct config_section { +char *name; +struct list_head element_head; +struct list_head list; +}; + +extern struct list_head *sections; + +typedef int (*configset_fn_t )(const char *,const char *,const 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, sections, 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->subkey, 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
Re: [PATCH 2/4] perf tools: Add functions which can get or set perf config variables.
Quoted 5 lines · Taeung Song
This patch consists of functions
which can get, set specific config variables.
For the syntax examples,perf config [options] [section.subkey[=value] ...]
not sure this gets fixed later on, but after applying up to this patch I've got following error:
Quoted 3 lines
display key-value pairs of specific config variables
# perf config report.queue-size report.children
[jolsa@krava perf]$ ./perf config report.queue-size invalid key: report.queue-size[jolsa@krava perf]$
Quoted 3 lines
set specific config variables
# perf config report.queue-size=100M report.children=true
[jolsa@krava perf]$ ./perf config report.queue-size=50M invalid key: report.queue-size=50M[jolsa@krava perf]$
jirka
Quoted 434 lines
Signed-off-by Taeung Song <[email protected]>--- tools/perf/Documentation/perf-config.txt | 2 + tools/perf/builtin-config.c | 276 ++++++++++++++++++++++++++++++- tools/perf/util/cache.h | 17 ++ tools/perf/util/config.c | 30 +++- 4 files changed, 320 insertions(+), 5 deletions(-)tools/perf/Documentation/perf-config.txt +2
-0@@ -8,6 +8,8 @@ perf-config - Get and set variables in configuration file. SYNOPSIS -------- [verse] +'perf config' [section.subkey[=value] ...] +or 'perf config' -l | --list DESCRIPTIONtools/perf/builtin-config.c +274
-2@@ -15,10 +15,14 @@static struct {bool list_action; +bool get_action; +bool set_action; } params; +struct list_head *sections; +static const char *const config_usage[] = { -"perf config [options]" , +"perf config [options] [section.subkey[=value] ...]" ,NULL };static const struct option config_options[] = {@@ -27,6 +31,74 @@ static const struct option config_options[] = {OPT_END () }; +static struct config_section *find_config_section (const char *section_name) +{ +struct config_section *section_node; +list_for_each_entry (section_node, sections, list) +if (!strcmp (section_node->name, section_name)) +return section_node; + +return NULL ; +} + +static struct config_element *find_config_element (const char *subkey, +struct config_section *section_node) +{ +struct config_element *element_node; + +list_for_each_entry (element_node, §ion_node->element_head, list) +if (!strcmp (element_node->subkey, subkey)) +return element_node; + +return NULL ; +} + +static struct config_section *init_config_section (const char *section_name) +{ +struct config_section *section_node; + + section_node =zalloc (sizeof (*section_node)); +if (!section_node) +return NULL ; + +INIT_LIST_HEAD (§ion_node->element_head); + section_node->name =strdup (section_name); +if (!section_node->name) { +pr_err ("%s: strdup failed\n" , __func__); +free (section_node); +return NULL ; + } + +return section_node; +} + +static int add_config_element (struct list_head *head, +const char *subkey,const char *value) +{ +struct config_element *element_node; + element_node =zalloc (sizeof (*element_node)); + element_node->subkey =strdup (subkey); +if (!element_node->subkey) { +pr_err ("%s: strdup failed\n" , __func__); + goto out_free; + } +if (value) { + element_node->value =strdup (value); +if (!element_node->value) { +pr_err ("%s: strdup failed\n" , __func__); + goto out_free; + } + }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 ) {@@ -38,12 +110,211 @@ static int show_config(const char *key, const char *value,return 0 ; } -int cmd_config (int argc,const char **argv,const char *prefix__maybe_unused ) +static void find_config (struct config_section **section_node,struct config_element **element_node, +const char *given_section_name,const char *given_subkey) +{ + *section_node =find_config_section (given_section_name); + +if (*section_node !=NULL ) + *element_node =find_config_element (given_subkey, *section_node); +else + *element_node =NULL ; +} + +static int show_spec_config (const char *section_name,const char *subkey, +const char *value__maybe_unused ) +{ +struct config_section *section_node =NULL ; +struct config_element *element_node =NULL ; +char key[BUFSIZ ]; + +find_config (§ion_node, &element_node, section_name, subkey); + +if (section_node && element_node) { +scnprintf (key,sizeof (key),"%s.%s" , section_node->name, element_node->subkey); +show_config (key, element_node->value,NULL ); + }else +pr_err ("Error: Failed to find the variable.\n" ); + +return 0 ; +} + +static int set_config (const char *section_name,const char *subkey, +const char *value) +{ +struct config_section *section_node =NULL ; +struct config_element *element_node =NULL ; + +find_config (§ion_node, &element_node, section_name, subkey); + +/* if there isn't existent section, add a new section */ +if (!section_node) { + section_node =init_config_section (section_name); +if (!section_node) +return -1 ; +list_add_tail (§ion_node->list, sections); + } +/* if nothing to replace, add a new element which contains key-value pair. */ +if (!element_node) +return add_config_element (§ion_node->element_head, subkey, value); +else + element_node->value = (char *)value; + +return 0 ; +} + +static int set_spec_config (const char *section_name,const char *subkey, +const char *value) {int ret =0 ; + ret +=set_config (section_name, subkey, value); + ret +=perf_configset_write_in_full (); + +return ret; +} + +static void parse_key (const char *var,const char **section_name,const char **subkey) +{ +char *key =strdup (var); + +if (!key) +die ("%s: strdup failed\n" , __func__); + + *section_name =strsep (&key,"." ); + *subkey =strsep (&key,"." ); +} + +static int collect_config (const char *var,const char *value, +void *cb__maybe_unused ) +{ +struct config_section *section_node; +const char *section_name, *subkey; + +parse_key (var, §ion_name, &subkey); + + section_node =find_config_section (section_name); +if (!section_node) { +/* Add a new section */ + section_node =init_config_section (section_name); +if (!section_node) +return -1 ; +list_add_tail (§ion_node->list, sections); + } + +return add_config_element (§ion_node->element_head, subkey, value); +} + +static int perf_configset_with_option (configset_fn_t fn,const char *var) +{ +int i, num_dot =0 , num_equals =0 ; +static char *given_section_name; +static char *given_subkey; +static char *given_value; +const char *last_dot; +char *key =strdup (var); + +if (!key) { +pr_err ("%s: strdup failed\n" , __func__); +return -1 ; + } + last_dot =strrchr (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 ; + } +for (i =0 ; key[i]; i++) { +if (i ==0 && !isalpha (key[i++])) + goto out_err; + +switch (key[i]) { +case '.' : + num_dot +=1 ; +if (!isalpha (key[++i])) + goto out_err; +break ; +case '=' : + num_equals +=1 ; +break ; +default : +if (!isalpha (key[i]) && !isalnum (key[i])) + goto out_err; + } + } + +if (num_equals >1 || num_dot >1 ) + goto out_err; + + given_value =strchr (key,'=' ); +if (given_value ==NULL || given_value == key) + given_value =NULL ; +else { +if (!given_value[1 ]) { +pr_err ("The config variable does not contain a value: %s\n" , key); +return -1 ; + }else + given_value++; + } + given_section_name =strsep (&key,"." ); + given_subkey =strsep (&key,"." ); + +if (given_value) + given_subkey =strsep (&given_subkey,"=" ); + +if (!sections) { + sections =zalloc (sizeof (*sections)); +if (!sections) +return -1 ; + +INIT_LIST_HEAD (sections); +perf_config (collect_config,NULL ); + } + +return fn (given_section_name, given_subkey, given_value); + +out_err: +pr_err ("invalid key: %s" , var); +return -1 ; +} + +int cmd_config (int argc,const char **argv,const char *prefix__maybe_unused ) +{ +int i, ret =0 ; +int origin_argc = argc -1 ; +char *value; +bool is_option; argc =parse_options (argc, argv, config_options, config_usage,PARSE_OPT_STOP_AT_NON_OPTION ); +if (origin_argc > argc) + is_option = true; +else + is_option = false; + +if (!is_option && argc >=0 ) { +switch (argc) { +case 0 : +break ; +default : +for (i =0 ; argv[i]; i++) { + value =strrchr (argv[i],'=' ); +if (value ==NULL || value == argv[i]) + ret =perf_configset_with_option (show_spec_config, argv[i]); +else + ret =perf_configset_with_option (set_spec_config, argv[i]); +if (ret <0 ) +break ; + } + goto out; + } + }if (params.list_action && argc ==0 ) ret =perf_config (show_config,NULL );@@ -52,5 +323,6 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)usage_with_options (config_usage, config_options); } +out:return ret; }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 *subkey; +char *value; +struct list_head list; +}; + +struct config_section { +char *name; +struct list_head element_head; +struct list_head list; +}; + +extern struct list_head *sections; + +typedef int (*configset_fn_t )(const char *,const char *,const 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, sections, 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->subkey, 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
Re: [PATCH 2/4] perf tools: Add functions which can get or set perf config variables.
In reply to Taeung SongQuoted 8 lines · Taeung Song
This patch consists of functions
which can get, set specific config variables.
For the syntax examples,perf config [options] [section.subkey[=value] ...]
display key-value pairs of specific config variables
# perf config report.queue-size report.children
[jolsa@krava perf]$ ./perf config krava.krava
krava.krava=true
?
some comments below
Quoted 11 lines
set specific config variables
# perf config report.queue-size=100M report.children=trueSigned-off-by Taeung Song <[email protected]>--- tools/perf/Documentation/perf-config.txt | 2 + tools/perf/builtin-config.c | 276 ++++++++++++++++++++++++++++++- tools/perf/util/cache.h | 17 ++ tools/perf/util/config.c | 30 +++- 4 files changed, 320 insertions(+), 5 deletions(-)
SNIP
Quoted 9 lines
tools/perf/builtin-config.c +7
-0+static int set_spec_config (const char *section_name,const char *subkey, +const char *value) {int ret =0 ; + ret +=set_config (section_name, subkey, value); + ret +=perf_configset_write_in_full (); + +return ret; +}
tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 184
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+ +static void parse_key (const char *var,const char **section_name,const char **subkey) +{ +char *key =strdup (var); + +if (!key) +die ("%s: strdup failed\n" , __func__); + + *section_name =strsep (&key,"." ); + *subkey =strsep (&key,"." );
should this check the config syntax? could be used for command line check as well
Quoted 7 lines
tools/perf/builtin-config.c +7
-0+} + +static int collect_config (const char *var,const char *value, +void *cb__maybe_unused ) +{ +struct config_section *section_node; +const char *section_name, *subkey;
SNIP
Quoted 7 lines
tools/perf/builtin-config.c +7
-0+ } +for (i =0 ; key[i]; i++) { +if (i ==0 && !isalpha (key[i++])) + goto out_err; + +switch (key[i]) { +case '.' :
tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 248
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+ num_dot +=1 ; +if (!isalpha (key[++i])) + goto out_err; +break ; +case '=' : + num_equals +=1 ; +break ; +default : +if (!isalpha (key[i]) && !isalnum (key[i])) + goto out_err;
you dont allow '-' in the key report.queue-size, I think we should support also _
also please put the name checks into separated function
Quoted 9 lines
tools/perf/builtin-config.c +9
-0+ } + } + +if (num_equals >1 || num_dot >1 ) + goto out_err; + + given_value =strchr (key,'=' ); +if (given_value ==NULL || given_value == key) + given_value =NULL ;
SNIP
Quoted 5 lines
tools/perf/builtin-config.c +3
-0argc =parse_options (argc, argv, config_options, config_usage,PARSE_OPT_STOP_AT_NON_OPTION ); +if (origin_argc > argc) + is_option = true; +else
tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 308
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+ is_option = false; + +if (!is_option && argc >=0 ) { +switch (argc) { +case 0 : +break ; +default : +for (i =0 ; argv[i]; i++) { + value =strrchr (argv[i],'=' ); +if (value ==NULL || value == argv[i])
hum, so you let go in args like '=krava' ?
why dont you completely check the name (assignment string) first and decide later about the callback
Quoted 9 lines
tools/perf/builtin-config.c +9
-0+ ret =perf_configset_with_option (show_spec_config, argv[i]); + else + ret =perf_configset_with_option (set_spec_config, argv[i]); +if (ret <0 ) +break ; + } + goto out; + } + }
SNIP
tools/perf/util/config.c out: · line 508
Quoted 9 lines
tools/perf/util/config.c +5
-0@@ -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." ;
so you parse whole config, change it and write back.. hum, I dont see better way.. and I like the first line ;-)
Quoted 26 lines
tools/perf/util/config.c +20
-0+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, sections, 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->subkey, 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
Re: [PATCH 2/4] perf tools: Add functions which can get or set perf config variables.
Hi, Jiri Olsa
Thanks for your feedbacks on my patches.
There are one thing I don't understand very well.
I wrote a number 1) in the middle of the your feedbacks to mark it.
I don't follow, could you elaborate it little more?
Quoted 106 lines · Jiri Olsa
Quoted 8 lines · Taeung Song
This patch consists of functions
which can get, set specific config variables.
For the syntax examples,perf config [options] [section.subkey[=value] ...]
display key-value pairs of specific config variables # perf config report.queue-size report.children
[jolsa@krava perf]$ ./perf config krava.krava
krava.krava=true?
some comments below
Quoted 10 lines
set specific config variables
# perf config report.queue-size=100M report.children=trueSigned-off-by Taeung Song <[email protected]>--- tools/perf/Documentation/perf-config.txt | 2 + tools/perf/builtin-config.c | 276 ++++++++++++++++++++++++++++++- tools/perf/util/cache.h | 17 ++ tools/perf/util/config.c | 30 +++- 4 files changed, 320 insertions(+), 5 deletions(-)SNIP
Quoted 9 lines
tools/perf/builtin-config.c +7
-0+static int set_spec_config (const char *section_name,const char *subkey, +const char *value) {int ret =0 ; + ret +=set_config (section_name, subkey, value); + ret +=perf_configset_write_in_full (); + +return ret; +}tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 184
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+ +static void parse_key (const char *var,const char **section_name,const char **subkey) +{ +char *key =strdup (var); + +if (!key) +die ("%s: strdup failed\n" , __func__); + + *section_name =strsep (&key,"." ); + *subkey =strsep (&key,"." );should this check the config syntax? could be used for command line check as well
Quoted 7 lines
tools/perf/builtin-config.c +7
-0+} + +static int collect_config (const char *var,const char *value, +void *cb__maybe_unused ) +{ +struct config_section *section_node; +const char *section_name, *subkey;SNIP
Quoted 7 lines
tools/perf/builtin-config.c +7
-0+ } +for (i =0 ; key[i]; i++) { +if (i ==0 && !isalpha (key[i++])) + goto out_err; + +switch (key[i]) { +case '.' :tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 248
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+ num_dot +=1 ; +if (!isalpha (key[++i])) + goto out_err; +break ; +case '=' : + num_equals +=1 ; +break ; +default : +if (!isalpha (key[i]) && !isalnum (key[i])) + goto out_err;you dont allow '-' in the key report.queue-size, I think we should support also _
also please put the name checks into separated function
Quoted 9 lines
tools/perf/builtin-config.c +9
-0+ } + } + +if (num_equals >1 || num_dot >1 ) + goto out_err; + + given_value =strchr (key,'=' ); +if (given_value ==NULL || given_value == key) + given_value =NULL ;SNIP
Quoted 5 lines
argc = parse_options(argc, argv,
config_options,config_usage,
PARSE_OPT_STOP_AT_NON_OPTION);tools/perf/builtin-config.c +3
-0+if (origin_argc > argc) + is_option = true; +else tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 308
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+ is_option = false; + +if (!is_option && argc >=0 ) { +switch (argc) { +case 0 : +break ; +default : +for (i =0 ; argv[i]; i++) { + value =strrchr (argv[i],'=' ); +if (value ==NULL || value == argv[i])hum, so you let go in args like '=krava' ?
Quoted 3 lines
why dont you completely check the name (assignment string) first and decide later about the callback
1) I understood that the name must be completely checked first. But I don't know the callback. What does it mean ? Could you elaborate it little more?
Thanks,
Taeung
Quoted 49 lines
Quoted 9 lines
tools/perf/builtin-config.c +9
-0+ ret =perf_configset_with_option (show_spec_config, argv[i]); + else + ret =perf_configset_with_option (set_spec_config, argv[i]); +if (ret <0 ) +break ; + } + goto out; + } + }SNIP
tools/perf/util/config.c out: · line 508
Quoted 9 lines
tools/perf/util/config.c +5
-0@@ -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." ;so you parse whole config, change it and write back.. hum, I dont see better way.. and I like the first line ;-)
Quoted 26 lines
tools/perf/util/config.c +20
-0+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, sections, 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->subkey, 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 3/4 perf tools: Add a option 'all' to perf-config.
In reply to Taeung SongA option '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
or
# perf config -a | --all
--- tools/perf/Documentation/perf-config.txt | 6 +++ tools/perf/builtin-config.c | 49 ++++++++++++++++++++++++ tools/perf/util/PERFCONFIG-DEFAULT | 65 ++++++++++++++++++++++++++++++++ tools/perf/util/cache.h | 1 + tools/perf/util/config.c | 2 +- 5 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 tools/perf/util/PERFCONFIG-DEFAULT
tools/perf/Documentation/perf-config.txt +6 -0
@@ -11,6 +11,8 @@ SYNOPSIS 'perf config' [section.subkey[=value] ...] or 'perf config' -l | --list +or +'perf config' -a | --all DESCRIPTION -----------
@@ -23,6 +25,10 @@ OPTIONS --list:: Show current config variables with key and value into each sections. +-a:: +--all:: + Show current and all possible config variables with default values. + CONFIGURATION FILE ------------------
tools/perf/builtin-config.c +49 -0
79 lines not on this page · raw message
tools/perf/util/PERFCONFIG-DEFAULT new file +65 -0
65 lines not on this page · raw message
tools/perf/util/cache.h +1 -0
@@ -39,6 +39,7 @@ 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 *); +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 *);
tools/perf/util/config.c +1 -1
@@ -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" );
Signature · 1 line
1.9.1
Re: [PATCH 3/4] perf tools: Add a option 'all' to perf-config.
Quoted 10 lines · Taeung Song
A option '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
or
# perf config -a | --all
hum, seems some values are mixed:
[jolsa@krava perf]$ ./perf config | grep size
call-graph.dump-size =
report.queue-size = true
SNIP
Quoted 21 lines
struct
list_head*sections;tools/perf/builtin-config.c +9
-0@@ -28,6 +29,8 @@ static const char * const config_usage[] = {static const struct option config_options[] = {OPT_GROUP ("Action" ),OPT_BOOLEAN ('l' ,"list" , ¶ms.list_action,"show current config variables" ), +OPT_BOOLEAN ('a' ,"all" , ¶ms.all_action, +"show current and all possible config variables with default values" ),OPT_END () };@@ -204,6 +207,49 @@ static int collect_config(const char *var, const char *value,return add_config_element (§ion_node->element_head, subkey, value); } +static int merge_config (const char *var,const char *value, +void *cb__maybe_unused ) +{ +const char *section_name, *subkey; +parse_key (var, §ion_name, &subkey); +return set_config (section_name, subkey, value); +}
tools/perf/builtin-config.c static int collect_config(const char *var, const char *value, · line 226
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+ +static int show_all_config (void ) +{ +int ret =0 ; +struct config_section *section_node; +struct config_element *element_node; +char *pwd, *all_config; + + pwd =getenv ("PWD" ); + all_config =strdup (mkpath ("%s/util/PERFCONFIG-DEFAULT" , pwd));
I haven't checked the whole code, but this cannot be dependent on the presence of the kernel tree..
I'll give it more time later today
jirka
Re: [PATCH 3/4] perf tools: Add a option 'all' to perf-config.
In reply to Taeung SongQuoted 10 lines · Taeung Song
A option '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
or
# perf config -a | --all
hum, I think we wanted
'perf config' to display current config file (same as -l)
'perf config -a' to display all possible config
jirka
Re: [PATCH 3/4] perf tools: Add a option 'all' to perf-config.
In reply to Taeung SongOn Mon, Apr 27, 2015 at 03:34:25PM +0900, Taeung Song wrote:
SNIP
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+ +static int show_all_config (void ) +{ +int ret =0 ; +struct config_section *section_node; +struct config_element *element_node; +char *pwd, *all_config; + + pwd =getenv ("PWD" ); + all_config =strdup (mkpath ("%s/util/PERFCONFIG-DEFAULT" , pwd));
tools/perf/builtin-config.c static int collect_config(const char *var, const char *value, · line 236
Quoted 10 lines
tools/perf/builtin-config.c +10
-0+ +if (!all_config) { +pr_err ("%s: strdup failed\n" , __func__); +return -1 ; + } + + sections =zalloc (sizeof (*sections)); +if (!sections) +return -1 ; +INIT_LIST_HEAD (sections);
this code pattern is already there, please placeit into function
also, where's the section freed?
jirka
Re: [PATCH 3/4] perf tools: Add a option 'all' to perf-config.
In reply to Taeung SongOn Mon, Apr 27, 2015 at 03:34:25PM +0900, Taeung Song wrote:
SNIP
Quoted 7 lines
(quoted diff) +7
-0+static int merge_config(const char *var, const char *value, + void *cb __maybe_unused) +{ + const char *section_name, *subkey; + parse_key(var, §ion_name, &subkey); + return set_config(section_name, subkey, value); +}
Review
Quoted 10 lines
(quoted diff) +10
-0+ +static int show_all_config(void) +{ + int ret = 0; + struct config_section *section_node; + struct config_element *element_node; + char *pwd, *all_config; + + pwd = getenv("PWD"); + all_config = strdup(mkpath("%s/util/PERFCONFIG-DEFAULT", pwd));
so we could compile defaultconfig directly into perf via following change
maybe the PERFCONFIG-DEFAULT could be in perf root dir
also I'm not sure if xxd is common enough to be used, maybe there's some common way used in kernel build already
jirka
---
tools/build/Makefile.build +1 -0
@@ -41,6 +41,7 @@ include $(build-file) quiet_cmd_flex = FLEX $@ quiet_cmd_bison = BISON $@ +quiet_cmd_xxd = XXD $@ # Create directory unless it exists quiet_cmd_mkdir = MKDIR $(dir $@)
tools/perf/Build +5 -0
@@ -43,3 +43,8 @@ libperf-y += ui/ libperf-y += scripts/ gtk-y += ui/gtk/ + +$(OUTPUT)builtin-config.o: $(OUTPUT)util/PERFCONFIG-DEFAULT.h + +$(OUTPUT)util/PERFCONFIG-DEFAULT.h: $(OUTPUT)util/PERFCONFIG-DEFAULT + @$(call echo-cmd,xxd)xxd -i $< > $@
tools/perf/builtin-config.c +1 -0
@@ -12,6 +12,7 @@#include "util/parse-options.h" #include "util/util.h" #include "util/debug.h" +#include "util/PERFCONFIG-DEFAULT.h" static struct { bool list_action;
PATCH 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.subkey ...]
--- tools/perf/Documentation/perf-config.txt | 6 ++++ tools/perf/builtin-config.c | 48 +++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 13 deletions(-)
tools/perf/Documentation/perf-config.txt +6 -0
@@ -13,6 +13,8 @@ or 'perf config' -l | --list or 'perf config' -a | --all +or +'perf config' -r | --remove [section.subkey ...] DESCRIPTION -----------
@@ -29,6 +31,10 @@ OPTIONS --all:: Show current and all possible config variables with default values. +-r:: +--remove:: + Remove specific config variables. + CONFIGURATION FILE ------------------
tools/perf/builtin-config.c +35 -13
73 lines not on this page · raw message
Signature · 1 line
1.9.1
Arnaldo Carvalho de Melo
maintainerEm Mon, Apr 27, 2015 at 03:34:23PM +0900, Taeung Song escreveu:
Quoted 36 lines
The perf configuration file contains 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 'perf-config' command with '--list' option and a document for it.Signed-off-by Taeung Song <[email protected]>--- tools/perf/Build | 1 + tools/perf/Documentation/perf-config.txt | 436 ++++++++++++++++++++++++++++ tools/perf/Documentation/perfconfig.example | 68 ++++- tools/perf/builtin-config.c | 56 ++++ tools/perf/builtin.h | 1 + tools/perf/command-list.txt | 1 + tools/perf/perf.c | 1 + 7 files changed, 553 insertions(+), 11 deletions(-) create mode 100644 tools/perf/Documentation/perf-config.txt create mode 100644 tools/perf/builtin-config.ctools/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.otools/perf/Documentation/perf-config.txt new file +0
-0
tools/perf/Documentation/perf-config.txt line 6
Quoted 6 lines
tools/perf/Documentation/perf-config.txt new file +6
-0@@ -0,0 +1,436 @@ +perf-config(1) +============== + +NAME +---- +perf-config - Get and set variables in configuration file.
"perf-config - Get and set variables in configuration files."
or:
"perf config - Get and set variables in a configuration file."
Looks more fluid, no?
tools/perf/Documentation/perf-config.txt line 15
Quoted 9 lines
tools/perf/Documentation/perf-config.txt new file +9
-0+ +SYNOPSIS +-------- +[verse] +'perf config' -l | --list + +DESCRIPTION +----------- +You can manage variables in configuration file with this command.
ditto, "... in a configuration file ..."
tools/perf/Documentation/perf-config.txt line 22
Quoted 7 lines
tools/perf/Documentation/perf-config.txt new file +7
-0+ +OPTIONS +------- + +-l:: +--list:: + Show current config variables with key and value into each sections.
section.
tools/perf/Documentation/perf-config.txt line 27
Quoted 5 lines
tools/perf/Documentation/perf-config.txt new file +5
-0+ +CONFIGURATION FILE +------------------ + +The Perf configuration file contain many variables which can make
contains
tools/perf/Documentation/perf-config.txt line 28
Quoted 1 line
tools/perf/Documentation/perf-config.txt new file +1
-0+the perf command's action more effective, more skilful.
?
tools/perf/Documentation/perf-config.txt line 30
Quoted 2 lines
tools/perf/Documentation/perf-config.txt new file +2
-0+The '$HOME/.perfconfig' file is used to store a per-user configuration. +The file 'etc/perfconfig' or '$(sysconfdir)/perfconfig' can be used to
/etc/perfconfig ?
tools/perf/Documentation/perf-config.txt line 33
Quoted 3 lines
tools/perf/Documentation/perf-config.txt new file +3
-0+store a system-wide default configuration. + +The variables are divided into sections. In each sections, the variables
section
tools/perf/Documentation/perf-config.txt line 34
Quoted 1 line
tools/perf/Documentation/perf-config.txt new file +1
-0+can contain a key and values.
are composed of a key and values?
tools/perf/Documentation/perf-config.txt line 43
Quoted 9 lines
tools/perf/Documentation/perf-config.txt new file +9
-0+ +Syntax +~~~~~~ + +The file consists of sections and subkeys. A section begins with +the name of the section in square brackets and continues until the next +section begins. Each variable have to belong to some section, which means +there must be a section header before the first setting of a variable, as below: +Each variable are in the form 'subkey = value'.
why "subkey" instead of "name"?
tools/perf/Documentation/perf-config.txt line 49
Quoted 6 lines
tools/perf/Documentation/perf-config.txt new file +6
-0+ + [section] + subkey1 = value1 + subkey2 = value2 + +Subsection names are case sensitive and can contain any characters except
"subsection"? Why not just "section"
tools/perf/Documentation/perf-config.txt line 51
Quoted 2 lines
tools/perf/Documentation/perf-config.txt new file +2
-0+newline (doublequote `"` and backslash have to be escaped as `\"` and `\\`, +respectively). Section headers cannot span multiple
"can't" or "can not"?
tools/perf/Documentation/perf-config.txt line 52
Quoted 1 line
tools/perf/Documentation/perf-config.txt new file +1
-0+lines. Variables may belong directly to a section or to a given subsection.
? define "section" and "subsection" :-)
Quoted 48 lines
tools/perf/Documentation/perf-config.txt new file +48
-0+ +Example +~~~~~~~ + +Given a $HOME/.perfconfig like this: + +# +# This is the config file, and +# a '#' and ';' character indicates a comment +# + +[colors] + # Color variables + top = red, default + medium = green, default + normal = lightgray, default + selected = white, lightgray + code = blue, default + addr = magenta, default + root = white, blue + +[tui] + # Defaults if linked with libslang + 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 + +[help] + # Format can be man, info, web or html + format = man + autocorrect = 0 + +[ui] + show-headers= true + +[call-graph] + # fp (framepointer), dwarf
tools/perf/Documentation/perf-config.txt line 110
Quoted 10 lines
tools/perf/Documentation/perf-config.txt new file +10
-0+ record-mode = fp + print-type = graph + order = caller + sort-key = function + +Variables +~~~~~~~~~ + +colors.*:: + Color variables can appoint colors of the output which is printed out
"customize" instead of "appoint"?
tools/perf/Documentation/perf-config.txt line 111
Quoted 1 line
tools/perf/Documentation/perf-config.txt new file +1
-0+ from ‘report’, ‘top’,’annotate’ on tui.
spaces after punctuation?
tools/perf/Documentation/perf-config.txt line 112
Quoted 1 line
tools/perf/Documentation/perf-config.txt new file +1
-0+ Color variables is composed of foreground and background
are
tools/perf/Documentation/perf-config.txt line 113
Quoted 1 line
tools/perf/Documentation/perf-config.txt new file +1
-0+ and should have two values for them. If you want to set as colors
If you want to keep the colors
tools/perf/Documentation/perf-config.txt line 114
Quoted 1 line
tools/perf/Documentation/perf-config.txt new file +1
-0+ of your terminal, you should use ‘default’ for color value.
for the color value.
tools/perf/Documentation/perf-config.txt line 115
Quoted 1 line
tools/perf/Documentation/perf-config.txt new file +1
-0+ The kind of color which can be used as below.
The color names that can be used are:
tools/perf/Documentation/perf-config.txt line 119
Quoted 4 lines
tools/perf/Documentation/perf-config.txt new file +4
-0+ red, green, default, black, blue, white, magenta, lightgray + + colors.top:: + ‘top’ means a overhead percentage which has more than 5%.
is
tools/perf/Documentation/perf-config.txt line 120
Quoted 1 line
tools/perf/Documentation/perf-config.txt new file +1
-0+ And values of it’s variable specify colors of percentage.
this
tools/perf/Documentation/perf-config.txt line 127
Quoted 7 lines
tools/perf/Documentation/perf-config.txt new file +7
-0+ Basic key values are foreground-color ’red’ and + background-color ’default’. + colors.medium:: + ‘medium’ means a overhead percentage which has more than 0.5%. + Default values are ’green’ and ’default’. + colors.normal:: + ‘normal’ means rest of overhead percentages
means the
tools/perf/Documentation/perf-config.txt line 131
Quoted 4 lines
tools/perf/Documentation/perf-config.txt new file +4
-0+ except ‘top’, ‘medium’, ‘selected’. + Default values are ’lightgray’ and ’default’. + colors.selected:: + This appoint colors for forcussed one of the output list
This selects the colors for the current entry in a list of entries
tools/perf/Documentation/perf-config.txt line 135
Quoted 4 lines
tools/perf/Documentation/perf-config.txt new file +4
-0+ from sub-commands (top,report,annotate). + Default values are ’white’ and ’lightgray’. + colors.code:: + Colors for a arrow and lines on jumping by assembly code
Colors for arroews and lines in jumps on assembly code listings
tools/perf/Documentation/perf-config.txt line 138
Quoted 3 lines
tools/perf/Documentation/perf-config.txt new file +3
-0+ such as ‘jns’,’jmp’,’jane’,etc. Default values are ‘blue’, ‘default’. + colors.addr:: + This appoint colors for addresses from a sub-command ’annotate’.
selects in 'annotate'.
tools/perf/Documentation/perf-config.txt line 146
Quoted 8 lines
tools/perf/Documentation/perf-config.txt new file +8
-0+ Default values are ‘magenta’, ‘default’. + colors.root:: + Colors for headers in the output of a sub-command ‘top’. + Default values are ‘white’, ‘blue’. + +tui.*:: + A boolean value that controls launching TUI browser for each subcommand. + By default, TUI is enabled if perf detects a needed library during build
the required library
tools/perf/Documentation/perf-config.txt line 150
Quoted 4 lines
tools/perf/Documentation/perf-config.txt new file +4
-0+ and this config option can control it. Available subcommands are 'top', + 'report' and 'annotate'. + +gtk.*::
Have to stop now,
- Arnaldo
Quoted 477 lines
tools/perf/Documentation/perf-config.txt new file +286
-0+ A boolean value that controls launching GTK+2 GUI browser for + each subcommand. By default, TUI is enabled if perf detects a + needed library during build and this config option can control + it. Available subcommands are 'top', 'report' and 'annotate'. + +buildid.*:: + buildid.dir:: + Each executable or shared library built with each program is assigned + a unique identification as build-id. The option means a path where + build-id information can be saved. + The default is $HOME/.debug + +annotate.*:: + There’re options which work with a ’annotate’ sub-command. + This Options is in control of addresses, jump function, source code + in lines of assembly code from a specific program. + + annotate.hide_src_code:: + If a program which is analyzed has source code of itself, + this option let ‘annotate’ print a list of assembly code with the source code. + For example, let’s see a part of a program. There’re four lines. + If this option is ‘false’, they can be printed + without source code from a program as below. + + │ push %rbp + │ mov %rsp,%rbp + │ sub $0x10,%rsp + │ mov (%rdi),%rdx + + But if this option is ‘true’, source code of the part + can be also printed as below. + + │ struct rb_node *rb_next(const struct rb_node *node) + │ { + │ push %rbp + │ mov %rsp,%rbp + │ sub $0x10,%rsp + │ struct rb_node *parent; + │ + │ if (RB_EMPTY_NODE(node)) + │ mov (%rdi),%rdx + │ return n; + + annotate.use_offset:: + Basing on a first address of a loaded function, offset can be used. + Instead of using original addresses of assembly code, + addresses subtracted from a base address can be printed. + Let’s illustrate a example. + If a base address is 0XFFFFFFFF81624d50 as below, + + ffffffff81624d50 <load0> + + a address on assembly code has a specific absolute address as below + + ffffffff816250b8:│ mov 0x8(%r14),%rdi + + but if use_offset is ’true’, a address subtracted from a base address is printed. + The default is true. + + 368:│ mov 0x8(%r14),%rdi + + annotate.jump_arrows:: + There’re jump instruction among assembly code. + Depending on a boolean value of jump_arrows, + arrows can be printed or not which represent + where do the instruction jump into as below. + + │ ┌──jmp 1333 + │ │ xchg %ax,%ax + │1330:│ mov %r15,%r10 + │1333:└─→cmp %r15,%r14 + + If jump_arrow is ‘false’, the arrows isn’t printed as below. + + │ ↓ jmp 1333 + │ xchg %ax,%ax + │1330: mov %r15,%r10 + │1333: cmp %r15,%r14 + + annotate.show_nr_jumps:: + Let’s see a part of assembly code. + + │1382: movb $0x1,-0x270(%rbp) + + If use this, the number of branches branching to that address can be printed as below. + + │1 1382: movb $0x1,-0x270(%rbp) + +help.*:: + help.format:: = man + A format of manual page can be ‘man’, ‘info’, ‘web’ or ‘html’. + ’man’ is default. + help.autocorrect:: = 0 + Automatically correct and execute mistyped commands after + waiting for the given number of deciseconds (0.1 sec). + Let's see a example. If a mistyped sub-command is executed like 'perf mistyped-command' + and this option is 0, the output is as below. + + perf: 'mistyped-command' is not a perf-command. See 'perf --help’. + + Or if this option is more than 1, the output can be such as. + + WARNING: You called a perf program named 'mistyped-command', which does not exist. + Continuing under the assumption that you meant 'with-kcore' + in 0.1 seconds automatically... + Usage: perf-with-kcore <perf sub-command> <perf.data directory> [<sub-command options> [ -- <workload>]] + <perf sub-command> can be record, script, report or inject + or: perf-with-kcore fix_buildid_cache_permissions + +hist.*:: + hist.percentage:: + This option control a way to calcurate overhead of filtered entries - + that means the value of this option is effective only if there's a + filter (by comm, dso or symbol name). Suppose a following example: + + Overhead Symbols + ........ ....... + 33.33% foo + 33.33% bar + 33.33% baz + + This is an original overhead and we'll filter out the first 'foo' + entry. The value of 'relative' would increase the overhead of 'bar' + and 'baz' to 50.00% for each, while 'absolute' would show their + current overhead (33.33%). + +ui.*:: + ui.show-headers:: + There’re columns as header ‘Overhead’, ‘Children’, ‘Shared Object’, ‘Symbol’, ’self’. + If this option is false, they are hiden. + +call-graph.*:: + When sub-commands ‘top’ and ‘report’ work with -g/—-children + there’re options in control of call-graph. + + call-graph.record-mode:: + The record-mode can be ‘fp’ (frame pointer) and ‘dwarf’. + The value of 'dwarf' is effective only if perf detect needed library + (libunwind or a recent version of libdw). Also it doesn't *require* + the dump-size option since it can use the default value of 8192 if + missing. + + call-graph.dump-size:: + The size of stack to dump in order to do post-unwinding. Default is 8192 (byte). + When using dwarf into record-mode this option should have a value. + + call-graph.print-type:: + The print-types can be graph (graph absolute), fractal (graph relative), flat. + This option controls a way to show overhead for each callchain entry. + Suppose a following example. + + Overhead Symbols + ........ ....... + 40.00% foo + | + --- foo + | + |--50.00%-- bar + | main + | + --50.00%-- baz + main + + This output is a default format which is 'fractal'. The 'foo' came + from 'bar' and 'baz' exactly half and half so 'fractal' shows 50.00% + for each (meaning that it assumes 100% total overhead of 'foo'). + + The 'graph' uses absolute overhead value of 'foo' as total so each of + 'bar' and 'baz' callchain will have 20.00% of overhead. + + call-graph.order:: + This option controls print order of callchains. The default is + 'callee' which means callee is printed at top and then followed by its + caller and so on. The 'caller' prints it in reverse order. + + call-graph.sort-key:: + The callchains are merged if they contain same information. + The sort-key option determines a way to compare the callchains. + A value of 'sort-key' can be 'function' or 'address’. + The default is ‘function’. + + call-graph.threshold:: + When there're many callchains it'd print tons of lines. So perf omits + small callchains under a certain overhead (threshold) and this option + control the threashold. Default is 0.5 (%). + + call-graph.print-limit:: + This is another way to control the number of callchains printed for a + single entry. Default is 0 which means no limitation. + +report.*:: + report.percent-limit:: + This one is mostly same as call-graph.threshold but works for + histogram entries. Entries have overhead lower than this percentage + will not be printed. Default is 0. + If percent-limit is 70, the output which has percentages of + each overhead above 70% can be printed. + + report.queue-size:: + option to setup the maximum allocation size for session's + ordered events queue, if not set there's no default limit + + report.children:: + The children means that functions called from another function. + If the option is true, accumulate callchain of children and show total overhead. + For example, there’re three functions like below. + + void foo(void) { + /* do something */ + } + + void bar(void) { + /* do something */ + foo(); + } + + int main(void) { + bar() + return 0; + } + + Defaultly the output of sub-commands such as ’top’, ‘report’ and ‘annotate’ + depend on a sort of overhead into each functions as below. + + Overhead Symbol + ........ ..................... + 60.00% foo + | + --- foo + bar + main + __libc_start_main + + 40.00% bar + | + --- bar + main + __libc_start_main + + But if this option is true, the sort is changed into a sort of + overhead into each children group of each function reciting all functions + from a first parent function till a last child function like below. + And it requires -g/--call-graph option enabled + + Children Self Symbol + ........ ........ .................... + 100.00% 0.00% __libc_start_main + | + --- __libc_start_main + + 100.00% 0.00% main + | + --- main + __libc_start_main + + 100.00% 40.00% bar + | + --- bar + main + __libc_start_main + + 60.00% 60.00% foo + | + --- foo + bar + main + __libc_start_main + +top.*:: + top.children:: + This option means same as report.children. + So it is true, the output of ‘top’ is rearranged by each overhead into children group. + +man.*:: + man.viewer:: + This option can assign a manual tool with which a subcommand 'help' work. + it can used as 'man', 'woman', 'konqueror'. Default value is 'man'. + +pager.*:: + pager.<subcommand>:: + When a subcommand work as stdio instead of TUI, use pager with it. + Default value is 'true'. + +SEE ALSO +-------- +linkperf:perf[1]tools/perf/Documentation/perfconfig.example +57
-11@@ -1,29 +1,75 @@ [colors] - - # These were the old defaults - top = red, lightgray - medium = green, lightgray - normal = black, lightgray - selected = lightgray, magenta - code = blue, lightgray - addr = magenta, lightgray + # There are types of colors which are red, + # green, default, black, blue, + # white, magenta, lightgray + # The default is like below + top = red, default + medium = green, default + normal = lightgray, default + selected = white, lightgray + code = blue, default + addr = magenta, default + root = white, blue [tui] - # Defaults if linked with libslang 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 + +[gtk] + report = off + annotate = off + #top = off + +[pager] + # That a 'cmd' is true mean to use "pager or less" + cmd = true + report = false + diff = true + +[help] + # Format can be man, info, web or html + format = man + autocorrect = 0 + +[hist] + # a value of 'percentage' can be 'relative' or 'absolute' + percentage = absolute + +[ui] + show-headers= true + +[call-graph] + # fp (framepointer), dwarf + record-mode = fp + + # graph (graph absolute), flat, fractal (graph relative) + print-type = fractal + + # caller, callee + order = caller + + # function, address + sort-key = function + +[report] + percent-limit = 1 + children = false + +[top] + children = true + +[man] + viewer = mantools/perf/builtin-config.c new file +56
-0@@ -0,0 +1,56 @@ +/* +* 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 struct { +bool list_action; +} params; + +static const char *const config_usage[] = { +"perf config [options]" , +NULL +}; +static const struct option config_options[] = { +OPT_GROUP ("Action" ), +OPT_BOOLEAN ('l' ,"list" , ¶ms.list_action,"show current config variables" ), +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 +printf ("%s\n" , key); + +return 0 ; +} + +int cmd_config (int argc,const char **argv,const char *prefix__maybe_unused ) +{ +int ret =0 ; + + argc =parse_options (argc, argv, config_options, config_usage, +PARSE_OPT_STOP_AT_NON_OPTION ); + +if (params.list_action && argc ==0 ) + ret =perf_config (show_config,NULL ); +else { +pr_warning ("Error: Unknown argument.\n" ); +usage_with_options (config_usage, config_options); + } + +return ret; +}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 commontools/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