Skip to content

Commit 74298dd

Browse files
Changbin Duacmel
authored andcommitted
perf ftrace: Detect whether ftrace is enabled on system
To make error messages more accurate, this change detects whether ftrace is enabled on system by checking trace file "set_ftrace_pid". Before: # perf ftrace failed to reset ftrace # After: # perf ftrace ftrace is not supported on this system # Committer testing: Doing it in an unprivileged toolbox container on Fedora 40: Before: acme@number:~/git/perf-tools-next$ toolbox enter perf ⬢[acme@toolbox perf-tools-next]$ sudo su - ⬢[root@toolbox ~]# ~acme/bin/perf ftrace failed to reset ftrace ⬢[root@toolbox ~]# After this patch: ⬢[root@toolbox ~]# ~acme/bin/perf ftrace ftrace is not supported on this system ⬢[root@toolbox ~]# Maybe we could check if we are in such as situation, inside an unprivileged container, and provide a HINT line? Reviewed-by: James Clark <[email protected]> Signed-off-by: Changbin Du <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Changbin Du <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kan Liang <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 83420d5 commit 74298dd

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tools/perf/builtin-ftrace.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,24 @@ static bool check_ftrace_capable(void)
8080
return false;
8181
}
8282

83+
static bool is_ftrace_supported(void)
84+
{
85+
char *file;
86+
bool supported = false;
87+
88+
file = get_tracing_file("set_ftrace_pid");
89+
if (!file) {
90+
pr_debug("cannot get tracing file set_ftrace_pid\n");
91+
return false;
92+
}
93+
94+
if (!access(file, F_OK))
95+
supported = true;
96+
97+
put_tracing_file(file);
98+
return supported;
99+
}
100+
83101
static int __write_tracing_file(const char *name, const char *val, bool append)
84102
{
85103
char *file;
@@ -1583,6 +1601,11 @@ int cmd_ftrace(int argc, const char **argv)
15831601
if (!check_ftrace_capable())
15841602
return -1;
15851603

1604+
if (!is_ftrace_supported()) {
1605+
pr_err("ftrace is not supported on this system\n");
1606+
return -ENOTSUP;
1607+
}
1608+
15861609
ret = perf_config(perf_ftrace_config, &ftrace);
15871610
if (ret < 0)
15881611
return -1;

0 commit comments

Comments
 (0)