Skip to content

Commit ecc4c56

Browse files
committed
perf tools: Propagate perf_config() errors
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 <[email protected]> Cc: David Ahern <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Wang Nan <[email protected]> Link: http://lkml.kernel.org/n/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent afc45cf commit ecc4c56

File tree

12 files changed

+62
-23
lines changed

12 files changed

+62
-23
lines changed

tools/perf/builtin-help.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,11 +447,13 @@ int cmd_help(int argc, const char **argv, const char *prefix __maybe_unused)
447447
NULL
448448
};
449449
const char *alias;
450-
int rc = 0;
450+
int rc;
451451

452452
load_command_list("perf-", &main_cmds, &other_cmds);
453453

454-
perf_config(perf_help_config, &help_format);
454+
rc = perf_config(perf_help_config, &help_format);
455+
if (rc)
456+
return rc;
455457

456458
argc = parse_options_subcommand(argc, argv, builtin_help_options,
457459
builtin_help_subcommands, builtin_help_usage, 0);

tools/perf/builtin-kmem.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,10 +1920,12 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
19201920
NULL
19211921
};
19221922
struct perf_session *session;
1923-
int ret = -1;
19241923
const char errmsg[] = "No %s allocation events found. Have you run 'perf kmem record --%s'?\n";
1924+
int ret = perf_config(kmem_config, NULL);
1925+
1926+
if (ret)
1927+
return ret;
19251928

1926-
perf_config(kmem_config, NULL);
19271929
argc = parse_options_subcommand(argc, argv, kmem_options,
19281930
kmem_subcommands, kmem_usage, 0);
19291931

@@ -1948,6 +1950,8 @@ int cmd_kmem(int argc, const char **argv, const char *prefix __maybe_unused)
19481950
if (session == NULL)
19491951
return -1;
19501952

1953+
ret = -1;
1954+
19511955
if (kmem_slab) {
19521956
if (!perf_evlist__find_tracepoint_by_name(session->evlist,
19531957
"kmem:kmalloc")) {

tools/perf/builtin-record.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,9 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)
16701670
if (rec->evlist == NULL)
16711671
return -ENOMEM;
16721672

1673-
perf_config(perf_record_config, rec);
1673+
err = perf_config(perf_record_config, rec);
1674+
if (err)
1675+
return err;
16741676

16751677
argc = parse_options(argc, argv, record_options, record_usage,
16761678
PARSE_OPT_STOP_AT_NON_OPTION);

tools/perf/builtin-report.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,9 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
847847
if (ret < 0)
848848
return ret;
849849

850-
perf_config(report__config, &report);
850+
ret = perf_config(report__config, &report);
851+
if (ret)
852+
return ret;
851853

852854
argc = parse_options(argc, argv, options, report_usage, 0);
853855
if (argc) {

tools/perf/builtin-top.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
12161216
if (top.evlist == NULL)
12171217
return -ENOMEM;
12181218

1219-
perf_config(perf_top_config, &top);
1219+
status = perf_config(perf_top_config, &top);
1220+
if (status)
1221+
return status;
12201222

12211223
argc = parse_options(argc, argv, options, top_usage, 0);
12221224
if (argc)

tools/perf/perf.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,12 @@ static int pager_command_config(const char *var, const char *value, void *data)
9090
/* returns 0 for "no pager", 1 for "use pager", and -1 for "not specified" */
9191
int check_pager_config(const char *cmd)
9292
{
93+
int err;
9394
struct pager_config c;
9495
c.cmd = cmd;
9596
c.val = -1;
96-
perf_config(pager_command_config, &c);
97-
return c.val;
97+
err = perf_config(pager_command_config, &c);
98+
return err ?: c.val;
9899
}
99100

100101
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
113114
*/
114115
static int check_browser_config(const char *cmd)
115116
{
117+
int err;
116118
struct pager_config c;
117119
c.cmd = cmd;
118120
c.val = -1;
119-
perf_config(browser_command_config, &c);
120-
return c.val;
121+
err = perf_config(browser_command_config, &c);
122+
return err ?: c.val;
121123
}
122124

123125
static void commit_pager_choice(void)
@@ -509,6 +511,7 @@ static void cache_line_size(int *cacheline_sizep)
509511

510512
int main(int argc, const char **argv)
511513
{
514+
int err;
512515
const char *cmd;
513516
char sbuf[STRERR_BUFSIZE];
514517
int value;
@@ -534,7 +537,9 @@ int main(int argc, const char **argv)
534537
srandom(time(NULL));
535538

536539
perf_config__init();
537-
perf_config(perf_default_config, NULL);
540+
err = perf_config(perf_default_config, NULL);
541+
if (err)
542+
return err;
538543
set_buildid_dir(NULL);
539544

540545
/* get debugfs/tracefs mount point from /proc/mounts */

tools/perf/util/callchain.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ static int parse_callchain_mode(const char *value)
4848
callchain_param.mode = CHAIN_FOLDED;
4949
return 0;
5050
}
51+
52+
pr_err("Invalid callchain mode: %s\n", value);
5153
return -1;
5254
}
5355

@@ -63,6 +65,8 @@ static int parse_callchain_order(const char *value)
6365
callchain_param.order_set = true;
6466
return 0;
6567
}
68+
69+
pr_err("Invalid callchain order: %s\n", value);
6670
return -1;
6771
}
6872

@@ -80,6 +84,8 @@ static int parse_callchain_sort_key(const char *value)
8084
callchain_param.branch_callstack = 1;
8185
return 0;
8286
}
87+
88+
pr_err("Invalid callchain sort key: %s\n", value);
8389
return -1;
8490
}
8591

@@ -97,6 +103,8 @@ static int parse_callchain_value(const char *value)
97103
callchain_param.value = CCVAL_COUNT;
98104
return 0;
99105
}
106+
107+
pr_err("Invalid callchain config key: %s\n", value);
100108
return -1;
101109
}
102110

@@ -210,13 +218,17 @@ int perf_callchain_config(const char *var, const char *value)
210218
return parse_callchain_sort_key(value);
211219
if (!strcmp(var, "threshold")) {
212220
callchain_param.min_percent = strtod(value, &endptr);
213-
if (value == endptr)
221+
if (value == endptr) {
222+
pr_err("Invalid callchain threshold: %s\n", value);
214223
return -1;
224+
}
215225
}
216226
if (!strcmp(var, "print-limit")) {
217227
callchain_param.print_limit = strtod(value, &endptr);
218-
if (value == endptr)
228+
if (value == endptr) {
229+
pr_err("Invalid callchain print limit: %s\n", value);
219230
return -1;
231+
}
220232
}
221233

222234
return 0;

tools/perf/util/config.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,10 @@ static int perf_buildid_config(const char *var, const char *value)
386386
if (!strcmp(var, "buildid.dir")) {
387387
const char *dir = perf_config_dirname(var, value);
388388

389-
if (!dir)
389+
if (!dir) {
390+
pr_err("Invalid buildid directory!\n");
390391
return -1;
392+
}
391393
strncpy(buildid_dir, dir, MAXPATHLEN-1);
392394
buildid_dir[MAXPATHLEN-1] = '\0';
393395
}
@@ -405,10 +407,9 @@ static int perf_default_core_config(const char *var __maybe_unused,
405407
static int perf_ui_config(const char *var, const char *value)
406408
{
407409
/* Add other config variables here. */
408-
if (!strcmp(var, "ui.show-headers")) {
410+
if (!strcmp(var, "ui.show-headers"))
409411
symbol_conf.show_hist_headers = perf_config_bool(var, value);
410-
return 0;
411-
}
412+
412413
return 0;
413414
}
414415

tools/perf/util/data-convert-bt.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,20 +1473,23 @@ int bt_convert__perf2ctf(const char *input, const char *path,
14731473
},
14741474
};
14751475
struct ctf_writer *cw = &c.writer;
1476-
int err = -1;
1476+
int err;
14771477

14781478
if (opts->all) {
14791479
c.tool.comm = process_comm_event;
14801480
c.tool.exit = process_exit_event;
14811481
c.tool.fork = process_fork_event;
14821482
}
14831483

1484-
perf_config(convert__config, &c);
1484+
err = perf_config(convert__config, &c);
1485+
if (err)
1486+
return err;
14851487

14861488
/* CTF writer */
14871489
if (ctf_writer__init(cw, path))
14881490
return -1;
14891491

1492+
err = -1;
14901493
/* perf.data session */
14911494
session = perf_session__new(&file, 0, &c.tool);
14921495
if (!session)

tools/perf/util/hist.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2439,8 +2439,10 @@ int parse_filter_percentage(const struct option *opt __maybe_unused,
24392439
symbol_conf.filter_relative = true;
24402440
else if (!strcmp(arg, "absolute"))
24412441
symbol_conf.filter_relative = false;
2442-
else
2442+
else {
2443+
pr_debug("Invalud percentage: %s\n", arg);
24432444
return -1;
2445+
}
24442446

24452447
return 0;
24462448
}

tools/perf/util/intel-pt.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,9 @@ int intel_pt_process_auxtrace_info(union perf_event *event,
21592159

21602160
addr_filters__init(&pt->filts);
21612161

2162-
perf_config(intel_pt_perf_config, pt);
2162+
err = perf_config(intel_pt_perf_config, pt);
2163+
if (err)
2164+
goto err_free;
21632165

21642166
err = auxtrace_queues__init(&pt->queues);
21652167
if (err)

tools/perf/util/llvm-utils.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ int perf_llvm_config(const char *var, const char *value)
4848
llvm_param.kbuild_opts = strdup(value);
4949
else if (!strcmp(var, "dump-obj"))
5050
llvm_param.dump_obj = !!perf_config_bool(var, value);
51-
else
51+
else {
52+
pr_debug("Invalid LLVM config option: %s\n", value);
5253
return -1;
54+
}
5355
llvm_param.user_set_param = true;
5456
return 0;
5557
}

0 commit comments

Comments
 (0)