Commit 608585f4 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf ftrace: Factor out check_ftrace_capable()

The check is a common part of the ftrace commands, let's move it out.
Reviewed-by: default avatarIan Rogers <irogers@google.com>
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Changbin Du <changbin.du@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Link: https://lore.kernel.org/lkml/20240729004127.238611-3-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c7780089
...@@ -59,6 +59,22 @@ static void ftrace__workload_exec_failed_signal(int signo __maybe_unused, ...@@ -59,6 +59,22 @@ static void ftrace__workload_exec_failed_signal(int signo __maybe_unused,
done = true; done = true;
} }
static int check_ftrace_capable(void)
{
if (!(perf_cap__capable(CAP_PERFMON) ||
perf_cap__capable(CAP_SYS_ADMIN))) {
pr_err("ftrace only works for %s!\n",
#ifdef HAVE_LIBCAP_SUPPORT
"users with the CAP_PERFMON or CAP_SYS_ADMIN capability"
#else
"root"
#endif
);
return -1;
}
return 0;
}
static int __write_tracing_file(const char *name, const char *val, bool append) static int __write_tracing_file(const char *name, const char *val, bool append)
{ {
char *file; char *file;
...@@ -586,18 +602,6 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace) ...@@ -586,18 +602,6 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace)
.events = POLLIN, .events = POLLIN,
}; };
if (!(perf_cap__capable(CAP_PERFMON) ||
perf_cap__capable(CAP_SYS_ADMIN))) {
pr_err("ftrace only works for %s!\n",
#ifdef HAVE_LIBCAP_SUPPORT
"users with the CAP_PERFMON or CAP_SYS_ADMIN capability"
#else
"root"
#endif
);
return -1;
}
select_tracer(ftrace); select_tracer(ftrace);
if (reset_tracing_files(ftrace) < 0) { if (reset_tracing_files(ftrace) < 0) {
...@@ -902,18 +906,6 @@ static int __cmd_latency(struct perf_ftrace *ftrace) ...@@ -902,18 +906,6 @@ static int __cmd_latency(struct perf_ftrace *ftrace)
}; };
int buckets[NUM_BUCKET] = { }; int buckets[NUM_BUCKET] = { };
if (!(perf_cap__capable(CAP_PERFMON) ||
perf_cap__capable(CAP_SYS_ADMIN))) {
pr_err("ftrace only works for %s!\n",
#ifdef HAVE_LIBCAP_SUPPORT
"users with the CAP_PERFMON or CAP_SYS_ADMIN capability"
#else
"root"
#endif
);
return -1;
}
trace_fd = prepare_func_latency(ftrace); trace_fd = prepare_func_latency(ftrace);
if (trace_fd < 0) if (trace_fd < 0)
goto out; goto out;
...@@ -1220,6 +1212,10 @@ int cmd_ftrace(int argc, const char **argv) ...@@ -1220,6 +1212,10 @@ int cmd_ftrace(int argc, const char **argv)
signal(SIGCHLD, sig_handler); signal(SIGCHLD, sig_handler);
signal(SIGPIPE, sig_handler); signal(SIGPIPE, sig_handler);
ret = check_ftrace_capable();
if (ret < 0)
return -1;
ret = perf_config(perf_ftrace_config, &ftrace); ret = perf_config(perf_ftrace_config, &ftrace);
if (ret < 0) if (ret < 0)
return -1; return -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment