xref: /cloud-hypervisor/docs/profiling.md (revision 3ce0fef7fd546467398c914dbc74d8542e45cf6f)
1# Profiling
2
3`perf` can be used to profile the `cloud-hypervisor` binary but it is necessary to make some modifications to the build in order to produce a binary that gives useful results.
4
5## Building a suitable binary
6
7This adds the symbol information to the release binary but does not otherwise affect the performance.
8
9The binary must also be built with frame pointers included so that the call graph can be captured by the profiler.
10
11```
12$ cargo clean && RUSTFLAGS='-C force-frame-pointers=y' cargo build --profile profiling
13```
14
15## Profiling
16
17`perf` may then be used in the usual manner:
18
19e.g.
20
21```
22$ perf record -g target/profiling/cloud-hypervisor \
23        --kernel ~/src/linux/vmlinux \
24        --pmem file=~/workloads/focal.raw \
25        --cpus boot=1 --memory size=1G \
26        --cmdline "root=/dev/pmem0p1 console=ttyS0" \
27        --serial tty --console off \
28        --api-socket=/tmp/api1
29```
30
31For analysing the samples:
32
33```
34$ perf report -g
35```
36
37If profiling with a network device attached either the TAP device must be already created and configured or the profiling must be done as root so that the TAP device can be created.
38
39## Userspace only profiling with LBR
40
41The use of LBR (Last Branch Record; available since Haswell) offers lower
42overhead if only userspace profiling is required. This lower overhead can allow
43a higher frequency of sampling. This also removes the requirement to compile
44with custom `RUSTFLAGS` however debug symbols should still be included:
45
46e.g.
47
48```
49$ perf record --call-graph lbr --all-user --user-callchains -g target/release/cloud-hypervisor \
50        --kernel ~/src/linux/vmlinux \
51        --pmem file=~/workloads/focal.raw \
52        --cpus boot=1 --memory size=1G \
53        --cmdline "root=/dev/pmem0p1 console=ttyS0" \
54        --serial tty --console off \
55        --api-socket=/tmp/api1
56```
57