Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf list: Give clues if failed to open tracing events directory

When executing the command "perf list", I met "Error: failed to open
tracing events directory" twice, the first reason is that there is no
"/sys/kernel/tracing/events" directory due to it does not enable the
kernel tracing infrastructure with CONFIG_FTRACE, the second reason
is that there is no root privileges.

Add the error string to tell the users what happened and what should
to do, and also call put_tracing_file() to free events_path a little
later to avoid messy code in the error message.

At the same time, just remove the redundant "/" of the file path in
the function get_tracing_file(), otherwise it shows something like
"/sys/kernel/tracing//events".

Before:

$ ./perf list
Error: failed to open tracing events directory

After:

(1) Without CONFIG_FTRACE

$ ./perf list
Error: failed to open tracing events directory
/sys/kernel/tracing/events: No such file or directory

(2) With CONFIG_FTRACE but no root privileges

$ ./perf list
Error: failed to open tracing events directory
/sys/kernel/tracing/events: Permission denied

Committer testing:

Redirect stdout to null to quickly test the patch:

Before:

$ perf list > /dev/null
Error: failed to open tracing events directory
$

After:

$ perf list > /dev/null
Error: failed to open tracing events directory
/sys/kernel/tracing/events: Permission denied
$

Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/lkml/20240730062301.23244-3-yangtiezhu@loongson.cn
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Tiezhu Yang and committed by
Arnaldo Carvalho de Melo
b48543c4 839b1832

+3 -2
+1 -1
tools/lib/api/fs/tracing_path.c
··· 69 69 { 70 70 char *file; 71 71 72 - if (asprintf(&file, "%s/%s", tracing_path_mount(), name) < 0) 72 + if (asprintf(&file, "%s%s", tracing_path_mount(), name) < 0) 73 73 return NULL; 74 74 75 75 return file;
+2 -1
tools/perf/util/print-events.c
··· 68 68 struct dirent **sys_namelist = NULL; 69 69 int sys_items; 70 70 71 - put_tracing_file(events_path); 72 71 if (events_fd < 0) { 73 72 pr_err("Error: failed to open tracing events directory\n"); 73 + pr_err("%s: %s\n", events_path, strerror(errno)); 74 74 return; 75 75 } 76 + put_tracing_file(events_path); 76 77 77 78 sys_items = tracing_events__scandir_alphasort(&sys_namelist); 78 79