Skip to contentSkip to conversation

perf record: Add doc for bpf event selection

PATCH Superseded Changbin Du 2 participants 3 messages Feb 1, 2019 perf events

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf record: Add doc for bpf event selection

Add document for how to pass bpf program with perf.

---
 tools/perf/Documentation/perf-record.txt | 13 +++++++++++++
 1 file changed, 13 insertions(+)
tools/perf/Documentation/perf-record.txt +13 -0
index d232b13ea713..0925d987cad0 100644
@@ -88,6 +88,19 @@ OPTIONS
           If you want to profile write accesses in [0x1000~1008), just set
           'mem:0x1000/8:w'.
 
+        - a bpf source file or object file to select events by a bpf program.
+          The bpf program can attach to variant perf events based on section
+          names.
+
+          When passing '.c', perf searches installed LLVM to compile it into
+          object file first. Optional clang options can be pased by option
+          '--clang-opt'.
+
+          perf record --clang-opt "-DLINUX_VERSION_CODE=0x50000" \
+                      -e ./tests/bpf-script-example.c
+
+          Note: '--clang-opt' must place before '--event'.
+
 	- a group of events surrounded by a pair of brace ("{event1,event2,...}").
 	  Each event is separated by commas and the group should be quoted to
 	  prevent the shell interpretation.  You also need to use --group on
Signature · 1 line
2.17.1
#1 lore raw

Em Fri, Feb 01, 2019 at 03:06:41AM +0000, Changbin Du escreveu:

Quoted 1 line

Add document for how to pass bpf program with perf.

That is a good start, see some comments below.

Quoted 10 lines
---
 tools/perf/Documentation/perf-record.txt | 13 +++++++++++++
 1 file changed, 13 insertions(+)
tools/perf/Documentation/perf-record.txt +0 -0
index d232b13ea713..0925d987cad0 100644

tools/perf/Documentation/perf-record.txt OPTIONS · line 91

Quoted 4 lines
tools/perf/Documentation/perf-record.txt +1 -0
@@ -88,6 +88,19 @@ OPTIONS
           If you want to profile write accesses in [0x1000~1008), just set
           'mem:0x1000/8:w'.
 
+        - a bpf source file or object file to select events by a bpf program.

A source file (ending in .c) or a precompiled object file (ending in .o) selects one or more BPF events.

tools/perf/Documentation/perf-record.txt OPTIONS · line 92

Quoted 1 line
tools/perf/Documentation/perf-record.txt +1 -0
+          The bpf program can attach to variant perf events based on section

The BPFa various

tools/perf/Documentation/perf-record.txt OPTIONS · line 95

Quoted 3 lines
tools/perf/Documentation/perf-record.txt +3 -0
+          names.
+
+          When passing '.c', perf searches installed LLVM to compile it into

a

tools/perf/Documentation/perf-record.txt OPTIONS · line 96

Quoted 1 line
tools/perf/Documentation/perf-record.txt +1 -0
+          object file first. Optional clang options can be pased by option

an

tools/perf/Documentation/perf-record.txt OPTIONS · line 102

Quoted 6 lines
tools/perf/Documentation/perf-record.txt +6 -0
+          '--clang-opt'.
+
+          perf record --clang-opt "-DLINUX_VERSION_CODE=0x50000" \
+                      -e ./tests/bpf-script-example.c
+
+          Note: '--clang-opt' must place before '--event'.

Please mention ~/.perfconfig, that needs a section in the tools/perf/Documentation/perf-config.txt, for instance I have right now:

[root@quaco ~]# cat ~/.perfconfig
[llvm]
dump-obj = true
clang-opt = -g

The 'clang-opt' is the same as the command line arg you documented above, dump object may be used to update a .o file, like:

[root@quaco ~]# vim /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.c

# Do some changes, save

[root@quaco ~]# perf record -e /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.c sleep 1
LLVM: dumping /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.023 MB perf.data ]
[root@quaco ~]#

And if you are up to documenting the remaining features, which I'd encourage you, please take a look at:

tools/perf/util/llvm-utils.c

In the perf_llvm_config function. there are more things that needs documenting, and doing a:

git blame tools/perf/util/llvm-utils.c

Helps in getting the needed explanations, for instance, the original patch adding the .perfconfig section was this:

git show aa61fd05ca796

And it has, for instance, among others:

            # kbuild directory. If not set, use /lib/modules/`uname -r`/build.
            # If set to "" deliberately, skip kernel header auto-detector.
            kbuild-dir = "/path/to/kernel/build"

# Options passed to 'make' when detecting kernel header options. kbuild-opts = "ARCH=x86_64"

Thanks for working on documenting these features!

- Arnaldo

Quoted 6 lines
tools/perf/Documentation/perf-record.txt +1 -0
+
 	- a group of events surrounded by a pair of brace ("{event1,event2,...}").
 	  Each event is separated by commas and the group should be quoted to
 	  prevent the shell interpretation.  You also need to use --group on
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
#2 lore raw

Sure, please check them in v2. Thanks!

Quoted 98 lines · Arnaldo Carvalho de Melo

Em Fri, Feb 01, 2019 at 03:06:41AM +0000, Changbin Du escreveu:

Quoted 1 line

Add document for how to pass bpf program with perf.

That is a good start, see some comments below.

Quoted 10 lines
---
 tools/perf/Documentation/perf-record.txt | 13 +++++++++++++
 1 file changed, 13 insertions(+)
tools/perf/Documentation/perf-record.txt +0 -0
index d232b13ea713..0925d987cad0 100644

tools/perf/Documentation/perf-record.txt OPTIONS · line 91

Quoted 4 lines
tools/perf/Documentation/perf-record.txt +1 -0
@@ -88,6 +88,19 @@ OPTIONS
           If you want to profile write accesses in [0x1000~1008), just set
           'mem:0x1000/8:w'.
 
+        - a bpf source file or object file to select events by a bpf program.

A source file (ending in .c) or a precompiled object file (ending in .o) selects one or more BPF events.

tools/perf/Documentation/perf-record.txt OPTIONS · line 92

Quoted 1 line
tools/perf/Documentation/perf-record.txt +1 -0
+          The bpf program can attach to variant perf events based on section

The BPFa various

tools/perf/Documentation/perf-record.txt OPTIONS · line 95

Quoted 3 lines
tools/perf/Documentation/perf-record.txt +3 -0
+          names.
+
+          When passing '.c', perf searches installed LLVM to compile it into

a

tools/perf/Documentation/perf-record.txt OPTIONS · line 96

Quoted 1 line
tools/perf/Documentation/perf-record.txt +1 -0
+          object file first. Optional clang options can be pased by option

an

tools/perf/Documentation/perf-record.txt OPTIONS · line 102

Quoted 6 lines
tools/perf/Documentation/perf-record.txt +6 -0
+          '--clang-opt'.
+
+          perf record --clang-opt "-DLINUX_VERSION_CODE=0x50000" \
+                      -e ./tests/bpf-script-example.c
+
+          Note: '--clang-opt' must place before '--event'.

Please mention ~/.perfconfig, that needs a section in the tools/perf/Documentation/perf-config.txt, for instance I have right now:

[root@quaco ~]# cat ~/.perfconfig
[llvm]
dump-obj = true
clang-opt = -g

The 'clang-opt' is the same as the command line arg you documented above, dump object may be used to update a .o file, like:

[root@quaco ~]# vim /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.c

# Do some changes, save

[root@quaco ~]# perf record -e /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.c sleep 1
LLVM: dumping /home/acme/git/perf/tools/perf/examples/bpf/augmented_raw_syscalls.o
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.023 MB perf.data ]
[root@quaco ~]#

And if you are up to documenting the remaining features, which I'd encourage you, please take a look at:

tools/perf/util/llvm-utils.c

In the perf_llvm_config function. there are more things that needs documenting, and doing a:

git blame tools/perf/util/llvm-utils.c

Helps in getting the needed explanations, for instance, the original patch adding the .perfconfig section was this:

git show aa61fd05ca796

And it has, for instance, among others:

            # kbuild directory. If not set, use /lib/modules/`uname -r`/build.
            # If set to "" deliberately, skip kernel header auto-detector.
            kbuild-dir = "/path/to/kernel/build"

# Options passed to 'make' when detecting kernel header options. kbuild-opts = "ARCH=x86_64"

Thanks for working on documenting these features!

- Arnaldo

Quoted 6 lines
tools/perf/Documentation/perf-record.txt +1 -0
+
 	- a group of events surrounded by a pair of brace ("{event1,event2,...}").
 	  Each event is separated by commas and the group should be quoted to
 	  prevent the shell interpretation.  You also need to use --group on
Signature · 1 line
2.17.1
Signature · 1 line
- Arnaldo
Signature · 2 lines
Cheers,
Changbin Du