mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-04 17:44:14 +08:00
301f0203e0
It was looking at bpf/bpf.h, which caused this problem: # perf trace -e tools/perf/examples/bpf/5sec.c /home/acme/git/perf/tools/perf/examples/bpf/5sec.c:42:10: fatal error: 'bpf/bpf.h' file not found #include <bpf/bpf.h> ^~~~~~~~~~~ 1 error generated. ERROR: unable to compile tools/perf/examples/bpf/5sec.c Hint: Check error message shown above. Hint: You can also pre-compile it into .o using: clang -target bpf -O2 -c tools/perf/examples/bpf/5sec.c with proper -I and -D options. event syntax error: 'tools/perf/examples/bpf/5sec.c' \___ Failed to load tools/perf/examples/bpf/5sec.c from source: Error when compiling BPF scriptlet # Change that to plain bpf.h, to make it work again: # perf trace -e tools/perf/examples/bpf/5sec.c sleep 5s 0.000 perf_bpf_probe:hrtimer_nanosleep(__probe_ip: -1776891872, rqtp: 5000000000) # perf trace -e tools/perf/examples/bpf/5sec.c/max-stack=16/ sleep 5s 0.000 perf_bpf_probe:hrtimer_nanosleep(__probe_ip: -1776891872, rqtp: 5000000000) hrtimer_nanosleep ([kernel.kallsyms]) common_nsleep ([kernel.kallsyms]) __x64_sys_clock_nanosleep ([kernel.kallsyms]) do_syscall_64 ([kernel.kallsyms]) entry_SYSCALL_64_after_hwframe ([kernel.kallsyms]) __clock_nanosleep_2 (/usr/lib64/libc-2.32.so) # perf trace -e tools/perf/examples/bpf/5sec.c sleep 4s # Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
52 lines
2.0 KiB
C
52 lines
2.0 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
Description:
|
|
|
|
. Disable strace like syscall tracing (--no-syscalls), or try tracing
|
|
just some (-e *sleep).
|
|
|
|
. Attach a filter function to a kernel function, returning when it should
|
|
be considered, i.e. appear on the output.
|
|
|
|
. Run it system wide, so that any sleep of >= 5 seconds and < than 6
|
|
seconds gets caught.
|
|
|
|
. Ask for callgraphs using DWARF info, so that userspace can be unwound
|
|
|
|
. While this is running, run something like "sleep 5s".
|
|
|
|
. If we decide to add tv_nsec as well, then it becomes:
|
|
|
|
int probe(hrtimer_nanosleep, rqtp->tv_sec rqtp->tv_nsec)(void *ctx, int err, long sec, long nsec)
|
|
|
|
I.e. add where it comes from (rqtp->tv_nsec) and where it will be
|
|
accessible in the function body (nsec)
|
|
|
|
# perf trace --no-syscalls -e tools/perf/examples/bpf/5sec.c/call-graph=dwarf/
|
|
0.000 perf_bpf_probe:func:(ffffffff9811b5f0) tv_sec=5
|
|
hrtimer_nanosleep ([kernel.kallsyms])
|
|
__x64_sys_nanosleep ([kernel.kallsyms])
|
|
do_syscall_64 ([kernel.kallsyms])
|
|
entry_SYSCALL_64 ([kernel.kallsyms])
|
|
__GI___nanosleep (/usr/lib64/libc-2.26.so)
|
|
rpl_nanosleep (/usr/bin/sleep)
|
|
xnanosleep (/usr/bin/sleep)
|
|
main (/usr/bin/sleep)
|
|
__libc_start_main (/usr/lib64/libc-2.26.so)
|
|
_start (/usr/bin/sleep)
|
|
^C#
|
|
|
|
Copyright (C) 2018 Red Hat, Inc., Arnaldo Carvalho de Melo <acme@redhat.com>
|
|
*/
|
|
|
|
#include <bpf.h>
|
|
|
|
#define NSEC_PER_SEC 1000000000L
|
|
|
|
int probe(hrtimer_nanosleep, rqtp)(void *ctx, int err, long long sec)
|
|
{
|
|
return sec / NSEC_PER_SEC == 5ULL;
|
|
}
|
|
|
|
license(GPL);
|