mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Taeung Song <treeze.taeung@gmail.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: linux-kernel@vger.kernel.org, jolsa@redhat.com,
	namhyung@kernel.org, Taeung Song <treeze.taeung@gmail.com>
Subject: [PATCH 4/4] perf tools: Add a option 'remove' to perf-config.
Date: Mon, 27 Apr 2015 15:34:26 +0900	[thread overview]
Message-ID: <1430116466-14427-4-git-send-email-treeze.taeung@gmail.com> (raw)
In-Reply-To: <1430116466-14427-1-git-send-email-treeze.taeung@gmail.com>

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@gmail.com>
---
 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", &params.list_action, "show current config variables"),
 	OPT_BOOLEAN('a', "all", &params.all_action,
 		    "show current and all possible config variables with default values"),
+	OPT_BOOLEAN('r', "remove", &params.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(&section_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(&section_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(&section_node->list, sections);
+		}
+		/* if nothing to replace, add a new element which contains key-value pair. */
+		if (!element_node)
+			return add_config_element(&section_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(&section_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


  parent reply	other threads:[~2015-04-27  6:35 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-27  6:34 [PATCH 1/4] perf tools: Add 'perf-config' command Taeung Song
2015-04-27  6:34 ` [PATCH 2/4] perf tools: Add functions which can get or set perf config variables Taeung Song
2015-05-04  8:41   ` Jiri Olsa
2015-05-04 19:16   ` Jiri Olsa
2015-05-11  2:15     ` taeung
2015-04-27  6:34 ` [PATCH 3/4] perf tools: Add a option 'all' to perf-config Taeung Song
2015-05-04  8:56   ` Jiri Olsa
2015-05-04 19:16   ` Jiri Olsa
2015-05-04 19:16   ` Jiri Olsa
2015-05-04 19:16   ` Jiri Olsa
2015-04-27  6:34 ` Taeung Song [this message]
2015-04-27 22:17 ` [PATCH 1/4] perf tools: Add 'perf-config' command Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1430116466-14427-4-git-send-email-treeze.taeung@gmail.com \
    --to=treeze.taeung@gmail.com \
    --cc=acme@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®