perf util: Remove setup_sorting dups
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 14 Dec 2009 22:09:29 +0000 (20:09 -0200)
committerIngo Molnar <mingo@elte.hu>
Tue, 15 Dec 2009 07:50:28 +0000 (08:50 +0100)
And it is also needed by 'perf diff'.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1260828571-3613-1-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
tools/perf/builtin-annotate.c
tools/perf/builtin-report.c
tools/perf/util/sort.c
tools/perf/util/sort.h

index fa833f50763eaf4ec53302a82bb66a70dd958fb0..2e2855a685c6579d663be57b6019f9c17cd0eed7 100644 (file)
@@ -521,21 +521,6 @@ static const struct option options[] = {
        OPT_END()
 };
 
-static void setup_sorting(void)
-{
-       char *tmp, *tok, *str = strdup(sort_order);
-
-       for (tok = strtok_r(str, ", ", &tmp);
-                       tok; tok = strtok_r(NULL, ", ", &tmp)) {
-               if (sort_dimension__add(tok) < 0) {
-                       error("Unknown --sort key: `%s'", tok);
-                       usage_with_options(annotate_usage, options);
-               }
-       }
-
-       free(str);
-}
-
 int cmd_annotate(int argc, const char **argv, const char *prefix __used)
 {
        if (symbol__init(&symbol_conf) < 0)
@@ -543,7 +528,7 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __used)
 
        argc = parse_options(argc, argv, options, annotate_usage, 0);
 
-       setup_sorting();
+       setup_sorting(annotate_usage, options);
 
        if (argc) {
                /*
index d12ea4ab0d21859a0a8c61eeffced573522d54ef..beff7c090d2bfe281c38a01ad5e1b9a2ffbc6a3a 100644 (file)
@@ -843,21 +843,6 @@ static const struct option options[] = {
        OPT_END()
 };
 
-static void setup_sorting(void)
-{
-       char *tmp, *tok, *str = strdup(sort_order);
-
-       for (tok = strtok_r(str, ", ", &tmp);
-                       tok; tok = strtok_r(NULL, ", ", &tmp)) {
-               if (sort_dimension__add(tok) < 0) {
-                       error("Unknown --sort key: `%s'", tok);
-                       usage_with_options(report_usage, options);
-               }
-       }
-
-       free(str);
-}
-
 static void setup_list(struct strlist **list, const char *list_str,
                       struct sort_entry *se, const char *list_name,
                       FILE *fp)
@@ -884,7 +869,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
 
        argc = parse_options(argc, argv, options, report_usage, 0);
 
-       setup_sorting();
+       setup_sorting(report_usage, options);
 
        if (parent_pattern != default_parent_pattern) {
                sort_dimension__add("parent");
index b490354d1b23d31e1d6a977c4801b2f34c97acea..cff1c316fa910648cc53328494c03a8b53809ea3 100644 (file)
@@ -288,3 +288,18 @@ int sort_dimension__add(const char *tok)
 
        return -ESRCH;
 }
+
+void setup_sorting(const char * const usagestr[], const struct option *opts)
+{
+       char *tmp, *tok, *str = strdup(sort_order);
+
+       for (tok = strtok_r(str, ", ", &tmp);
+                       tok; tok = strtok_r(NULL, ", ", &tmp)) {
+               if (sort_dimension__add(tok) < 0) {
+                       error("Unknown --sort key: `%s'", tok);
+                       usage_with_options(usagestr, opts);
+               }
+       }
+
+       free(str);
+}
index 333e664ff45fddfe9838f113dda25dc0a26c3860..cb6151c026f2e9da35ef4ca7080891f1830b33e1 100644 (file)
@@ -81,6 +81,8 @@ struct sort_entry {
 extern struct sort_entry sort_thread;
 extern struct list_head hist_entry__sort_list;
 
+void setup_sorting(const char * const usagestr[], const struct option *opts);
+
 extern int repsep_fprintf(FILE *fp, const char *fmt, ...);
 extern size_t sort__thread_print(FILE *, struct hist_entry *, unsigned int);
 extern size_t sort__comm_print(FILE *, struct hist_entry *, unsigned int);