Skip to contentSkip to conversation

perf config: Add several functionalities into perf-config

PATCH RESEND New Taeung Song 1 participant 9 messages Feb 25, 2016 perf events

lore
Share & tools
lore
#0 lore raw

v16 cover perf config: Add several functionalities into perf-config

Hello,

This patchset implements new functionalities for perf-config subcommand. Add options (list-all, skel, verbose, remove) and
getting and setting functionalities into perf-config subcommand to more useful.

Changes in v16:
- rebased onto the current tip/perf/core

Changes in v15:
- separate out perf-config documention from this patchset
- 'list' and 'list-all' options can also work with --verbose
- 'get' functionality can also work with --verbose

Changes in v14:
- change default value for report.group config [Namhyung]
- make a distinction between user and system config file name in error message when nothing configured
- bug fix, segmentation fault of '--skel' option
of which reason is that a variable wasn't initialized
- rename colors.code to colors.jump_arrows among config variables

Changes in v13:
- add record.build-id config info to perf-config doc [Namhyung]
- fill missing options info ('verbose', 'skel') on perf-config doc

Changes in v12:
- modify perf-config documentation for each section to be more proper and correct small typing errors [Namhyung]
- add missing config variables that are group, show_linenr and show_total_period [Namhyung]

Changes in v11:
- add --skel option to produce an skeleton with the possible config variables [Arnaldo]
- add exception handling to --list option when nothing configured [Arnaldo]
- default action without option is to show an usage message [Arnaldo]

Changes in v10:
- split perf-config.txt into several patches for each section and replace some paragraphes with better proper things [Arnaldo, Namhyung]
- correct wrong default values for each variable [Namhyung]
- remove the compare name function

Changes in v9:
- add the compare name functionality treating '-' and '-' as being the same thing for usability

Changes in v8:
- correct small typing errors in a perf-config documention
- split the collecting configs part into a separate patch
- use new enum and struct for default configs instead of hard-coded value [Namhyung]

Changes in v7:
- modify explanations of syntax and options(color, gtk, tui, buildid, annotate) to be better proper descriptions [Arnaldo]

Changes in v6:
- split a 'set' feature patch into two patch to separate normalize_value() from it
- bug fix : 'remove' and 'set' malfunctions when without a specific file-option (If file-option isn't used, 'remove' feature had to use both user and system config file and 'set' feature had to only handle user config file.)

Changes in v5:
- simplify the switch statement in cmd_config()
- set a config file path with '--system' or '--user' instead of '--global' or '--system' [Namhyung]
- the patch about 'get' and 'set 'split into two patchs [Namhyung]

Changes in v4:
- if some config value is default value, notice it is '(default)' [Jirka]
- if there wasn't any perfconfig file, perf-config malfunctioned so add exception routine with '--global' and '--system' option which can select perf config file path [Jirka]

Changes in v3:
- add a config variable 'kmem.default' with a default value [Namhyung]

Changes in v2:
- change option name of listing all configs as '--list-all'
instead of '--all' [Namhyung]
- correct small infelicities or typing errors in a perf-config documention [Arnaldo]
- declaration a global variable 'static struct default_configsets' has config variables with default values instead of using a 'util/PERFCONFIG-DEFAULT' file.
- add a function to normalize a value and check data type of it.
- simplify parsing arguments as arguments is just divided by '=' and then in front of '.' is a section, between '.' and '=' is a name,
and behind '=' is a value.
- if run perf-config command without any option, perf-config work as '--list'.

Taeung Song (8):
perf config: Collect configs to handle config variables perf config: Add 'list-all' option to perf-config perf config: Add a option 'skel' to perf-config
perf config: Add --verbose option for showing config description perf config: Add 'get' functionality
perf config: Add 'set' functionality
perf config: normalize a value depending on default type of it perf config: Add a option 'remove' to perf-config

 tools/perf/Documentation/perf-config.txt |  24 +
 tools/perf/builtin-config.c              | 723 ++++++++++++++++++++++++++++++-
 tools/perf/util/cache.h                  |  17 +
 tools/perf/util/config.c                 |  27 +-
 4 files changed, 777 insertions(+), 14 deletions(-)
Signature · 1 line
2.5.0
#1 lore raw

PATCH RESEND v16 1/8 perf config: Collect configs to handle config variables

Collecting configs into list because of two reason.

First of all, if there are same variables both user and system config file, they all will be printed when 'list' command work. But if config variables are duplicated, user config variables should only be printed because it has priority.

Lastly, list into which configs is collected will be required to keep and handle config variables and values in the near furture. For example, getting or setting functionality.

And change show_config() function.
Old show_config() worked depending on perf_config(). New show_config() work using collected configs list.

Cc Namhyung Kim <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/builtin-config.c | 150 ++++++++++++++++++++++++++++++++++++++++++--
 tools/perf/util/cache.h     |  13 ++++
 2 files changed, 158 insertions(+), 5 deletions(-)
tools/perf/builtin-config.c +145 -5
index c42448e..c43234e 100644
@@ -32,13 +32,148 @@ static struct option config_options[] = {
 	OPT_END()
 };
 
-static int show_config(const char *key, const char *value,
-		       void *cb __maybe_unused)
+static struct config_section *find_section(struct list_head *sections,
+					   const char *section_name)
 {
+	struct config_section *section;
+
+	list_for_each_entry(section, sections, list)
+		if (!strcmp(section->name, section_name))
+			return section;
+
+	return NULL;
+}
+
+static struct config_element *find_element(const char *name,
+					   struct config_section *section)
+{
+	struct config_element *element;
+
+	list_for_each_entry(element, &section->element_head, list)
+		if (!strcmp(element->name, name))
+			return element;
+
+	return NULL;
+}
+
+static void find_config(struct list_head *sections,
+			struct config_section **section,
+			struct config_element **element,
+			const char *section_name, const char *name)
+{
+	*section = find_section(sections, section_name);
+
+	if (*section != NULL)
+		*element = find_element(name, *section);
+	else
+		*element = NULL;
+}
+
+static struct config_section *init_section(const char *section_name)
+{
+	struct config_section *section;
+
+	section = zalloc(sizeof(*section));
+	if (!section)
+		return NULL;
+
+	INIT_LIST_HEAD(&section->element_head);
+	section->name = strdup(section_name);
+	if (!section->name) {
+		pr_err("%s: strdup failed\n", __func__);
+		free(section);
+		return NULL;
+	}
+
+	return section;
+}
+
+static int add_element(struct list_head *head,
+			      const char *name, const char *value)
+{
+	struct config_element *element;
+
+	element = zalloc(sizeof(*element));
+	if (!element)
+		return -1;
+
+	element->name = strdup(name);
+	if (!element->name) {
+		pr_err("%s: strdup failed\n", __func__);
+		free(element);
+		return -1;
+	}
 	if (value)
-		printf("%s=%s\n", key, value);
+		element->value = (char *)value;
 	else
-		printf("%s\n", key);
+		element->value = NULL;
+
+	list_add_tail(&element->list, head);
+	return 0;
+}
+
+static int collect_current_config(const char *var, const char *value,
+				  void *spec_sections)
+{
+	int ret = -1;
+	char *ptr, *key;
+	char *section_name, *name;
+	struct config_section *section = NULL;
+	struct config_element *element = NULL;
+	struct list_head *sections = (struct list_head *)spec_sections;
+
+	key = ptr = strdup(var);
+	if (!key) {
+		pr_err("%s: strdup failed\n", __func__);
+		return -1;
+	}
+
+	section_name = strsep(&ptr, ".");
+	name = ptr;
+	if (name == NULL || value == NULL)
+		goto out_err;
+
+	find_config(sections, &section, &element, section_name, name);
+
+	if (!section) {
+		section = init_section(section_name);
+		if (!section)
+			goto out_err;
+		list_add_tail(&section->list, sections);
+	}
+
+	value = strdup(value);
+	if (!value) {
+		pr_err("%s: strdup failed\n", __func__);
+		goto out_err;
+	}
+
+	if (!element)
+		add_element(&section->element_head, name, value);
+	else {
+		free(element->value);
+		element->value = (char *)value;
+	}
+
+	ret = 0;
+out_err:
+	free(key);
+	return ret;
+}
+
+static int show_config(struct list_head *sections)
+{
+	struct config_section *section;
+	struct config_element *element;
+
+	if (list_empty(sections))
+		return -1;
+	list_for_each_entry(section, sections, list) {
+		list_for_each_entry(element, &section->element_head, list) {
+			printf("%s.%s=%s\n", section->name,
+				       element->name, element->value);
+		}
+	}
 
 	return 0;
 }
@@ -46,6 +181,7 @@ static int show_config(const char *key, const char *value,
 int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 {
 	int ret = 0;
+	struct list_head sections;
 	char *user_config = mkpath("%s/.perfconfig", getenv("HOME"));
 
 	argc = parse_options(argc, argv, config_options, config_usage,
@@ -58,18 +194,22 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 		return -1;
 	}
 
+	INIT_LIST_HEAD(&sections);
+
 	if (use_system_config)
 		config_exclusive_filename = perf_etc_perfconfig();
 	else if (use_user_config)
 		config_exclusive_filename = user_config;
 
+	perf_config(collect_current_config, &sections);
+
 	switch (actions) {
 	case ACTION_LIST:
 		if (argc) {
 			pr_err("Error: takes no arguments\n");
 			parse_options_usage(config_usage, config_options, "l", 1);
 		} else {
-			ret = perf_config(show_config, NULL);
+			ret = show_config(&sections);
 			if (ret < 0) {
 				const char * config_filename = config_exclusive_filename;
 				if (!config_exclusive_filename)
tools/perf/util/cache.h +13 -0
index 3ca453f..92cd739 100644
@@ -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"
@@ -23,6 +24,18 @@
 #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
 #define PERF_PAGER_ENVIRONMENT "PERF_PAGER"
 
+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;
+};
+
 extern const char *config_exclusive_filename;
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
Signature · 1 line
2.5.0
#2 lore raw

PATCH RESEND v16 2/8 perf config: Add 'list-all' option to perf-config

In reply to Taeung Song

'list-all' option is to display both current config variables and all possible config variables with default values. The syntax examples are like below

perf config [<file-option>] [options]

display all perf config with default values.
# perf config -a | --list-all

Cc Namhyung Kim <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/Documentation/perf-config.txt |   6 +
 tools/perf/builtin-config.c              | 231 ++++++++++++++++++++++++++++++-
 2 files changed, 235 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-config.txt +6 -0
index 15949e2..d9fb8c3 100644
@@ -9,6 +9,8 @@ SYNOPSIS
 --------
 [verse]
 'perf config' [<file-option>] -l | --list
+or
+'perf config' [<file-option>] -a | --list-all
 
 DESCRIPTION
 -----------
@@ -29,6 +31,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 +229 -2

268 lines not on this page · raw message

Signature · 1 line
2.5.0
#3 lore raw

PATCH RESEND v16 3/8 perf config: Add a option 'skel' to perf-config

In reply to Taeung Song

Produce an skeleton with the possible config variables so that one could then use $EDITOR ~/.perfconfig or $(sysconfdir)/perfconfigand go on setting the knobs.

For the syntax examples,

    # perf config -k | --skel
    Initialize the possible config variables on config file.
    # perf config --skel > ~/.perfconfig
Cc Namhyung Kim <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/Documentation/perf-config.txt |  6 ++++++
 tools/perf/builtin-config.c              | 32 +++++++++++++++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-config.txt +6 -0
index d9fb8c3..964879a 100644
@@ -11,6 +11,8 @@ SYNOPSIS
 'perf config' [<file-option>] -l | --list
 or
 'perf config' [<file-option>] -a | --list-all
+or
+'perf config' [<file-option>] -k | --skel
 
 DESCRIPTION
 -----------
@@ -35,6 +37,10 @@ OPTIONS
 --list-all::
 	Show current and all possible config variables with default values.
 
+-k::
+--skel::
+	Produce an skeleton with the possible config variables.
+
 CONFIGURATION FILE
 ------------------
 
tools/perf/builtin-config.c +31 -1
index 8a63119..6ab53b2 100644
@@ -22,7 +22,8 @@ static const char * const config_usage[] = {
 
 enum actions {
 	ACTION_LIST = 1,
-	ACTION_LIST_ALL
+	ACTION_LIST_ALL,
+	ACTION_SKEL
 } actions;
 
 static struct option config_options[] = {
@@ -31,6 +32,9 @@ static struct option config_options[] = {
 	OPT_SET_UINT('a', "list-all", &actions,
 		     "show current and all possible config"
 		     " variables with default values", ACTION_LIST_ALL),
+	OPT_SET_UINT('k', "skel", &actions,
+		     "produce an skeleton with the possible"
+		     " config variables", ACTION_SKEL),
 	OPT_BOOLEAN(0, "system", &use_system_config, "use system config file"),
 	OPT_BOOLEAN(0, "user", &use_user_config, "use user config file"),
 	OPT_END()
@@ -282,6 +286,26 @@ static char *get_value(struct config_item *config)
 	return value;
 }
 
+static int show_skel_config(void)
+{
+	int i;
+	const char *section = "";
+
+	for (i = 0; default_configs[i].type != CONFIG_END; i++) {
+		struct config_item *config = &default_configs[i];
+		char *value = get_value(config);
+
+		if (strcmp(section, config->section) != 0) {
+			section = config->section;
+			printf("\n[%s]\n", config->section);
+		}
+		printf("\t%s = %s\n", config->name, value);
+		free(value);
+	}
+
+	return 0;
+}
+
 static int show_all_config(struct list_head *sections)
 {
 	int i;
@@ -422,6 +446,12 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 	perf_config(collect_current_config, &sections);
 
 	switch (actions) {
+	case ACTION_SKEL:
+		if (argc)
+			parse_options_usage(config_usage, config_options, "k", 1);
+		else
+			ret = show_skel_config();
+		break;
 	case ACTION_LIST_ALL:
 		if (argc == 0) {
 			ret = show_all_config(&sections);
Signature · 1 line
2.5.0
#4 lore raw

PATCH RESEND v16 4/8 perf config: Add --verbose option for showing config description

In reply to Taeung Song

To explain what each of variable options configures, this option can be used with 'skel', 'list' and 'list-all' options, i.e.

    print the possible config variables with comments over each of them.
    # perf config -vk | --verbose --skel
    or
    print all or current config variables with descriptions
    # perf config -vl | --verbose --list
    # perf config -va | --verbose --list-all
Cc Namhyung Kim <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/Documentation/perf-config.txt |   4 +
 tools/perf/builtin-config.c              | 186 +++++++++++++++++++++----------
 2 files changed, 130 insertions(+), 60 deletions(-)
tools/perf/Documentation/perf-config.txt +4 -0
index 964879a..1da577f 100644
@@ -41,6 +41,10 @@ OPTIONS
 --skel::
 	Produce an skeleton with the possible config variables.
 
+-v::
+--verbose::
+	Be more verbose. (show config description)
+
 CONFIGURATION FILE
 ------------------
 
tools/perf/builtin-config.c +126 -60

227 lines not on this page · raw message

Signature · 1 line
2.5.0
#5 lore raw

PATCH RESEND v16 5/8 perf config: Add 'get' functionality

In reply to Taeung Song

This patch consists of functions
which can get specific config variables.
For the syntax examples,

perf config [<file-option>] [section.name ...]

display key-value pairs of specific config variables # perf config report.queue-size report.children

In addition, the functionality can work with --verbose option to show the config description, i.e.

    # perf config -v report.queue-size
Cc Namhyung Kim <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/Documentation/perf-config.txt |  2 +
 tools/perf/builtin-config.c              | 87 ++++++++++++++++++++++++++++++--
 tools/perf/util/cache.h                  |  1 +
 3 files changed, 86 insertions(+), 4 deletions(-)
tools/perf/Documentation/perf-config.txt +2 -0
index 1da577f..f83e9de 100644
@@ -8,6 +8,8 @@ perf-config - Get and set variables in a configuration file.
 SYNOPSIS
 --------
 [verse]
+'perf config' [<file-option>] [section.name ...]
+or
 'perf config' [<file-option>] -l | --list
 or
 'perf config' [<file-option>] -a | --list-all
tools/perf/builtin-config.c +83 -4

123 lines not on this page · raw message

tools/perf/util/cache.h +1 -0
index 92cd739..d5dcc85 100644
@@ -39,6 +39,7 @@ struct config_section {
 extern const char *config_exclusive_filename;
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
+typedef int (*configset_fn_t)(struct list_head *, const char *, const char *);
 extern int perf_default_config(const char *, const char *, void *);
 extern int perf_config(config_fn_t fn, void *);
 extern int perf_config_int(const char *, const char *);
Signature · 1 line
2.5.0
#6 lore raw

PATCH RESEND v16 6/8 perf config: Add 'set' functionality

In reply to Taeung Song

This patch consists of functions which can set specific config variables. For the syntax examples,

perf config [<file-option>] [options] [section.name[=value] ...]

set specific config variables
# perf config report.queue-size=100M report.children=true

Cc Namhyung Kim <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/Documentation/perf-config.txt |   2 +-
 tools/perf/builtin-config.c              | 122 +++++++++++++++++++++++++------
 tools/perf/util/cache.h                  |   5 +-
 tools/perf/util/config.c                 |  27 ++++++-
 4 files changed, 131 insertions(+), 25 deletions(-)
tools/perf/Documentation/perf-config.txt +1 -1
index f83e9de..52fdb4b 100644
@@ -8,7 +8,7 @@ perf-config - Get and set variables in a configuration file.
 SYNOPSIS
 --------
 [verse]
-'perf config' [<file-option>] [section.name ...]
+'perf config' [<file-option>] [section.name[=value] ...]
 or
 'perf config' [<file-option>] -l | --list
 or
tools/perf/builtin-config.c +100 -22

191 lines not on this page · raw message

tools/perf/util/cache.h +4 -1
index d5dcc85..9614afd 100644
@@ -39,9 +39,12 @@ struct config_section {
 extern const char *config_exclusive_filename;
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
-typedef int (*configset_fn_t)(struct list_head *, const char *, const char *);
+typedef int (*configset_fn_t)(struct list_head *, const char *,
+			      const char *, const char *, char *);
+extern int perf_configset_write_in_full(struct list_head *sections, const char *file_name);
 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 +26 -1
index 4e72763..34eff22 100644
@@ -416,7 +416,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");
@@ -506,6 +506,31 @@ out:
 	return ret;
 }
 
+int perf_configset_write_in_full(struct list_head *sections, const char *file_name)
+{
+	struct config_section *section;
+	struct config_element *element;
+	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, sections, list) {
+		fprintf(fp, "[%s]\n", section->name);
+		list_for_each_entry(element, &section->element_head, list) {
+			if (element->value)
+				fprintf(fp, "\t%s = %s\n",
+					element->name, element->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
2.5.0
#7 lore raw

PATCH RESEND v16 7/8 perf config: normalize a value depending on default type of it

In reply to Taeung Song

Whether or not user mis-type wrong data type to set config, normalize the value. If a config user enter isn't contained in default configs, just pass as it is.
For the examples,

   # perf config report.queue-size=1M
   # perf config report.queue-size
   report.queue-size=1048576
Cc Namhyung Kim <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/builtin-config.c | 54 ++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 49 insertions(+), 5 deletions(-)
tools/perf/builtin-config.c +49 -5
index d2587c5..bad8182 100644
@@ -444,6 +444,54 @@ static int show_spec_config(struct list_head *sections,
 	return -1;
 }
 
+static char *normalize_value(const char *section_name, const char *name, const char *value)
+{
+	int i, ret = 0;
+	char *endptr;
+	char key[BUFSIZ];
+	char *normalized;
+
+	scnprintf(key, sizeof(key), "%s.%s", section_name, name);
+	for (i = 0; default_configs[i].type != CONFIG_END; i++) {
+		struct config_item *config = &default_configs[i];
+
+		if (!strcmp(config->section, section_name) &&
+		    !strcmp(config->name, name)) {
+			if (config->type == CONFIG_TYPE_BOOL)
+				ret = asprintf(&normalized, "%s",
+					       perf_config_bool(key, value) ? "true" : "false");
+			else if (config->type == CONFIG_TYPE_INT ||
+				 config->type == CONFIG_TYPE_LONG)
+				ret = asprintf(&normalized, "%d",
+					       perf_config_int(key, value));
+			else if (config->type == CONFIG_TYPE_U64)
+				ret = asprintf(&normalized, "%"PRId64,
+					       perf_config_u64(key, value));
+			else if (config->type == CONFIG_TYPE_FLOAT)
+				ret = asprintf(&normalized, "%f",
+					       strtof(value, &endptr));
+			else if (config->type == CONFIG_TYPE_DOUBLE)
+				ret = asprintf(&normalized, "%f",
+					       strtod(value, &endptr));
+			else
+				ret = asprintf(&normalized, "%s", value);
+
+			if (ret < 0)
+				return NULL;
+
+			return normalized;
+		}
+	}
+
+	normalized = strdup(value);
+	if (!normalized) {
+		pr_err("%s: strdup failed\n", __func__);
+		return NULL;
+	}
+
+	return normalized;
+}
+
 static int set_config(struct list_head *sections, const char *config_file_name,
 		      const char *section_name, const char *name, char *value)
 {
@@ -452,11 +500,7 @@ static int set_config(struct list_head *sections, const char *config_file_name,
 
 	find_config(sections, &section, &element, section_name, name);
 	if (value != NULL) {
-		value = strdup(value);
-		if (!value) {
-			pr_err("%s: strdup failed\n", __func__);
-			return -1;
-		}
+		value = normalize_value(section_name, name, value);
 
 		/* if there isn't existent section, add a new section */
 		if (!section) {
Signature · 1 line
2.5.0
#8 lore raw

PATCH RESEND v16 8/8 perf config: Add a option 'remove' to perf-config

In reply to Taeung Song

A option 'remove' is to remove specific config variables. For the syntax examples,

    # perf config [<file-option>] -r | --remove [section.name ...]
Cc Namhyung Kim <[email protected]>
Cc Jiri Olsa <[email protected]>
---
 tools/perf/Documentation/perf-config.txt |  6 ++++++
 tools/perf/builtin-config.c              | 37 ++++++++++++++++++++++++++++++--
 2 files changed, 41 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-config.txt +6 -0
index 52fdb4b..89c1ceb 100644
@@ -15,6 +15,8 @@ or
 'perf config' [<file-option>] -a | --list-all
 or
 'perf config' [<file-option>] -k | --skel
+or
+'perf config' [<file-option>] -r | --remove [section.name ...]
 
 DESCRIPTION
 -----------
@@ -47,6 +49,10 @@ OPTIONS
 --verbose::
 	Be more verbose. (show config description)
 
+-r::
+--remove::
+	Remove specific config variables.
+
 CONFIGURATION FILE
 ------------------
 
tools/perf/builtin-config.c +35 -2
index bad8182..7ba842c 100644
@@ -23,7 +23,8 @@ static const char * const config_usage[] = {
 enum actions {
 	ACTION_LIST = 1,
 	ACTION_LIST_ALL,
-	ACTION_SKEL
+	ACTION_SKEL,
+	ACTION_REMOVE
 } actions;
 
 static struct option config_options[] = {
@@ -35,6 +36,8 @@ static struct option config_options[] = {
 	OPT_SET_UINT('k', "skel", &actions,
 		     "produce an skeleton with the possible"
 		     " config variables", ACTION_SKEL),
+	OPT_SET_UINT('r', "remove", &actions,
+		     "remove specific variables: [section.name ...]", ACTION_REMOVE),
 	OPT_INCR('v', "verbose", &verbose, "Be more verbose"
 		 " (show config description)"),
 	OPT_BOOLEAN(0, "system", &use_system_config, "use system config file"),
@@ -499,7 +502,13 @@ static int set_config(struct list_head *sections, const char *config_file_name,
 	struct config_element *element = NULL;
 
 	find_config(sections, &section, &element, section_name, name);
-	if (value != NULL) {
+	if (!value) {
+		/* value == NULL means remove the variable */
+		if (section && element) {
+			free(element->value);
+			element->value = NULL;
+		}
+	} else {
 		value = normalize_value(section_name, name, value);
 
 		/* if there isn't existent section, add a new section */
@@ -663,6 +672,7 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 
 	set_option_flag(config_options, 'l', "list", PARSE_OPT_EXCLUSIVE);
 	set_option_flag(config_options, 'a', "list-all", PARSE_OPT_EXCLUSIVE);
+	set_option_flag(config_options, 'r', "remove", PARSE_OPT_EXCLUSIVE);
 
 	argc = parse_options(argc, argv, config_options, config_usage,
 			     PARSE_OPT_STOP_AT_NON_OPTION);
@@ -692,6 +702,29 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 	}
 
 	switch (actions) {
+	case ACTION_REMOVE:
+		if (argc) {
+			for (i = 0; argv[i]; i++) {
+				if (!use_system_config && !use_user_config) {
+					ret = perf_configset_with_option(set_config,
+									 &system_sections,
+									 system_config,
+									 argv[i], NULL);
+					ret = perf_configset_with_option(set_config,
+									 &user_sections,
+									 user_config,
+									 argv[i], NULL);
+				} else
+					ret = perf_configset_with_option(set_config, sections,
+									 config_exclusive_filename,
+									 argv[i], NULL);
+			}
+		} else {
+			pr_err("Error: Missing arguments\n");
+			parse_options_usage(config_usage, config_options, "r", 1);
+			return -1;
+		}
+		break;
 	case ACTION_SKEL:
 		if (argc)
 			parse_options_usage(config_usage, config_options, "k", 1);
Signature · 1 line
2.5.0