1 /*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 //
17 // Test if simpleperf -> create_llvm_prof can convert addresses in ETM data correctly to
18 // symbols and source lines in llvm prof data.
19 //
20 // To test address conversion for userspace binaries:
21 // 1. Generate branch list file on device:
22 // (device) $ simpleperf record -e cs-etm:u --delay 10 --duration 1 ./autofdo_addr_test
23 // (device) $ simpleperf inject -i perf.data --output branch-list -o branch_user.data
24 //
25 // 2. Generate llvm prof data on host:
26 // (host) $ simpleperf inject -i branch_user.data --symdir .
27 // (host) $ create_llvm_prof --profiler text --binary=autofdo_addr_test \
28 // --profile=perf_inject.data --out=user.profdata --format text
29 //
30 // 3. Check llvm prof data. It should show something like the following content:
31 // (host) $ cat user.profdata
32 // main:4289758:0
33 // 0: 0
34 // 1: 428974
35 // 2: 428976
36 //
37 // To test address conversion for vmlinux:
38 // 1. Generate branch list file on device:
39 // (device) $ simpleperf inject -e cs-etm:k --delay 10 --duration 1 ./autofdo_addr_test
40 // (device) $ simpleperf inject -i perf.data --output branch-list -o branch.data
41 //
42 // 2. Generate llvm prof data on host:
43 // (device) $ simpleperf inject -i branch.data --symdir .
44 // (device) $ create_llvm_prof --profiler text --binary=vmlinux --profile=perf_inject.data \
45 // --out=kernel.profdata --format text
46 //
47 // 3. Check llvm prof data. The top functions should be like the following content:
48 // (host) $ cat kernel.profdata | grep -v "^ "
49 // __arm64_sys_getpriority:24967795:0
50 // do_el0_svc:13978399:185833
51 // el0_svc:11968147:184885
52 // invoke_syscall:8962484:2843
53 // __rcu_read_unlock:8667849:200748
54 // el0_svc_common:7142648:0
55 //
56 // [TODO] Test address conversion for kernel modules
57 //
58 //
59 //
60 // Test if simpleperf -> perf2bolt can convert addresses in ETM data correctly to symbols and
61 // and offsets in perf2bolt.
62 //
63 // To test address conversion for userspace binaries:
64 // 1. Generate branch list file on device (as for create_llvm_prof)
65 // 2. Generate perf2bolt profile on host:
66 // (host) $ simpleperf inject -i branch_user.data --output bolt -o perf_inject_bolt.data \
67 // --symdir .
68 // (host) $ sed -i '1d' perf_inject_bolt.data
69 // (host) $ perf2bolt --pa -p perf_inject_bolt.data -o perf.fdata autofdo_addr_test
70 //
71 // 3. Check perf.fdata. The output should be like the following content:
72 // (host) $ cat perf.fdata
73 // 1 getpriority@PLT c 0 [unknown] 0 0 429112
74 // 1 main 10 1 getpriority@PLT 0 0 429110
75 // 1 main 14 1 main 8 0 429109
76 //
77 //
78
79 #include <sys/resource.h>
80
main()81 int main() {
82 while (true) {
83 getpriority(PRIO_PROCESS, 0);
84 }
85 return 0;
86 }
87