diff options
Diffstat (limited to 'tools/perf/builtin-ftrace.c')
| -rw-r--r-- | tools/perf/builtin-ftrace.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index ae1466aa3b26..1367bb5046a7 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -13,6 +13,7 @@ #include <signal.h> #include <fcntl.h> #include <poll.h> +#include <linux/capability.h> #include "debug.h" #include <subcmd/parse-options.h> @@ -21,6 +22,7 @@ #include "target.h" #include "cpumap.h" #include "thread_map.h" +#include "util/cap.h" #include "util/config.h" @@ -173,7 +175,7 @@ static int set_tracing_cpumask(struct perf_cpu_map *cpumap) int last_cpu; last_cpu = cpu_map__cpu(cpumap, cpumap->nr - 1); - mask_size = (last_cpu + 3) / 4 + 1; + mask_size = last_cpu / 4 + 2; /* one more byte for EOS */ mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */ cpumask = malloc(mask_size); @@ -281,8 +283,14 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) .events = POLLIN, }; - if (geteuid() != 0) { - pr_err("ftrace only works for root!\n"); + if (!perf_cap__capable(CAP_SYS_ADMIN)) { + pr_err("ftrace only works for %s!\n", +#ifdef HAVE_LIBCAP_SUPPORT + "users with the SYS_ADMIN capability" +#else + "root" +#endif + ); return -1; } |
