[PATCH 4/4] perf tools: Add a option 'remove' to perf-config.
From: Taeung Song
Date: Mon Apr 27 2015 - 02:35:09 EST
A option 'remove' is to remove specific config variables.
For the syntax examples,
# perf config -r | --remove [section.subkey ...]
Signed-off-by: Taeung Song <treeze.taeung@xxxxxxxxx>
---
tools/perf/Documentation/perf-config.txt | 6 ++++
tools/perf/builtin-config.c | 48 +++++++++++++++++++++++---------
2 files changed, 41 insertions(+), 13 deletions(-)
diff --git a/tools/perf/Documentation/perf-config.txt b/tools/perf/Documentation/perf-config.txt
index 1c9027e..fb8ca74 100644
--- a/tools/perf/Documentation/perf-config.txt
+++ b/tools/perf/Documentation/perf-config.txt
@@ -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
------------------
diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index a67aea3..ff49c22 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -18,6 +18,7 @@ static struct {
bool get_action;
bool set_action;
bool all_action;
+ bool remove_action;
} params;
struct list_head *sections;
@@ -31,6 +32,7 @@ static const struct option config_options[] = {
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_BOOLEAN('r', "remove", ¶ms.remove_action, "remove specific variables: [section.subkey ...]"),
OPT_END()
};
@@ -150,19 +152,26 @@ static int set_config(const char *section_name, const char *subkey,
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 (!value) {
+ /* value == NULL means remove the variable */
+ if (section_node && element_node)
+ element_node->value = NULL;
+ else
+ pr_err("Error: Failed to find the variable.\n");
+ } else {
+ /* 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;;
}
- /* 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;
}
@@ -367,7 +376,20 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
ret = perf_config(show_config, NULL);
else if (params.all_action && argc == 0)
ret = show_all_config();
- else {
+ else if (params.remove_action) {
+ for (i = 0; argv[i]; i++) {
+ value = strrchr(argv[i], '=');
+ if (value == NULL || value == argv[0])
+ ret = perf_configset_with_option(set_spec_config, argv[i]);
+ else {
+ pr_err("invalid key: %s", argv[i]);
+ return -1;
+ }
+ if (ret < 0)
+ goto out;
+ }
+ } else {
+
pr_warning("Error: Unknown argument.\n");
usage_with_options(config_usage, config_options);
}
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/