perf tools: Propagate perf_config() errors
authorArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 24 Jan 2017 16:44:10 +0000 (13:44 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 27 Jan 2017 15:23:33 +0000 (12:23 -0300)
Previously these were being ignored, sometimes silently.

Stop doing that, emitting debug messages and handling the errors.

Testing it:

  $ cat ~/.perfconfig
  cat: /home/acme/.perfconfig: No such file or directory
  $ perf stat -e cycles usleep 1

   Performance counter stats for 'usleep 1':

           938,996      cycles:u

       0.003813731 seconds time elapsed

  $ perf top --stdio
  Error:
  You may not have permission to collect system-wide stats.

  Consider tweaking /proc/sys/kernel/perf_event_paranoid,
  <SNIP>
  [ perf record: Captured and wrote 0.019 MB perf.data (7 samples) ]
  [acme@jouet linux]$ perf report --stdio
  # To display the perf.data header info, please use --header/--header-only options.
  # Overhead  Command  Shared Object      Symbol
  # ........  .......  .................  .........................
    71.77%  usleep   libc-2.24.so       [.] _dl_addr
    27.07%  usleep   ld-2.24.so         [.] _dl_next_ld_env_entry
     1.13%  usleep   [kernel.kallsyms]  [k] page_fault
  $
  $ touch ~/.perfconfig
  $ ls -la ~/.perfconfig
  -rw-rw-r--. 1 acme acme 0 Jan 27 12:14 /home/acme/.perfconfig
  $
  $ perf stat -e instructions usleep 1

   Performance counter stats for 'usleep 1':

           244,610      instructions:u

       0.000805383 seconds time elapsed

  $
  [root@jouet ~]# chown acme.acme ~/.perfconfig
  [root@jouet ~]# perf stat -e cycles usleep 1
    Warning: File /root/.perfconfig not owned by current user or root, ignoring it.

   Performance counter stats for 'usleep 1':

           937,615      cycles

       0.000836931 seconds time elapsed
  #

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-j2rq96so6xdqlr8p8rd6a3jx@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
12 files changed:
tools/perf/builtin-help.c
tools/perf/builtin-kmem.c
tools/perf/builtin-record.c
tools/perf/builtin-report.c
tools/perf/builtin-top.c
tools/perf/perf.c
tools/perf/util/callchain.c
tools/perf/util/config.c
tools/perf/util/data-convert-bt.c
tools/perf/util/hist.c
tools/perf/util/intel-pt.c
tools/perf/util/llvm-utils.c

index 93da24a638befc75e1a06ece1cdb93c6a0fa9131..aed0d844e8c271426137abf3b622362913de2340 100644 (file)
@@ -447,11 +447,13 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
                NULL
        };
        const char *alias;
-       int rc = 0;
+       int rc;
 
        load_command_list("perf-", &main_cmds, &other_cmds);
 
-       perf_config(perf_help_config, &help_format);
+       rc = perf_config(perf_help_config, &help_format);
+       if (rc)
+               return rc;
 
        argc = parse_options_subcommand(argc, argv, builtin_help_options,
                        builtin_help_subcommands, builtin_help_usage, 0);
index 915869e00d863af03ca409f0f9ffa98147c45385..29f4751a357431ed5b8144e3375876c18aa3cc37 100644 (file)
@@ -1920,10 +1920,12 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
                NULL
        };
        struct perf_session *session;
-       int ret = -1;
        const char errmsg[] = "No %s allocation events found.  Have you run 'perf kmem record --%s'?\n";
+       int ret = perf_config(kmem_config, NULL);
+
+       if (ret)
+               return ret;
 
-       perf_config(kmem_config, NULL);
        argc = parse_options_subcommand(argc, argv, kmem_options,
                                        kmem_subcommands, kmem_usage, 0);
 
@@ -1948,6 +1950,8 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
        if (session == NULL)
                return -1;
 
+       ret = -1;
+
        if (kmem_slab) {
                if (!perf_evlist__find_tracepoint_by_name(session->evlist,
                                                          "kmem:kmalloc")) {
index 33a9eaaf9db49463374762d259b36e5854806bf9..ffac8ca9fb01e3974c8e57a4b1ca248810ff4597 100644 (file)
@@ -1670,7 +1670,9 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
        if (rec->evlist == NULL)
                return -ENOMEM;
 
-       perf_config(perf_record_config, rec);
+       err = perf_config(perf_record_config, rec);
+       if (err)
+               return err;
 
        argc = parse_options(argc, argv, record_options, record_usage,
                            PARSE_OPT_STOP_AT_NON_OPTION);
index 06cc759a459758472fc73925222b3eadd28aeee0..dbd7fa0288616e3c29003d9de62e8a62bf068051 100644 (file)
@@ -847,7 +847,9 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
        if (ret < 0)
                return ret;
 
-       perf_config(report__config, &report);
+       ret = perf_config(report__config, &report);
+       if (ret)
+               return ret;
 
        argc = parse_options(argc, argv, options, report_usage, 0);
        if (argc) {
index 3df4178ba378167aa6988f8b5a19f470e1607eb0..20aef9815cd89a3ad89e99683114dbacc4099019 100644 (file)
@@ -1216,7 +1216,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
        if (top.evlist == NULL)
                return -ENOMEM;
 
-       perf_config(perf_top_config, &top);
+       status = perf_config(perf_top_config, &top);
+       if (status)
+               return status;
 
        argc = parse_options(argc, argv, options, top_usage, 0);
        if (argc)
index 34bcf90f887102cdfa2f0a1a12b7ef2a8eba4c03..6d5479e03e0dbc080531f3037d5fe5a6644bc3c9 100644 (file)
@@ -90,11 +90,12 @@ static int pager_command_config(const char *var, const char *value, void *data)
 /* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
 int check_pager_config(const char *cmd)
 {
+       int err;
        struct pager_config c;
        c.cmd = cmd;
        c.val = -1;
-       perf_config(pager_command_config, &c);
-       return c.val;
+       err = perf_config(pager_command_config, &c);
+       return err ?: c.val;
 }
 
 static int browser_command_config(const char *var, const char *value, void *data)
@@ -113,11 +114,12 @@ static int browser_command_config(const char *var, const char *value, void *data
  */
 static int check_browser_config(const char *cmd)
 {
+       int err;
        struct pager_config c;
        c.cmd = cmd;
        c.val = -1;
-       perf_config(browser_command_config, &c);
-       return c.val;
+       err = perf_config(browser_command_config, &c);
+       return err ?: c.val;
 }
 
 static void commit_pager_choice(void)
@@ -509,6 +511,7 @@ static void cache_line_size(int *cacheline_sizep)
 
 int main(int argc, const char **argv)
 {
+       int err;
        const char *cmd;
        char sbuf[STRERR_BUFSIZE];
        int value;
@@ -534,7 +537,9 @@ int main(int argc, const char **argv)
        srandom(time(NULL));
 
        perf_config__init();
-       perf_config(perf_default_config, NULL);
+       err = perf_config(perf_default_config, NULL);
+       if (err)
+               return err;
        set_buildid_dir(NULL);
 
        /* get debugfs/tracefs mount point from /proc/mounts */
index 42922512c1c62fe09eb12f301c281ceb57c2bf3c..e16db30dfe405e535ad18b6908b2c6a93518cc7e 100644 (file)
@@ -48,6 +48,8 @@ static int parse_callchain_mode(const char *value)
                callchain_param.mode = CHAIN_FOLDED;
                return 0;
        }
+
+       pr_err("Invalid callchain mode: %s\n", value);
        return -1;
 }
 
@@ -63,6 +65,8 @@ static int parse_callchain_order(const char *value)
                callchain_param.order_set = true;
                return 0;
        }
+
+       pr_err("Invalid callchain order: %s\n", value);
        return -1;
 }
 
@@ -80,6 +84,8 @@ static int parse_callchain_sort_key(const char *value)
                callchain_param.branch_callstack = 1;
                return 0;
        }
+
+       pr_err("Invalid callchain sort key: %s\n", value);
        return -1;
 }
 
@@ -97,6 +103,8 @@ static int parse_callchain_value(const char *value)
                callchain_param.value = CCVAL_COUNT;
                return 0;
        }
+
+       pr_err("Invalid callchain config key: %s\n", value);
        return -1;
 }
 
@@ -210,13 +218,17 @@ int perf_callchain_config(const char *var, const char *value)
                return parse_callchain_sort_key(value);
        if (!strcmp(var, "threshold")) {
                callchain_param.min_percent = strtod(value, &endptr);
-               if (value == endptr)
+               if (value == endptr) {
+                       pr_err("Invalid callchain threshold: %s\n", value);
                        return -1;
+               }
        }
        if (!strcmp(var, "print-limit")) {
                callchain_param.print_limit = strtod(value, &endptr);
-               if (value == endptr)
+               if (value == endptr) {
+                       pr_err("Invalid callchain print limit: %s\n", value);
                        return -1;
+               }
        }
 
        return 0;
index 615e8b4a693ba1f99ab9f6cf16fc4c213aee0ed9..0c7d5a4975cd4a8f798533cbd15660c058652d37 100644 (file)
@@ -386,8 +386,10 @@ static int perf_buildid_config(const char *var, const char *value)
        if (!strcmp(var, "buildid.dir")) {
                const char *dir = perf_config_dirname(var, value);
 
-               if (!dir)
+               if (!dir) {
+                       pr_err("Invalid buildid directory!\n");
                        return -1;
+               }
                strncpy(buildid_dir, dir, MAXPATHLEN-1);
                buildid_dir[MAXPATHLEN-1] = '\0';
        }
@@ -405,10 +407,9 @@ static int perf_default_core_config(const char *var __maybe_unused,
 static int perf_ui_config(const char *var, const char *value)
 {
        /* Add other config variables here. */
-       if (!strcmp(var, "ui.show-headers")) {
+       if (!strcmp(var, "ui.show-headers"))
                symbol_conf.show_hist_headers = perf_config_bool(var, value);
-               return 0;
-       }
+
        return 0;
 }
 
index 7123f4de32ccbc4beb835260b25a9ca08df789f1..4e6cbc99f08efc608c2d73ffb9054672d25fb7d9 100644 (file)
@@ -1473,7 +1473,7 @@ int bt_convert__perf2ctf(const char *input, const char *path,
                },
        };
        struct ctf_writer *cw = &c.writer;
-       int err = -1;
+       int err;
 
        if (opts->all) {
                c.tool.comm = process_comm_event;
@@ -1481,12 +1481,15 @@ int bt_convert__perf2ctf(const char *input, const char *path,
                c.tool.fork = process_fork_event;
        }
 
-       perf_config(convert__config, &c);
+       err = perf_config(convert__config, &c);
+       if (err)
+               return err;
 
        /* CTF writer */
        if (ctf_writer__init(cw, path))
                return -1;
 
+       err = -1;
        /* perf.data session */
        session = perf_session__new(&file, 0, &c.tool);
        if (!session)
index 6770a964560954e0b7d028698a50b8bcab0cf891..cff2e9041b15f9d0967f0975a7c791992b6bc045 100644 (file)
@@ -2439,8 +2439,10 @@ int parse_filter_percentage(const struct option *opt __maybe_unused,
                symbol_conf.filter_relative = true;
        else if (!strcmp(arg, "absolute"))
                symbol_conf.filter_relative = false;
-       else
+       else {
+               pr_debug("Invalud percentage: %s\n", arg);
                return -1;
+       }
 
        return 0;
 }
index 85d5eeb66c75339fc7c230bfcd7bcabd975ee402..da20cd5612e97f53853a3fdfb79502cdfa5d3a6b 100644 (file)
@@ -2159,7 +2159,9 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
 
        addr_filters__init(&pt->filts);
 
-       perf_config(intel_pt_perf_config, pt);
+       err = perf_config(intel_pt_perf_config, pt);
+       if (err)
+               goto err_free;
 
        err = auxtrace_queues__init(&pt->queues);
        if (err)
index b23ff44cf214fe7f786230a72a8466ffe7e91dc7..824356488ce6a8c7d9ecda1748456b262f0a7114 100644 (file)
@@ -48,8 +48,10 @@ int perf_llvm_config(const char *var, const char *value)
                llvm_param.kbuild_opts = strdup(value);
        else if (!strcmp(var, "dump-obj"))
                llvm_param.dump_obj = !!perf_config_bool(var, value);
-       else
+       else {
+               pr_debug("Invalid LLVM config option: %s\n", value);
                return -1;
+       }
        llvm_param.user_set_param = true;
        return 0;
 }