blob: 53d16e4d0923c39927117d4f6e74ce35976a2938 [file] [log] [blame] [view]
Ulises Mendez Martinezc2ac77f2022-11-15 15:11:36 +00001# `GCOV`
2
3When the flag `--gcov` is set, the build is reconfigured to produce (and keep)
4`*.gcno` files.
5
6For example:
7
8```shell
Yifan Hong669e4302023-01-31 15:00:36 -08009$ tools/bazel build --gcov //common:kernel_aarch64
Ulises Mendez Martinezc2ac77f2022-11-15 15:11:36 +000010```
11
12You may find the `*.gcno` files under the
Yifan Hongded788d2023-02-08 18:43:55 +000013`bazel-bin/<package_name>/<target_name>/<target_name>_gcno` directory,
Ulises Mendez Martinezc2ac77f2022-11-15 15:11:36 +000014where `<target_name>` is the name of the `kernel_build()`
15macro. In the above example, the `.gcno` files can be found at
16
17```
Yifan Hongded788d2023-02-08 18:43:55 +000018bazel-bin/common/kernel_aarch64/kernel_aarch64_gcno/
19```
20
HONG Yifan51cdd9b2024-09-03 16:47:46 -070021... or in `destdir`.
Yifan Hong669e4302023-01-31 15:00:36 -080022
23## Handling path mapping
24
25After you boot up the kernel and [mount debugfs](https://docs.kernel.org/filesystems/debugfs.html):
26
27```shell
28$ mount -t debugfs debugfs /sys/kernel/debug
29```
30
31You may see gcno files under:
32
33```
34/sys/kernel/debug/gcov/<some_host_absolute_path_to_repository>/<some_out_directory>/common/<some_source_file>.gcno
35```
36
Yifan Hongded788d2023-02-08 18:43:55 +000037To map between these paths to the host, consult the `gcno_mapping.<name>.json`
Yifan Hong669e4302023-01-31 15:00:36 -080038under `bazel-bin/`.
39
40### GKI
41
42In the above example, the file can be found after a build:
43
44```shell
45$ tools/bazel build --gcov //common:kernel_aarch64
46[...]
Yifan Hongded788d2023-02-08 18:43:55 +000047$ cat bazel-bin/common/kernel_aarch64/gcno_mapping.kernel_aarch64.json
Yifan Hong669e4302023-01-31 15:00:36 -080048[...]
49```
50
HONG Yifan51cdd9b2024-09-03 16:47:46 -070051You may also find this file under `destdir`:
Yifan Hong669e4302023-01-31 15:00:36 -080052
53```shell
HONG Yifan51cdd9b2024-09-03 16:47:46 -070054$ tools/bazel run //common:kernel_aarch64_dist -- --destdir=out/kernel_aarch64/dist
Yifan Hong669e4302023-01-31 15:00:36 -080055[...]
56$ cat out/kernel_aarch64/dist/gcno_mapping.kernel_aarch64.json
57[...]
58```
59
60### Device mixed builds
61
62You need to consult the JSON file for the device `kernel_build`.
63Using virtual device as an example, you may find the files under:
64
65```shell
66$ tools/bazel build --gcov //common-modules/virtual-device:virtual_device_x86_64
67[...]
Yifan Hongded788d2023-02-08 18:43:55 +000068$ cat bazel-bin/common-modules/virtual-device/virtual_device_x86_64/gcno_mapping.virtual_device_x86_64.json
Yifan Hong669e4302023-01-31 15:00:36 -080069[...]
70```
71
HONG Yifan51cdd9b2024-09-03 16:47:46 -070072Or under `destdir`:
Yifan Hong669e4302023-01-31 15:00:36 -080073
74```shell
HONG Yifan51cdd9b2024-09-03 16:47:46 -070075$ tools/bazel run --gcov //common-modules/virtual-device:virtual_device_x86_64_dist -- --destdir=out/vd/dist
Yifan Hong669e4302023-01-31 15:00:36 -080076[...]
77$ cat out/vd/dist/gcno_mapping.virtual_device_x86_64.json
78[...]
79```
80
HONG Yifan51cdd9b2024-09-03 16:47:46 -070081**Note**: You will also see `gcno_mapping.kernel_x86_64.json` under `destdir`. That file is incomplete
Yifan Hong669e4302023-01-31 15:00:36 -080082as it does not contain mappings for in-tree modules specific for virtual device.
83
Yifan Hongded788d2023-02-08 18:43:55 +000084### Sample content of `gcno_mapping.<name>.json`:
Yifan Hong669e4302023-01-31 15:00:36 -080085
86Without `--config=local` (see [sandboxing](sandbox.md)):
87
88```json
89[
90 {
91 "from": "/<repository_root>/out/bazel/output_user_root/.../__main__/out.../android-mainline/common",
92 "to": "bazel-out/.../kernel_x86_64/gcno"
93 }
94]
95```
96
97With `--config=local` (see [sandboxing](sandbox.md)):
98
99```json
100[
101 {
102 "from": "/mnt/sdc/android/kernel/out/cache/.../common",
103 "to": "bazel-out/k8-fastbuild/bin/common/kernel_aarch64/gcno"
104 }
105]
106```
107
108The JSON file contains a list of mappings. Each mapping indicates that the `.gcno` files
109located in `<from>` were copied to `<to>`. Hence, `/sys/kernel/debug/<from>`
110on the device maps to `<to>` on host.
111
112**Note**: For both `<from>` and `<to>`, absolute paths should be interpreted as-is,
113and relative paths should be interpreted as relative to the repository on host. For example:
114
115```json
116[
117 {
118 "from": "/absolute/from",
119 "to": "/absolute/to"
120 },
121 {
122 "from": "relative/from",
123 "to": "relative/to"
124 }
125]
126```
127
128This means:
129* Device `/sys/kernel/debug/absolute/from` maps to host `/absolute/to`
130* Device `/sys/kernel/debug/<repositry_root>/relative/from` maps to host `/<repository_root>/relative/to`.