perf sort: Make setup_sorting returns an error code
authorNamhyung Kim <namhyung.kim@lge.com>
Wed, 6 Feb 2013 05:57:16 +0000 (14:57 +0900)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 6 Feb 2013 21:09:26 +0000 (18:09 -0300)
Currently the setup_sorting() is called for parsing sort keys and exits
if it failed to add the sort key.  As it's included in libperf it'd be
better returning an error code rather than exiting application inside of
the library.

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Suggested-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1360130237-9963-2-git-send-email-namhyung@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/builtin-annotate.c
tools/perf/builtin-diff.c
tools/perf/builtin-report.c
tools/perf/builtin-top.c
tools/perf/tests/hists_link.c
tools/perf/util/sort.c
tools/perf/util/sort.h

index dc870cf31b79beefa01c777680efb761c0ed3377..95a2ad3f043e5560deabd888c2c55d550f6ff5c2 100644 (file)
@@ -309,7 +309,8 @@ int cmd_annotate(int argc, const char **argv, const char *prefix __maybe_unused)
        if (symbol__init() < 0)
                return -1;
 
-       setup_sorting(annotate_usage, options);
+       if (setup_sorting() < 0)
+               usage_with_options(annotate_usage, options);
 
        if (argc) {
                /*
index 4af0b580b046e4f74191dee57946646adff4d306..d207a97a2db1e96887418f354961d947bfecb7c2 100644 (file)
@@ -605,7 +605,9 @@ int cmd_diff(int argc, const char **argv, const char *prefix __maybe_unused)
 
        ui_init();
 
-       setup_sorting(diff_usage, options);
+       if (setup_sorting() < 0)
+               usage_with_options(diff_usage, options);
+
        setup_pager();
 
        sort_entry__setup_elide(&sort_dso, symbol_conf.dso_list, "dso", NULL);
index 91555d4885f482127bebcd0238777c9a2f2050f8..96b5a7fee4bbe45a0f2558fb243e706ad65b8567 100644 (file)
@@ -751,7 +751,8 @@ repeat:
 
        }
 
-       setup_sorting(report_usage, options);
+       if (setup_sorting() < 0)
+               usage_with_options(report_usage, options);
 
        /*
         * Only in the newt browser we are doing integrated annotation,
index f561757b1bfa2d5bfbdf737ce7ec0f84f3ff7c11..72f6eb7b4173c86f84fcf3b001f6eb9ae1bdd8b4 100644 (file)
@@ -1129,7 +1129,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
        if (sort_order == default_sort_order)
                sort_order = "dso,symbol";
 
-       setup_sorting(top_usage, options);
+       if (setup_sorting() < 0)
+               usage_with_options(top_usage, options);
 
        if (top.use_stdio)
                use_browser = 0;
index 0afd9223bde7181284f27e95d926de9a6000a6ca..1be64a6c5dafbda094a075faeb1556abbeee0f9f 100644 (file)
@@ -449,7 +449,8 @@ int test__hists_link(void)
                goto out;
 
        /* default sort order (comm,dso,sym) will be used */
-       setup_sorting(NULL, NULL);
+       if (setup_sorting() < 0)
+               goto out;
 
        machines__init(&machines);
 
index 03cabe5678d0f157fbadb018d0391b9c54b08678..d8b48827a17ead2162e3551cec8738b3fb478320 100644 (file)
@@ -565,23 +565,25 @@ int sort_dimension__add(const char *tok)
        return -ESRCH;
 }
 
-void setup_sorting(const char * const usagestr[], const struct option *opts)
+int setup_sorting(void)
 {
        char *tmp, *tok, *str = strdup(sort_order);
+       int ret = 0;
 
        for (tok = strtok_r(str, ", ", &tmp);
                        tok; tok = strtok_r(NULL, ", ", &tmp)) {
-               int ret = sort_dimension__add(tok);
+               ret = sort_dimension__add(tok);
                if (ret == -EINVAL) {
                        error("Invalid --sort key: `%s'", tok);
-                       usage_with_options(usagestr, opts);
+                       break;
                } else if (ret == -ESRCH) {
                        error("Unknown --sort key: `%s'", tok);
-                       usage_with_options(usagestr, opts);
+                       break;
                }
        }
 
        free(str);
+       return ret;
 }
 
 void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list,
index e994ad3e989705bf8524492a9b2c88f3388c983f..b13e56f6ccbebf7aa03b25c6ffdf98357b78716b 100644 (file)
@@ -160,7 +160,7 @@ 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);
+int setup_sorting(void);
 extern int sort_dimension__add(const char *);
 void sort_entry__setup_elide(struct sort_entry *self, struct strlist *list,
                             const char *list_name, FILE *fp);