perf bpf: Add kprobe example to catch 5s naps
tip-bot for Arnaldo Carvalho de Melo
merge botCommit-ID: 7542b767b0469f4a76afa3feae6246d8a3d44e7f Gitweb: https://git.kernel.org/tip/7542b767b0469f4a76afa3feae6246d8a3d44e7f Author: Arnaldo Carvalho de Melo <[email protected]> AuthorDate: Fri, 4 May 2018 15:08:01 -0300 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Tue, 15 May 2018 14:31:24 -0300
perf bpf: Add kprobe example to catch 5s naps
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:
$ cat tools/perf/examples/bpf/5sec.c #include <bpf.h>
SEC("func=hrtimer_nanosleep rqtp->tv_sec")
int func(void *ctx, int err, long sec)
{
return sec == 5;}
char _license[] SEC("license") = "GPL";
int _version SEC("version") = LINUX_VERSION_CODE;
$. 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".
# 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#Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Wang Nan <[email protected]>
Signed-off-by Arnaldo Carvalho de Melo <[email protected]>
--- tools/perf/examples/bpf/5sec.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
tools/perf/examples/bpf/5sec.c new file +44 -0
@@ -0,0 +1,44 @@ +// 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". + +# 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 <[email protected]> +*/ + +#include <bpf.h> + +SEC("func=hrtimer_nanosleep rqtp->tv_sec") +int func (void *ctx,int err,long sec) +{ +return sec ==5 ; +} + +char _license[] SEC("license") = "GPL"; +int _version SEC("version") = LINUX_VERSION_CODE;