5sec.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. Description:
  4. . Disable strace like syscall tracing (--no-syscalls), or try tracing
  5. just some (-e *sleep).
  6. . Attach a filter function to a kernel function, returning when it should
  7. be considered, i.e. appear on the output.
  8. . Run it system wide, so that any sleep of >= 5 seconds and < than 6
  9. seconds gets caught.
  10. . Ask for callgraphs using DWARF info, so that userspace can be unwound
  11. . While this is running, run something like "sleep 5s".
  12. . If we decide to add tv_nsec as well, then it becomes:
  13. int probe(hrtimer_nanosleep, rqtp->tv_sec rqtp->tv_nsec)(void *ctx, int err, long sec, long nsec)
  14. I.e. add where it comes from (rqtp->tv_nsec) and where it will be
  15. accessible in the function body (nsec)
  16. # perf trace --no-syscalls -e tools/perf/examples/bpf/5sec.c/call-graph=dwarf/
  17. 0.000 perf_bpf_probe:func:(ffffffff9811b5f0) tv_sec=5
  18. hrtimer_nanosleep ([kernel.kallsyms])
  19. __x64_sys_nanosleep ([kernel.kallsyms])
  20. do_syscall_64 ([kernel.kallsyms])
  21. entry_SYSCALL_64 ([kernel.kallsyms])
  22. __GI___nanosleep (/usr/lib64/libc-2.26.so)
  23. rpl_nanosleep (/usr/bin/sleep)
  24. xnanosleep (/usr/bin/sleep)
  25. main (/usr/bin/sleep)
  26. __libc_start_main (/usr/lib64/libc-2.26.so)
  27. _start (/usr/bin/sleep)
  28. ^C#
  29. Copyright (C) 2018 Red Hat, Inc., Arnaldo Carvalho de Melo <acme@redhat.com>
  30. */
  31. #include <bpf.h>
  32. int probe(hrtimer_nanosleep, rqtp->tv_sec)(void *ctx, int err, long sec)
  33. {
  34. return sec == 5;
  35. }
  36. license(GPL);