]> git.baikalelectronics.ru Git - kernel.git/commit
perf bpf: Add bpf/stdio.h wrapper to bpf_perf_event_output function
authorArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 6 Aug 2018 12:15:18 +0000 (09:15 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 8 Aug 2018 18:55:55 +0000 (15:55 -0300)
commit4fa44b8517743fd3e9b12a90d3a5b27edc91818b
tree06ebe9a88eff99e3f3fcea2e5f21a4523be95793
parentc07b6c6c5457b90d95a75b201045379548af6251
perf bpf: Add bpf/stdio.h wrapper to bpf_perf_event_output function

That, together with the map __bpf_output__ that is already handled by
'perf trace' to print that event's contents as strings provides a
debugging facility, to show it in use, print a simple string everytime
the syscalls:sys_enter_openat() syscall tracepoint is hit:

  # cat tools/perf/examples/bpf/hello.c
  #include <stdio.h>

  int syscall_enter(openat)(void *args)
  {
  puts("Hello, world\n");
  return 0;
  }

  license(GPL);
  #
  # perf trace -e openat,tools/perf/examples/bpf/hello.c cat /etc/passwd > /dev/null
     0.016 (         ): __bpf_stdout__:Hello, world
     0.018 ( 0.010 ms): cat/9079 openat(dfd: CWD, filename: /etc/ld.so.cache, flags: CLOEXEC) = 3
     0.057 (         ): __bpf_stdout__:Hello, world
     0.059 ( 0.011 ms): cat/9079 openat(dfd: CWD, filename: /lib64/libc.so.6, flags: CLOEXEC) = 3
     0.417 (         ): __bpf_stdout__:Hello, world
     0.419 ( 0.009 ms): cat/9079 openat(dfd: CWD, filename: /etc/passwd) = 3
  #

This is part of an ongoing experimentation on making eBPF scripts as
consumed by perf to be as concise as possible and using familiar
concepts such as stdio.h functions, that end up just wrapping the
existing BPF functions, trying to hide as much boilerplate as possible
while using just conventions and C preprocessor tricks.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-4tiaqlx5crf0fwpe7a6j84x7@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/examples/bpf/hello.c [new file with mode: 0644]
tools/perf/include/bpf/stdio.h [new file with mode: 0644]