Ulises Mendez Martinez | c2ac77f | 2022-11-15 15:11:36 +0000 | [diff] [blame] | 1 | # `GCOV` |
| 2 | |
| 3 | When the flag `--gcov` is set, the build is reconfigured to produce (and keep) |
| 4 | `*.gcno` files. |
| 5 | |
| 6 | For example: |
| 7 | |
| 8 | ```shell |
Yifan Hong | 669e430 | 2023-01-31 15:00:36 -0800 | [diff] [blame] | 9 | $ tools/bazel build --gcov //common:kernel_aarch64 |
Ulises Mendez Martinez | c2ac77f | 2022-11-15 15:11:36 +0000 | [diff] [blame] | 10 | ``` |
| 11 | |
| 12 | You may find the `*.gcno` files under the |
Yifan Hong | ded788d | 2023-02-08 18:43:55 +0000 | [diff] [blame] | 13 | `bazel-bin/<package_name>/<target_name>/<target_name>_gcno` directory, |
Ulises Mendez Martinez | c2ac77f | 2022-11-15 15:11:36 +0000 | [diff] [blame] | 14 | where `<target_name>` is the name of the `kernel_build()` |
| 15 | macro. In the above example, the `.gcno` files can be found at |
| 16 | |
| 17 | ``` |
Yifan Hong | ded788d | 2023-02-08 18:43:55 +0000 | [diff] [blame] | 18 | bazel-bin/common/kernel_aarch64/kernel_aarch64_gcno/ |
| 19 | ``` |
| 20 | |
HONG Yifan | 51cdd9b | 2024-09-03 16:47:46 -0700 | [diff] [blame] | 21 | ... or in `destdir`. |
Yifan Hong | 669e430 | 2023-01-31 15:00:36 -0800 | [diff] [blame] | 22 | |
| 23 | ## Handling path mapping |
| 24 | |
| 25 | After 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 | |
| 31 | You 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 Hong | ded788d | 2023-02-08 18:43:55 +0000 | [diff] [blame] | 37 | To map between these paths to the host, consult the `gcno_mapping.<name>.json` |
Yifan Hong | 669e430 | 2023-01-31 15:00:36 -0800 | [diff] [blame] | 38 | under `bazel-bin/`. |
| 39 | |
| 40 | ### GKI |
| 41 | |
| 42 | In the above example, the file can be found after a build: |
| 43 | |
| 44 | ```shell |
| 45 | $ tools/bazel build --gcov //common:kernel_aarch64 |
| 46 | [...] |
Yifan Hong | ded788d | 2023-02-08 18:43:55 +0000 | [diff] [blame] | 47 | $ cat bazel-bin/common/kernel_aarch64/gcno_mapping.kernel_aarch64.json |
Yifan Hong | 669e430 | 2023-01-31 15:00:36 -0800 | [diff] [blame] | 48 | [...] |
| 49 | ``` |
| 50 | |
HONG Yifan | 51cdd9b | 2024-09-03 16:47:46 -0700 | [diff] [blame] | 51 | You may also find this file under `destdir`: |
Yifan Hong | 669e430 | 2023-01-31 15:00:36 -0800 | [diff] [blame] | 52 | |
| 53 | ```shell |
HONG Yifan | 51cdd9b | 2024-09-03 16:47:46 -0700 | [diff] [blame] | 54 | $ tools/bazel run //common:kernel_aarch64_dist -- --destdir=out/kernel_aarch64/dist |
Yifan Hong | 669e430 | 2023-01-31 15:00:36 -0800 | [diff] [blame] | 55 | [...] |
| 56 | $ cat out/kernel_aarch64/dist/gcno_mapping.kernel_aarch64.json |
| 57 | [...] |
| 58 | ``` |
| 59 | |
| 60 | ### Device mixed builds |
| 61 | |
| 62 | You need to consult the JSON file for the device `kernel_build`. |
| 63 | Using 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 Hong | ded788d | 2023-02-08 18:43:55 +0000 | [diff] [blame] | 68 | $ cat bazel-bin/common-modules/virtual-device/virtual_device_x86_64/gcno_mapping.virtual_device_x86_64.json |
Yifan Hong | 669e430 | 2023-01-31 15:00:36 -0800 | [diff] [blame] | 69 | [...] |
| 70 | ``` |
| 71 | |
HONG Yifan | 51cdd9b | 2024-09-03 16:47:46 -0700 | [diff] [blame] | 72 | Or under `destdir`: |
Yifan Hong | 669e430 | 2023-01-31 15:00:36 -0800 | [diff] [blame] | 73 | |
| 74 | ```shell |
HONG Yifan | 51cdd9b | 2024-09-03 16:47:46 -0700 | [diff] [blame] | 75 | $ tools/bazel run --gcov //common-modules/virtual-device:virtual_device_x86_64_dist -- --destdir=out/vd/dist |
Yifan Hong | 669e430 | 2023-01-31 15:00:36 -0800 | [diff] [blame] | 76 | [...] |
| 77 | $ cat out/vd/dist/gcno_mapping.virtual_device_x86_64.json |
| 78 | [...] |
| 79 | ``` |
| 80 | |
HONG Yifan | 51cdd9b | 2024-09-03 16:47:46 -0700 | [diff] [blame] | 81 | **Note**: You will also see `gcno_mapping.kernel_x86_64.json` under `destdir`. That file is incomplete |
Yifan Hong | 669e430 | 2023-01-31 15:00:36 -0800 | [diff] [blame] | 82 | as it does not contain mappings for in-tree modules specific for virtual device. |
| 83 | |
Yifan Hong | ded788d | 2023-02-08 18:43:55 +0000 | [diff] [blame] | 84 | ### Sample content of `gcno_mapping.<name>.json`: |
Yifan Hong | 669e430 | 2023-01-31 15:00:36 -0800 | [diff] [blame] | 85 | |
| 86 | Without `--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 | |
| 97 | With `--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 | |
| 108 | The JSON file contains a list of mappings. Each mapping indicates that the `.gcno` files |
| 109 | located in `<from>` were copied to `<to>`. Hence, `/sys/kernel/debug/<from>` |
| 110 | on the device maps to `<to>` on host. |
| 111 | |
| 112 | **Note**: For both `<from>` and `<to>`, absolute paths should be interpreted as-is, |
| 113 | and 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 | |
| 128 | This 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`. |