perf config: Finally write changed configs on config file at a time
PATCH v2 2/4 perf config: Finally write changed configs on config file at a time
Currently set_config() can be repeatedly called for each input config on the below case:
$ perf config kmem.default=slab report.children=false ...
But it's a waste, so finally write changed configs at a time.
--- tools/perf/builtin-config.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
tools/perf/builtin-config.c +10 -5
@@ -33,8 +33,7 @@ static struct option config_options[] = { OPT_END() }; -static int set_config (struct perf_config_set *set,const char *file_name, -const char *var,const char *value) +static int set_config (struct perf_config_set *set,const char *file_name) {struct perf_config_section *section =NULL ;struct perf_config_item *item =NULL ;
@@ -48,7 +47,6 @@ static int set_config(struct perf_config_set *set, const char *file_name,if (!fp)return -1 ; -perf_config_set__collect (set, file_name, var, value);fprintf (fp,"%s\n" , first_line);/* overwrite configvariables */
@@ -160,6 +158,7 @@ int cmd_config(int argc, const char **argv)struct perf_config_set *set;char *user_config =mkpath ("%s/.perfconfig" ,getenv ("HOME" ));const char *config_filename; +bool changed = false; argc =parse_options (argc, argv, config_options, config_usage,PARSE_OPT_STOP_AT_NON_OPTION );
@@ -227,10 +226,16 @@ int cmd_config(int argc, const char **argv)if (value ==NULL ) ret =show_spec_config (set, var); -else - ret =set_config (set, config_filename, var, value); +else { +perf_config_set__collect (set, config_filename, + var, value); + changed = true; + }free (arg); } + +if (changed) + ret =set_config (set, config_filename); }perf_config_set__delete (set);
Signature · 1 line
2.7.4
Arnaldo Carvalho de Melo
maintainerEm Mon, May 08, 2017 at 08:07:40PM +0900, Taeung Song escreveu:
Quoted 50 lines
Currently
set_config()can be repeatedly called for each input config on the below case:$ perf config kmem.default=slab report.children=false ...But it's a waste, so finally write changed configs at a time.
Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Signed-off-by Taeung Song <[email protected]>--- tools/perf/builtin-config.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)tools/perf/builtin-config.c +2
-5@@ -33,8 +33,7 @@ static struct option config_options[] = { OPT_END() }; -static int set_config (struct perf_config_set *set,const char *file_name, -const char *var,const char *value) +static int set_config (struct perf_config_set *set,const char *file_name) {struct perf_config_section *section =NULL ;struct perf_config_item *item =NULL ;@@ -48,7 +47,6 @@ static int set_config(struct perf_config_set *set, const char *file_name,if (!fp)return -1 ; -perf_config_set__collect (set, file_name, var, value);fprintf (fp,"%s\n" , first_line);/* overwrite configvariables */ @@ -160,6 +158,7 @@ int cmd_config(int argc, const char **argv)struct perf_config_set *set;char *user_config =mkpath ("%s/.perfconfig" ,getenv ("HOME" ));const char *config_filename; +bool changed = false; argc =parse_options (argc, argv, config_options, config_usage,PARSE_OPT_STOP_AT_NON_OPTION );@@ -227,10 +226,16 @@ int cmd_config(int argc, const char **argv)if (value ==NULL ) ret =show_spec_config (set, var); -else - ret =set_config (set, config_filename, var, value);
tools/perf/builtin-config.c int cmd_config(int argc, const char **argv) · line 238
Quoted 10 lines
tools/perf/builtin-config.c +8
-0+else { +perf_config_set__collect (set, config_filename, + var, value); + changed = true; + }free (arg); } + +if (changed) + ret =set_config (set, config_filename);
Ok, this improves the situation, even fixing what seems like a bug, i.e. that ret variable set in the if (value == NULL) case is not being checked, the look just goes on to completion and whatever is the last value left in 'ret' is what will be returned by cmd_config()...
I think we should fix that bug first, making it exit the loop and perhaps show some error message, then do this 'call set_config()' only at the end', no?
I applied the first patch, the one just renesting things.
- Arnaldo
Quoted 5 lines
tools/perf/builtin-config.c +0
-0}perf_config_set__delete (set);Signature · 1 line
2.7.4
Quoted 67 lines · Arnaldo Carvalho de Melo
Em Mon, May 08, 2017 at 08:07:40PM +0900, Taeung Song escreveu:
Quoted 50 lines
Currently
set_config()can be repeatedly called for each input config on the below case:$ perf config kmem.default=slab report.children=false ...But it's a waste, so finally write changed configs at a time.
Cc Jiri Olsa <[email protected]>Cc Namhyung Kim <[email protected]>Signed-off-by Taeung Song <[email protected]>--- tools/perf/builtin-config.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)tools/perf/builtin-config.c +2
-5@@ -33,8 +33,7 @@ static struct option config_options[] = { OPT_END() }; -static int set_config (struct perf_config_set *set,const char *file_name, -const char *var,const char *value) +static int set_config (struct perf_config_set *set,const char *file_name) {struct perf_config_section *section =NULL ;struct perf_config_item *item =NULL ;@@ -48,7 +47,6 @@ static int set_config(struct perf_config_set *set, const char *file_name,if (!fp)return -1 ; -perf_config_set__collect (set, file_name, var, value);fprintf (fp,"%s\n" , first_line);/* overwrite configvariables */ @@ -160,6 +158,7 @@ int cmd_config(int argc, const char **argv)struct perf_config_set *set;char *user_config =mkpath ("%s/.perfconfig" ,getenv ("HOME" ));const char *config_filename; +bool changed = false; argc =parse_options (argc, argv, config_options, config_usage,PARSE_OPT_STOP_AT_NON_OPTION );@@ -227,10 +226,16 @@ int cmd_config(int argc, const char **argv)if (value ==NULL ) ret =show_spec_config (set, var); -else - ret =set_config (set, config_filename, var, value);tools/perf/builtin-config.c int cmd_config(int argc, const char **argv) · line 238
Quoted 10 lines
tools/perf/builtin-config.c +8
-0+else { +perf_config_set__collect (set, config_filename, + var, value); + changed = true; + }free (arg); } + +if (changed) + ret =set_config (set, config_filename);Ok, this improves the situation, even fixing what seems like a bug, i.e. that ret variable set in the if (value == NULL) case is not being checked, the look just goes on to completion and whatever is the last value left in 'ret' is what will be returned by
cmd_config()...
Quoted 3 lines
I think we should fix that bug first, making it exit the loop and perhaps show some error message, then do this 'call
set_config()' only at the end', no?
I understood !
will fix the bug you mentioned first,
before this patch.
Quoted 4 lines
I applied the first patch, the one just renesting things.
- Arnaldo
Thank you !,
Taeung
Quoted 6 lines
Quoted 6 lines
tools/perf/builtin-config.c +0
-1}perf_config_set__delete (set); --2.7.4