Skip to contentSkip to conversation

perf tools: Add 'perf-config' command

PATCH In review Taeung Song 2 participants 7 messages Apr 12, 2015 – Apr 19, 2015 3 messages not in the archive perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 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 '--all' option and a document for it.

---
 tools/perf/Build                            |   1 +
 tools/perf/Documentation/perf-config.txt    | 433 ++++++++++++++++++++++++++++
 tools/perf/Documentation/perfconfig.example |  65 ++++-
 tools/perf/builtin-config.c                 |  71 +++++
 tools/perf/builtin.h                        |   1 +
 tools/perf/command-list.txt                 |   1 +
 tools/perf/perf.c                           |   1 +
 7 files changed, 562 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
index b77370e..3c1f437 100644
@@ -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 +433 -0

433 lines not on this page · raw message

tools/perf/Documentation/perfconfig.example +54 -11

83 lines not on this page · raw message

tools/perf/builtin-config.c new file +71 -0

71 lines not on this page · raw message

tools/perf/builtin.h +1 -0
index 3688ad2..3f871b5 100644
@@ -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
index 00fcaf8..acc3ea7 100644
@@ -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
index b857fcb..604fa4a 100644
@@ -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
#1 lore raw

PATCH 2/2 perf tools: Add a option 'remove' to perf-config and features which get or set a config variable.

This patch consists of adding functions which get, set or remove a specific config variable. For the syntax examples,

perf config [options] [section.subkey[=value]]

display a specific key(section.subkey) and value

   # perf config report.queue

set a specific key and value

   # perf config report.queue=100M

remove a specific key

   # perf config -r | --remove report.queue
---
 tools/perf/Documentation/perf-config.txt |   8 ++
 tools/perf/builtin-config.c              | 224 ++++++++++++++++++++++++++++++-
 tools/perf/util/cache.h                  |  17 +++
 tools/perf/util/config.c                 |  35 ++++-
 4 files changed, 278 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-config.txt +8 -0
index b251702..7354b18 100644
@@ -8,7 +8,11 @@ perf-config - Get and set variables in configuration file.
 SYNOPSIS
 --------
 [verse]
+'perf config' section.subkey[=value]
+or
 'perf config' -a | --all
+or
+'perf config' -r | --remove section.subkey
 
 DESCRIPTION
 -----------
@@ -21,6 +25,10 @@ OPTIONS
 --all::
 	Show all variables with key and value into each sections.
 
+-r::
+--remove::
+	Remove a specific variable.
+
 CONFIGURATION FILE
 ------------------
 
tools/perf/builtin-config.c +221 -3

264 lines not on this page · raw message

tools/perf/util/cache.h +17 -0
index fbcca21..17b271f 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"
@@ -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)(struct config_section *, struct config_element *);
+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 +32 -3
index e18f653..ffcbe96 100644
@@ -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,36 @@ out:
 	return ret;
 }
 
+int perf_configset_write_in_full(void)
+{
+	struct config_section *section_node;
+	struct config_element *element_node;
+	char section[BUFSIZ];
+	char key_value_pair[BUFSIZ];
+	const char *first_line = "# this file is auto-generated.\n";
+	FILE *f = fopen(config_file_name, "w");
+
+	if (!f)
+		return -1;
+
+	fwrite(first_line, strlen(first_line), 1, f);
+	/* overwrite configvariables */
+	list_for_each_entry(section_node, &sections, list) {
+		sprintf(section, "[%s]\n", section_node->name);
+		fwrite(section, strlen(section), 1, f);
+		list_for_each_entry(element_node, &section_node->element_head, list) {
+			if (element_node->value) {
+				sprintf(key_value_pair, "\t%s = %s\n"
+					, element_node->subkey, element_node->value);
+				fwrite(key_value_pair, strlen(key_value_pair), 1, f);
+			}
+		}
+	}
+	fclose(f);
+
+	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
maintainer
#2 lore raw

Re: [PATCH 2/2] perf tools: Add a option 'remove' to perf-config and features which get or set a config variable.

Quoted 28 lines · Taeung Song

This patch consists of adding functions which get, set or remove a specific config variable. For the syntax examples,

perf config [options] [section.subkey[=value]]

display a specific key(section.subkey) and value

   # perf config report.queue

set a specific key and value

   # perf config report.queue=100M

remove a specific key

   # perf config -r | --remove report.queue
---
 tools/perf/Documentation/perf-config.txt |   8 ++
 tools/perf/builtin-config.c              | 224 ++++++++++++++++++++++++++++++-
 tools/perf/util/cache.h                  |  17 +++
 tools/perf/util/config.c                 |  35 ++++-
 4 files changed, 278 insertions(+), 6 deletions(-)
tools/perf/Documentation/perf-config.txt +0 -0
index b251702..7354b18 100644

tools/perf/Documentation/perf-config.txt perf-config - Get and set variables in configuration file. · line 15

Quoted 8 lines
tools/perf/Documentation/perf-config.txt +4 -0
@@ -8,7 +8,11 @@ perf-config - Get and set variables in configuration file.
 SYNOPSIS
 --------
 [verse]
+'perf config' section.subkey[=value]
+or
 'perf config' -a | --all
+or
+'perf config' -r | --remove section.subkey

I'd like to suggest to split -r option handling into a separate patch.

Quoted 21 lines
tools/perf/Documentation/perf-config.txt +4 -0
 DESCRIPTION
 -----------
@@ -21,6 +25,10 @@ OPTIONS
 --all::
 	Show all variables with key and value into each sections.
 
+-r::
+--remove::
+	Remove a specific variable.
+
 CONFIGURATION FILE
 ------------------
 
tools/perf/builtin-config.c +0 -0
index 7cf6d03..205e053 100644
@@ -15,15 +15,24 @@
 
 static struct {

tools/perf/builtin-config.c line 26

Quoted 10 lines
tools/perf/builtin-config.c +7 -0
 	bool all_action;
+	bool get_action;
+	bool set_action;
+	bool remove_action;
 } params;
 
+LIST_HEAD(sections);
+static char *given_section_name;
+static char *given_subkey;
+static char *given_value;

Why this given_* variables are needed? I think they can be passed simply via function arguments?

Quoted 14 lines
tools/perf/builtin-config.c +3 -1
+
 static const char * const config_usage[] = {
-	"perf config [options]",
+	"perf config [options] [section.subkey[=value]]",
 	NULL
 };
 static const struct option config_options[] = {
 	OPT_GROUP("Action"),
 	OPT_BOOLEAN('a', "all", &params.all_action, "print all configurations"),
+	OPT_BOOLEAN('r', "remove", &params.remove_action, "remove a variable: section.subkey"),
 	OPT_END()
 };
 

tools/perf/builtin-config.c static void check_argc(int argc, int limit) · line 49

Quoted 6 lines
tools/perf/builtin-config.c +3 -0
@@ -35,6 +44,72 @@ static void check_argc(int argc, int limit)
 	usage_with_options(config_usage, config_options);
 }
 
+static struct config_section *find_config_section(const char *section_name)
+{
+	struct config_section *section_node;

It'd be better to split declaration and function body with a blank line.

Quoted 20 lines
tools/perf/builtin-config.c +20 -0
+	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, &section_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)

tools/perf/builtin-config.c static void check_argc(int argc, int limit) · line 79

Quoted 10 lines
tools/perf/builtin-config.c +10 -0
+{
+	struct config_section *section_node;
+	LIST_HEAD(element_head);
+
+	section_node = zalloc(sizeof(*section_node));
+	if (!section_node)
+		return NULL;
+
+	INIT_LIST_HEAD(&section_node->element_head);
+	list_splice(&element_head, &section_node->element_head);

I don't see why this additional element_head is needed?

Quoted 6 lines
tools/perf/builtin-config.c +6 -0
+	section_node->name = strdup(section_name);
+	if (!section_node->name) {
+		pr_err("%s: strdup failed\n", __func__);
+		return NULL;
+	}
+

tools/perf/builtin-config.c static void check_argc(int argc, int limit) · line 95

Quoted 10 lines
tools/perf/builtin-config.c +10 -0
+	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) {

You need to free all previously allocated memory (i.e. the element_node).

tools/perf/builtin-config.c static void check_argc(int argc, int limit) · line 101

Quoted 6 lines
tools/perf/builtin-config.c +6 -0
+		pr_err("%s: strdup failed\n", __func__);
+		return -1;
+	}
+	if (value) {
+		element_node->value = strdup(value);
+		if (!element_node->value) {

Ditto.

Quoted 15 lines
tools/perf/builtin-config.c +11 -0
+			pr_err("%s: strdup failed\n", __func__);
+			return -1;
+		}
+	} else
+		element_node->value = NULL;
+
+	list_add_tail(&element_node->list, head);
+
+	return 0;
+}
+
 static int show_config(const char *key, const char *value,
 			   void *cb __maybe_unused)
 {

tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 130

Quoted 10 lines
tools/perf/builtin-config.c +7 -0
@@ -46,22 +121,165 @@ static int show_config(const char *key, const char *value,
 	return 0;
 }
 
+static int show_spec_config(struct config_section *section_node
+			    , struct config_element *element_node)
+{
+	char key[BUFSIZ];
+
+	if (section_node && element_node) {
+		sprintf(key, "%s.%s", section_node->name, element_node->subkey);

Please use scnprintf() instead of sprintf().

Quoted 57 lines
tools/perf/builtin-config.c +57 -0
+		show_config(key, element_node->value, NULL);
+	} else
+		pr_err("Error: Failed to find the variable.\n");
+
+	return 0;
+}
+
+static int set_config(struct config_section *section_node, struct config_element *element_node)
+{
+	if (!given_value) {
+		/* value == NULL means remove the variable */
+		if (section_node && element_node)
+			element_node->value = NULL;
+		else /* do nothing */
+			return 0;
+	} else {
+		/* if there isn't existent section, add a new section */
+		if (!section_node) {
+			section_node = init_config_section(given_section_name);
+			if (!section_node)
+				return -1;
+			list_add_tail(&section_node->list, &sections);
+		}
+		/* if nothing to replace, add a new element which contains key-value pair. */
+		if (!element_node)
+			add_config_element(&section_node->element_head, given_subkey, given_value);
+		else
+			element_node->value = given_value;
+	}
+
+	perf_configset_write_in_full();
+
+	return 0;
+}
+
+static int collect_config(const char *var, const char *value
+			  , void *cb __maybe_unused)
+{
+	struct config_section *section_node;
+	char *section_name, *subkey;
+	char *key = strdup(var);
+
+	if (!key) {
+		pr_err("%s: strdup failed\n", __func__);
+		return -1;
+	}
+	section_name = strsep(&key, ".");
+	subkey = strsep(&key, ".");
+	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(&section_node->list, &sections);
+	}
+

tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 197

Quoted 10 lines
tools/perf/builtin-config.c +10 -0
+	add_config_element(&section_node->element_head, subkey, value);
+
+	return 0;
+}
+
+static int perf_configset_with_option(configset_fn_t fn, const char *var)
+{
+	struct config_section *section_node = NULL;
+	struct config_element *element_node = NULL;
+	char *key = strdup(var);

Need to check return value here.

Quoted 5 lines
tools/perf/builtin-config.c +5 -0
+	const char *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.
+	 */

tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 212

Quoted 10 lines
tools/perf/builtin-config.c +10 -0
+	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;
+	}
+
+	given_value = strrchr(key, '=');

I think it should be strchr so that it can find first '=' character instead of the last one in case the given_value contains the '=' like env variables.

Quoted 14 lines
tools/perf/builtin-config.c +14 -0
+	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 (strsep(&key, ".") != NULL)
+		return -1;
+	if (given_value)

tools/perf/builtin-config.c static int show_config(const char *key, const char *value, · line 236

Quoted 10 lines
tools/perf/builtin-config.c +10 -0
+		given_subkey = strsep(&given_subkey, "=");
+
+	perf_config(collect_config, NULL);
+
+	section_node = find_config_section(given_section_name);
+
+	if (section_node != NULL)
+		element_node = find_config_element(given_subkey, section_node);
+
+	fn(section_node, element_node);

Here, given_section, subkey and value can be passed.

Quoted 124 lines
tools/perf/builtin-config.c +32 -2
+
+	return 0;
+}
+
 int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 {
 	int 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 (argc > 0) {
+	if (origin_argc > argc)
+		is_option = true;
+	else
+		is_option = false;
+
+	if (!is_option && argc > 0) {
 		if (strcmp(argv[0], "-") == 0) {
 			pr_warning("  Error: '-' is not supported.\n");
 			usage_with_options(config_usage, config_options);
 		}
+
+		switch (argc) {
+		case 1:
+			value = strrchr(argv[0], '=');
+			if (value == NULL || value == argv[0])
+				params.get_action = true;
+			else
+				params.set_action = true;
+			break;
+		default:
+			break;
+		}
 	}
 
-	if (argc == 0 || params.all_action) {
+	if ((!is_option && argc == 0) || params.all_action) {
 		check_argc(argc, 0);
 		ret = perf_config(show_config, NULL);
+	} else if (params.get_action) {
+		check_argc(argc, 1);
+		ret = perf_configset_with_option(show_spec_config, argv[0]);
+	} else if (params.set_action || params.remove_action) {
+		check_argc(argc, 1);
+		ret = perf_configset_with_option(set_config, argv[0]);
 	} else {
 		pr_warning("Error: Unknown argument.\n");
 		usage_with_options(config_usage, config_options);
tools/perf/util/cache.h +17 -0
index fbcca21..17b271f 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"
@@ -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)(struct config_section *, struct config_element *);
+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 +9 -3
index e18f653..ffcbe96 100644
@@ -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,36 @@ out:
 	return ret;
 }
 
+int perf_configset_write_in_full(void)
+{
+	struct config_section *section_node;
+	struct config_element *element_node;
+	char section[BUFSIZ];
+	char key_value_pair[BUFSIZ];
+	const char *first_line = "# this file is auto-generated.\n";

tools/perf/util/config.c out: · line 520

Quoted 10 lines
tools/perf/util/config.c +10 -0
+	FILE *f = fopen(config_file_name, "w");
+
+	if (!f)
+		return -1;
+
+	fwrite(first_line, strlen(first_line), 1, f);
+	/* overwrite configvariables */
+	list_for_each_entry(section_node, &sections, list) {
+		sprintf(section, "[%s]\n", section_node->name);
+		fwrite(section, strlen(section), 1, f);

Why not calling fprintf() directly?

tools/perf/util/config.c out: · line 525

Quoted 5 lines
tools/perf/util/config.c +5 -0
+		list_for_each_entry(element_node, &section_node->element_head, list) {
+			if (element_node->value) {
+				sprintf(key_value_pair, "\t%s = %s\n"
+					, element_node->subkey, element_node->value);
+				fwrite(key_value_pair, strlen(key_value_pair), 1, f);

Ditto..

Thanks,
Namhyung

Quoted 19 lines
tools/perf/util/config.c +8 -0
+			}
+		}
+	}
+	fclose(f);
+
+	return 0;
+}
+
 /*
  * Call this to report error for your variable that should not
  * get a boolean value (i.e. "[my] var" means "true").
Signature · 7 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#4 lore raw

Re: [PATCH 2/2] perf tools: Add a option 'remove' to perf-config and features which get or set a config variable.

Quoted 18 lines · Taewoong Song
Quoted 8 lines · Namhyung Kim

tools/perf/builtin-config.c static void check_argc(int argc, int limit) · line 49

Quoted 3 lines · Taeung Song
tools/perf/builtin-config.c +3 -0
+static struct config_section *find_config_section(const char *section_name)
+{
+	struct config_section *section_node;

It'd be better to split declaration and function body with a blank line.

Does mean it like followed by ?

tools/perf/builtin-config.c +4 -0
+static struct config_section *find_config_section(const char *section_name)
+
+{
+	struct config_section *section_node;

,or is it ?

tools/perf/builtin-config.c static void check_argc(int argc, int limit) · line 71

Quoted 4 lines
tools/perf/builtin-config.c +4 -0
+static struct config_section *find_config_section(const char *section_name)
+{
+
+	struct config_section *section_node;

Nope! I meant

static struct config_section *find_config_section(const char *section_name)

{
	struct config_section *section node
								<-- here
	list_for_each_entry(section_node, &sections, list)
		...
}
Quoted 11 lines
Quoted 11 lines

tools/perf/builtin-config.c static void check_argc(int argc, int limit) · line 58

Quoted 11 lines
tools/perf/builtin-config.c +9 -0
+	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)

And this is not how we put comma, please change it to

static struct config_element *find_config_element(const char *subkey,
struct config_section *section_node)

Ditto for others..

Thanks,
Namhyung

maintainer
#5 lore raw
In reply to Taeung Song

Hi Taeung,

Quoted 8 lines · Taeung Song

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 '--all' option and a document for it.

---

Thanks for your work!

I think the documentation updates need to be shared with tools manpages, or at least they can point to this document for details. This can be further work though. ;-)

[SNIP]

Quoted 32 lines
tools/perf/builtin-config.c new file +26 -0
new file mode 100644
index 0000000..7cf6d03
@@ -0,0 +1,71 @@
+/*
+ * 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 all_action;
+} params;
+
+static const char * const config_usage[] = {
+	"perf config [options]",
+	NULL
+};
+static const struct option config_options[] = {
+	OPT_GROUP("Action"),
+	OPT_BOOLEAN('a', "all", &params.all_action, "print all configurations"),

tools/perf/builtin-config.c line 36

Quoted 10 lines
tools/perf/builtin-config.c new file +10 -0
+	OPT_END()
+};
+
+static void check_argc(int argc, int limit)
+{
+	if (argc >= limit && argc <= limit)
+		return;
+	error("wrong number of arguments");
+	usage_with_options(config_usage, config_options);
+}

I don't know why this is needed. The -a option won't need this and we can support to get/set any number of config items IMHO.

Quoted 11 lines
tools/perf/builtin-config.c new file +11 -0
+
+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;
+}

tools/perf/builtin-config.c line 57

Quoted 10 lines
tools/perf/builtin-config.c new file +10 -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 (argc > 0) {
+		if (strcmp(argv[0], "-") == 0) {
+			pr_warning("  Error: '-' is not supported.\n");

I don't understand this. Why is the "-" so special?

And I think current behavior don't allow any argument. So what about this?

	argc = parse_options(...);
	if (argc)
		usage_with_options(...);

	if (params.all_action)
		...

tools/perf/builtin-config.c line 64

Quoted 7 lines
tools/perf/builtin-config.c new file +7 -0
+			usage_with_options(config_usage, config_options);
+		}
+	}
+
+	if (argc == 0 || params.all_action) {
+		check_argc(argc, 0);
+		ret = perf_config(show_config, NULL);

But doesn't it just print currently set items in a config file? I guess -a/--all option should show this *AND* all possible config items with default values. Current behavior can be done by -l/--list option like git-config..

Thanks,
Namhyung

Quoted 51 lines
tools/perf/builtin-config.c new file +7 -0
+	} else {
+		pr_warning("Error: Unknown argument.\n");
+		usage_with_options(config_usage, config_options);
+	}
+
+	return ret;
+}
tools/perf/builtin.h +1 -0
index 3688ad2..3f871b5 100644
@@ -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
index 00fcaf8..acc3ea7 100644
@@ -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
index b857fcb..604fa4a 100644
@@ -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 · 7 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#7 lore raw

Hi Taeung,

Quoted 21 lines · Taewoong Song

Hi, Namhyung

Thanks for your review and advices :)
There is a question which may be weird, followed by

Quoted 16 lines · Namhyung Kim

Hi Taeung,

Quoted 8 lines · Taeung Song

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 '--all' option and a document for it.

Signed-off-by Taeung Song <[email protected] <mailto:[email protected]>>

---

Thanks for your work!

Quoted 7 lines
Quoted 4 lines

I think the documentation updates need to be shared with tools manpages, or at least they can point to this document for details. This can be further work though. ;-)

Sorry I don’t understand this share very well. How can I share the documentation with tools manpages ?

I mean you can add a description for some feature to link the config document or vice versa. Many of those description can be added to the tool manpage or cross-reference config option at least.

For example, I sent a patch for children overhead documentation so you can just add 'see perf-report(1) for more details' into the description of the config option instead of repeating the whole contents. Or use asciidoc's 'include' macro to include the (part of) doc directly if possible.

Quoted 3 lines

And are there people who can help the document to be modified with more detail info ? Are they contributors for doc ?

Unfortunately, very few people donated their time to improve the documentation until now.

Thanks,
Namhyung

A message that is not in the archive (sent off-list or not yet received): [email protected]

maintainer
#9 lore raw
Quoted 29 lines · Taewoong Song
Quoted 13 lines · Namhyung Kim

tools/perf/builtin-config.c line 36

Quoted 7 lines · Taeung Song
tools/perf/builtin-config.c new file +7 -0
+static void check_argc(int argc, int limit)
+{
+	if (argc >= limit && argc <= limit)
+		return;
+	error("wrong number of arguments");
+	usage_with_options(config_usage, config_options);
+}

I don't know why this is needed. The -a option won't need this and we can support to get/set any number of config items IMHO.

I also think we can support to get/set any number of config items. But I think that ‘—list’ or ‘—all’ can need to be checked to validate argument. If work ‘git —list’ with other argument, error message can be printed like this.

:> git config --list 134
error: wrong number of arguments
usage: git config [options]

Config file location
--global use global config file
--system use system config file
--local use repository config file
-f, --file <file> use given config file --blob <blob-id> read config from given blob object

Quoted 6 lines

…(omitted)…

If don’t checking number of argument, we allow users to work a optio ‘-a’ or ‘-l’ with other arguments which can be weor meaningless. Did I misunderstand what you say?
Or is there other way to avoid this problem ?

Then just check 'argc != 0' for -l or -a cases. The get/set won't need it IMHO.

Thanks,
Namhyung