Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1417372

[PATCH v8 5/5] perf config: Reimplement show_config() using perf_config_set__iter()

From Taeung Song <treeze.taeung@gmail.com>
Newsgroups linux.kernel
Subject [PATCH v8 5/5] perf config: Reimplement show_config() using perf_config_set__iter()
Date 2016-06-08 14:40 +0200
Message-ID <rHKW7-7x-43@gated-at.bofh.it> (permalink)
References <rHKW5-7x-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Old show_config() directly use config set so
there are many duplicated code with perf_config_set__iter().

So reimplement show_config() using perf_config() that use
perf_config_set__iter() with config set that already
contains all configs.

Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Wang Nan <wangnan0@huawei.com>
Signed-off-by: Taeung Song <treeze.taeung@gmail.com>
---
 tools/perf/builtin-config.c | 29 +++++++----------------------
 tools/perf/util/config.c    |  2 +-
 tools/perf/util/config.h    |  1 +
 3 files changed, 9 insertions(+), 23 deletions(-)

diff --git a/tools/perf/builtin-config.c b/tools/perf/builtin-config.c
index c07f744..9c654f9 100644
--- a/tools/perf/builtin-config.c
+++ b/tools/perf/builtin-config.c
@@ -33,28 +33,13 @@ static struct option config_options[] = {
 	OPT_END()
 };
 
-static int show_config(struct perf_config_set *set)
+static int show_config(const char *key, const char *value,
+		       void *cb __maybe_unused)
 {
-	struct perf_config_section *section;
-	struct perf_config_item *item;
-	struct list_head *sections;
-
-	if (set == NULL)
-		return -1;
-
-	sections = &set->sections;
-	if (list_empty(sections))
-		return -1;
-
-	list_for_each_entry(section, sections, node) {
-		list_for_each_entry(item, &section->items, node) {
-			char *value = item->value;
-
-			if (value)
-				printf("%s.%s=%s\n", section->name,
-				       item->name, value);
-		}
-	}
+	if (value)
+		printf("%s=%s\n", key, value);
+	else
+		printf("%s\n", key);
 
 	return 0;
 }
@@ -96,7 +81,7 @@ int cmd_config(int argc, const char **argv, const char *prefix __maybe_unused)
 			pr_err("Error: takes no arguments\n");
 			parse_options_usage(config_usage, config_options, "l", 1);
 		} else {
-			ret = show_config(set);
+			ret = perf_config_set__iter(set, show_config, NULL);
 			if (ret < 0) {
 				const char * config_filename = config_exclusive_filename;
 				if (!config_exclusive_filename)
diff --git a/tools/perf/util/config.c b/tools/perf/util/config.c
index 23fb8e4..4775d18 100644
--- a/tools/perf/util/config.c
+++ b/tools/perf/util/config.c
@@ -662,7 +662,7 @@ struct perf_config_set *perf_config_set__new(void)
 	return set;
 }
 
-static int perf_config_set__iter(struct perf_config_set *set, config_fn_t fn, void *data)
+int perf_config_set__iter(struct perf_config_set *set, config_fn_t fn, void *data)
 {
 	struct perf_config_section *section;
 	struct perf_config_item *item;
diff --git a/tools/perf/util/config.h b/tools/perf/util/config.h
index fafba86..3526bb7 100644
--- a/tools/perf/util/config.h
+++ b/tools/perf/util/config.h
@@ -35,5 +35,6 @@ const char *perf_etc_perfconfig(void);
 
 struct perf_config_set *perf_config_set__new(void);
 void perf_config_set__delete(struct perf_config_set **set);
+int perf_config_set__iter(struct perf_config_set *set, config_fn_t fn, void *data);
 
 #endif /* __PERF_CONFIG_H */
-- 
2.5.0

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

[RFC][PATCH v8 0/5] perf config: Reimplement perf_config() using perf_config_set__inter() Taeung Song <treeze.taeung@gmail.com> - 2016-06-08 14:40 +0200
  [BUGFIX][PATCH v8 1/5] perf config: Handle the error about NULL at perf_config_set__delete() Taeung Song <treeze.taeung@gmail.com> - 2016-06-08 14:40 +0200
  [PATCH v8 2/5] perf config: Bring declarations about config from util/cache.h to util/config.h Taeung Song <treeze.taeung@gmail.com> - 2016-06-08 14:40 +0200
    Re: [PATCH v8 2/5] perf config: Bring declarations about config from  util/cache.h to util/config.h Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-09 15:40 +0200
      Re: [PATCH v8 2/5] perf config: Bring declarations about config from  util/cache.h to util/config.h Taeung Song <treeze.taeung@gmail.com> - 2016-06-10 08:30 +0200
        Re: [PATCH v8 2/5] perf config: Bring declarations about config from  util/cache.h to util/config.h Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-10 21:10 +0200
          Re: [PATCH v8 2/5] perf config: Bring declarations about config from  util/cache.h to util/config.h Taeung Song <treeze.taeung@gmail.com> - 2016-06-11 03:00 +0200
  [PATCH v8 3/5] perf config: Reimplement perf_config() using perf_config_set__iter() Taeung Song <treeze.taeung@gmail.com> - 2016-06-08 14:40 +0200
    Re: [PATCH v8 3/5] perf config: Reimplement perf_config() using  perf_config_set__iter() Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-09 15:40 +0200
      Re: [PATCH v8 3/5] perf config: Reimplement perf_config() using  perf_config_set__iter() Taeung Song <treeze.taeung@gmail.com> - 2016-06-10 13:00 +0200
    Re: [PATCH v8 3/5] perf config: Reimplement perf_config() using  perf_config_set__iter() Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-06-09 15:50 +0200
      Re: [PATCH v8 3/5] perf config: Reimplement perf_config() using  perf_config_set__iter() Taeung Song <treeze.taeung@gmail.com> - 2016-06-10 13:10 +0200
  [PATCH v8 5/5] perf config: Reimplement show_config() using perf_config_set__iter() Taeung Song <treeze.taeung@gmail.com> - 2016-06-08 14:40 +0200

csiph-web