1*02ca8ccaSAndroid Build Coastguard WorkerHOWTO - using the library with perf {#howto_perf} 2*02ca8ccaSAndroid Build Coastguard Worker=================================== 3*02ca8ccaSAndroid Build Coastguard Worker 4*02ca8ccaSAndroid Build Coastguard Worker@brief Using command line perf and OpenCSD to collect and decode trace. 5*02ca8ccaSAndroid Build Coastguard Worker 6*02ca8ccaSAndroid Build Coastguard WorkerThis HOWTO explains how to use the perf cmd line tools and the openCSD 7*02ca8ccaSAndroid Build Coastguard Workerlibrary to collect and extract program flow traces generated by the 8*02ca8ccaSAndroid Build Coastguard WorkerCoreSight IP blocks on a Linux system. The examples have been generated using 9*02ca8ccaSAndroid Build Coastguard Workeran aarch64 Juno-r0 platform. 10*02ca8ccaSAndroid Build Coastguard Worker 11*02ca8ccaSAndroid Build Coastguard Worker 12*02ca8ccaSAndroid Build Coastguard WorkerOn Target Trace Acquisition - Perf Record 13*02ca8ccaSAndroid Build Coastguard Worker----------------------------------------- 14*02ca8ccaSAndroid Build Coastguard Worker 15*02ca8ccaSAndroid Build Coastguard WorkerCompile the perf tool from the same kernel source code version you are using with: 16*02ca8ccaSAndroid Build Coastguard Worker 17*02ca8ccaSAndroid Build Coastguard Worker make -C tools/perf 18*02ca8ccaSAndroid Build Coastguard Worker 19*02ca8ccaSAndroid Build Coastguard WorkerThis will yield a `perf` executable that will support CoreSight trace collection. 20*02ca8ccaSAndroid Build Coastguard Worker 21*02ca8ccaSAndroid Build Coastguard Worker*Note:* If traces are to be decompressed **off** target, there is no need to download 22*02ca8ccaSAndroid Build Coastguard Workerand compile the openCSD library (on the target). 23*02ca8ccaSAndroid Build Coastguard Worker 24*02ca8ccaSAndroid Build Coastguard WorkerIf you are instead planning to use perf to record and decode the trace on the target, 25*02ca8ccaSAndroid Build Coastguard Workercompile the perf tool linking against the openCSD library, in the following way: 26*02ca8ccaSAndroid Build Coastguard Worker 27*02ca8ccaSAndroid Build Coastguard Worker make -C tools/perf VF=1 CORESIGHT=1 28*02ca8ccaSAndroid Build Coastguard Worker 29*02ca8ccaSAndroid Build Coastguard WorkerFurther information on the needed build environments and options are detailed later 30*02ca8ccaSAndroid Build Coastguard Workerin the section **Off Target Perf Tools Compilation**. 31*02ca8ccaSAndroid Build Coastguard Worker 32*02ca8ccaSAndroid Build Coastguard WorkerBefore launching a trace run a sink that will collect trace data needs to be 33*02ca8ccaSAndroid Build Coastguard Workeridentified. All CoreSight blocks identified by the framework are registed in 34*02ca8ccaSAndroid Build Coastguard WorkersysFS: 35*02ca8ccaSAndroid Build Coastguard Worker 36*02ca8ccaSAndroid Build Coastguard Worker 37*02ca8ccaSAndroid Build Coastguard Worker linaro@linaro-nano:~$ ls /sys/bus/coresight/devices/ 38*02ca8ccaSAndroid Build Coastguard Worker etm0 etm2 etm4 etm6 funnel0 funnel2 funnel4 stm0 tmc_etr0 39*02ca8ccaSAndroid Build Coastguard Worker etm1 etm3 etm5 etm7 funnel1 funnel3 replicator0 tmc_etf0 40*02ca8ccaSAndroid Build Coastguard Worker 41*02ca8ccaSAndroid Build Coastguard Worker 42*02ca8ccaSAndroid Build Coastguard WorkerCoreSight blocks are listed in the device tree for a specific system and 43*02ca8ccaSAndroid Build Coastguard Workerdiscovered at boot time. Since tracers can be linked to more than one sink, 44*02ca8ccaSAndroid Build Coastguard Workerthe sink that will recieve trace data needs to be identified and given as an 45*02ca8ccaSAndroid Build Coastguard Workeroption on the perf command line. Once a sink has been identify trace collection 46*02ca8ccaSAndroid Build Coastguard Workercan start. An easy and yet interesting example is the `uname` command: 47*02ca8ccaSAndroid Build Coastguard Worker 48*02ca8ccaSAndroid Build Coastguard Worker linaro@linaro-nano:~/kernel$ ./tools/perf/perf record -e cs_etm/@tmc_etr0/ --per-thread uname 49*02ca8ccaSAndroid Build Coastguard Worker 50*02ca8ccaSAndroid Build Coastguard WorkerThis will generate a `perf.data` file where execution has been traced for both 51*02ca8ccaSAndroid Build Coastguard Workeruser and kernel space. To narrow the field to either user or kernel space the 52*02ca8ccaSAndroid Build Coastguard Worker`u` and `k` options can be specified. For example the following will limit 53*02ca8ccaSAndroid Build Coastguard Workertraces to user space: 54*02ca8ccaSAndroid Build Coastguard Worker 55*02ca8ccaSAndroid Build Coastguard Worker 56*02ca8ccaSAndroid Build Coastguard Worker linaro@linaro-nano:~/kernel$ ./tools/perf/perf record -vvv -e cs_etm/@tmc_etr0/u --per-thread uname 57*02ca8ccaSAndroid Build Coastguard Worker Problems setting modules path maps, continuing anyway... 58*02ca8ccaSAndroid Build Coastguard Worker ----------------------------------------------------------- 59*02ca8ccaSAndroid Build Coastguard Worker perf_event_attr: 60*02ca8ccaSAndroid Build Coastguard Worker type 8 61*02ca8ccaSAndroid Build Coastguard Worker size 112 62*02ca8ccaSAndroid Build Coastguard Worker { sample_period, sample_freq } 1 63*02ca8ccaSAndroid Build Coastguard Worker sample_type IP|TID|IDENTIFIER 64*02ca8ccaSAndroid Build Coastguard Worker read_format ID 65*02ca8ccaSAndroid Build Coastguard Worker disabled 1 66*02ca8ccaSAndroid Build Coastguard Worker exclude_kernel 1 67*02ca8ccaSAndroid Build Coastguard Worker exclude_hv 1 68*02ca8ccaSAndroid Build Coastguard Worker enable_on_exec 1 69*02ca8ccaSAndroid Build Coastguard Worker sample_id_all 1 70*02ca8ccaSAndroid Build Coastguard Worker ------------------------------------------------------------ 71*02ca8ccaSAndroid Build Coastguard Worker sys_perf_event_open: pid 11375 cpu -1 group_fd -1 flags 0x8 72*02ca8ccaSAndroid Build Coastguard Worker ------------------------------------------------------------ 73*02ca8ccaSAndroid Build Coastguard Worker perf_event_attr: 74*02ca8ccaSAndroid Build Coastguard Worker type 1 75*02ca8ccaSAndroid Build Coastguard Worker size 112 76*02ca8ccaSAndroid Build Coastguard Worker config 0x9 77*02ca8ccaSAndroid Build Coastguard Worker { sample_period, sample_freq } 1 78*02ca8ccaSAndroid Build Coastguard Worker sample_type IP|TID|IDENTIFIER 79*02ca8ccaSAndroid Build Coastguard Worker read_format ID 80*02ca8ccaSAndroid Build Coastguard Worker disabled 1 81*02ca8ccaSAndroid Build Coastguard Worker exclude_kernel 1 82*02ca8ccaSAndroid Build Coastguard Worker exclude_hv 1 83*02ca8ccaSAndroid Build Coastguard Worker mmap 1 84*02ca8ccaSAndroid Build Coastguard Worker comm 1 85*02ca8ccaSAndroid Build Coastguard Worker enable_on_exec 1 86*02ca8ccaSAndroid Build Coastguard Worker task 1 87*02ca8ccaSAndroid Build Coastguard Worker sample_id_all 1 88*02ca8ccaSAndroid Build Coastguard Worker mmap2 1 89*02ca8ccaSAndroid Build Coastguard Worker comm_exec 1 90*02ca8ccaSAndroid Build Coastguard Worker ------------------------------------------------------------ 91*02ca8ccaSAndroid Build Coastguard Worker sys_perf_event_open: pid 11375 cpu -1 group_fd -1 flags 0x8 92*02ca8ccaSAndroid Build Coastguard Worker mmap size 266240B 93*02ca8ccaSAndroid Build Coastguard Worker AUX area mmap length 131072 94*02ca8ccaSAndroid Build Coastguard Worker perf event ring buffer mmapped per thread 95*02ca8ccaSAndroid Build Coastguard Worker Synthesizing auxtrace information 96*02ca8ccaSAndroid Build Coastguard Worker Linux 97*02ca8ccaSAndroid Build Coastguard Worker auxtrace idx 0 old 0 head 0x11ea0 diff 0x11ea0 98*02ca8ccaSAndroid Build Coastguard Worker [ perf record: Woken up 1 times to write data ] 99*02ca8ccaSAndroid Build Coastguard Worker overlapping maps: 100*02ca8ccaSAndroid Build Coastguard Worker 7f99daf000-7f99db0000 0 [vdso] 101*02ca8ccaSAndroid Build Coastguard Worker 7f99d84000-7f99db3000 0 /lib/aarch64-linux-gnu/ld-2.21.so 102*02ca8ccaSAndroid Build Coastguard Worker 7f99d84000-7f99daf000 0 /lib/aarch64-linux-gnu/ld-2.21.so 103*02ca8ccaSAndroid Build Coastguard Worker 7f99db0000-7f99db3000 0 /lib/aarch64-linux-gnu/ld-2.21.so 104*02ca8ccaSAndroid Build Coastguard Worker failed to write feature 8 105*02ca8ccaSAndroid Build Coastguard Worker failed to write feature 9 106*02ca8ccaSAndroid Build Coastguard Worker failed to write feature 14 107*02ca8ccaSAndroid Build Coastguard Worker [ perf record: Captured and wrote 0.072 MB perf.data ] 108*02ca8ccaSAndroid Build Coastguard Worker 109*02ca8ccaSAndroid Build Coastguard Worker linaro@linaro-nano:~/kernel$ ls -l ~/.debug/ perf.data 110*02ca8ccaSAndroid Build Coastguard Worker _-rw------- 1 linaro linaro 77888 Mar 2 20:41 perf.data 111*02ca8ccaSAndroid Build Coastguard Worker 112*02ca8ccaSAndroid Build Coastguard Worker /home/linaro/.debug/: 113*02ca8ccaSAndroid Build Coastguard Worker total 16 114*02ca8ccaSAndroid Build Coastguard Worker drwxr-xr-x 2 linaro linaro 4096 Mar 2 20:40 [kernel.kallsyms] 115*02ca8ccaSAndroid Build Coastguard Worker drwxr-xr-x 2 linaro linaro 4096 Mar 2 20:40 [vdso] 116*02ca8ccaSAndroid Build Coastguard Worker drwxr-xr-x 3 linaro linaro 4096 Mar 2 20:40 bin 117*02ca8ccaSAndroid Build Coastguard Worker drwxr-xr-x 3 linaro linaro 4096 Mar 2 20:40 lib 118*02ca8ccaSAndroid Build Coastguard Worker 119*02ca8ccaSAndroid Build Coastguard WorkerTrace data filtering 120*02ca8ccaSAndroid Build Coastguard Worker-------------------- 121*02ca8ccaSAndroid Build Coastguard WorkerThe amount of traces generated by CoreSight tracers is staggering, event for 122*02ca8ccaSAndroid Build Coastguard Workerthe most simple trace scenario. Reducing trace generation to specific areas 123*02ca8ccaSAndroid Build Coastguard Workerof interest is desirable to save trace buffer space and avoid getting lost in 124*02ca8ccaSAndroid Build Coastguard Workerthe trace data that isn't relevant. Supplementing the 'k' and 'u' options 125*02ca8ccaSAndroid Build Coastguard Workerdescribed above is the notion of address filters. 126*02ca8ccaSAndroid Build Coastguard Worker 127*02ca8ccaSAndroid Build Coastguard WorkerOn CoreSight two types of address filter have been implemented - address range 128*02ca8ccaSAndroid Build Coastguard Workerand start/stop filter: 129*02ca8ccaSAndroid Build Coastguard Worker 130*02ca8ccaSAndroid Build Coastguard Worker**Address range filters:** 131*02ca8ccaSAndroid Build Coastguard WorkerWith address range filters traces are generated if the instruction pointer 132*02ca8ccaSAndroid Build Coastguard Workerfalls within the specified range. Any work done by the CPU outside of that 133*02ca8ccaSAndroid Build Coastguard Workerrange will not be traced. Address range filters can be specified for both 134*02ca8ccaSAndroid Build Coastguard Workeruser and kernel space session: 135*02ca8ccaSAndroid Build Coastguard Worker 136*02ca8ccaSAndroid Build Coastguard Worker perf record -e cs_etm/@tmc_etr0/k --filter 'filter 0xffffff8008562d0c/0x48' --per-thread uname 137*02ca8ccaSAndroid Build Coastguard Worker 138*02ca8ccaSAndroid Build Coastguard Worker perf record -e cs_etm/@tmc_etr0/u --filter 'filter 0x72c/0x40@/opt/lib/libcstest.so.1.0' --per-thread ./main 139*02ca8ccaSAndroid Build Coastguard Worker 140*02ca8ccaSAndroid Build Coastguard WorkerWhen dealing with kernel space trace addresses are typically taken in the 141*02ca8ccaSAndroid Build Coastguard Worker'System.map' file. In user space addresses are relocatable and can be 142*02ca8ccaSAndroid Build Coastguard Workerextracted from an objdump output: 143*02ca8ccaSAndroid Build Coastguard Worker 144*02ca8ccaSAndroid Build Coastguard Worker $ aarch64-linux-gnu-objdump -d libcstest.so.1.0 145*02ca8ccaSAndroid Build Coastguard Worker ... 146*02ca8ccaSAndroid Build Coastguard Worker ... 147*02ca8ccaSAndroid Build Coastguard Worker 000000000000072c <coresight_test1>: <------------ Beginning of traces 148*02ca8ccaSAndroid Build Coastguard Worker 72c: d10083ff sub sp, sp, #0x20 149*02ca8ccaSAndroid Build Coastguard Worker 730: b9000fe0 str w0, [sp,#12] 150*02ca8ccaSAndroid Build Coastguard Worker 734: b9001fff str wzr, [sp,#28] 151*02ca8ccaSAndroid Build Coastguard Worker 738: 14000007 b 754 <coresight_test1+0x28> 152*02ca8ccaSAndroid Build Coastguard Worker 73c: b9400fe0 ldr w0, [sp,#12] 153*02ca8ccaSAndroid Build Coastguard Worker 740: 11000800 add w0, w0, #0x2 154*02ca8ccaSAndroid Build Coastguard Worker 744: b9000fe0 str w0, [sp,#12] 155*02ca8ccaSAndroid Build Coastguard Worker 748: b9401fe0 ldr w0, [sp,#28] 156*02ca8ccaSAndroid Build Coastguard Worker 74c: 11000400 add w0, w0, #0x1 157*02ca8ccaSAndroid Build Coastguard Worker 750: b9001fe0 str w0, [sp,#28] 158*02ca8ccaSAndroid Build Coastguard Worker 754: b9401fe0 ldr w0, [sp,#28] 159*02ca8ccaSAndroid Build Coastguard Worker 758: 7100101f cmp w0, #0x4 160*02ca8ccaSAndroid Build Coastguard Worker 75c: 54ffff0d b.le 73c <coresight_test1+0x10> 161*02ca8ccaSAndroid Build Coastguard Worker 760: b9400fe0 ldr w0, [sp,#12] 162*02ca8ccaSAndroid Build Coastguard Worker 764: 910083ff add sp, sp, #0x20 163*02ca8ccaSAndroid Build Coastguard Worker 768: d65f03c0 ret 164*02ca8ccaSAndroid Build Coastguard Worker ... 165*02ca8ccaSAndroid Build Coastguard Worker ... 166*02ca8ccaSAndroid Build Coastguard Worker 167*02ca8ccaSAndroid Build Coastguard WorkerFollowing the address the amount of byte is specified and if tracing in user 168*02ca8ccaSAndroid Build Coastguard Workerspace, the full path to the binary (or library) being traced. 169*02ca8ccaSAndroid Build Coastguard Worker 170*02ca8ccaSAndroid Build Coastguard Worker**Start/Stop filters:** 171*02ca8ccaSAndroid Build Coastguard WorkerWith start/stop filters traces are generated when the instruction pointer is 172*02ca8ccaSAndroid Build Coastguard Workerequal to the start address. Incidentally traces stop being generated when the 173*02ca8ccaSAndroid Build Coastguard Workerinsruction pointer is equal to the stop address. Anything that happens between 174*02ca8ccaSAndroid Build Coastguard Workerthere to events is traced: 175*02ca8ccaSAndroid Build Coastguard Worker 176*02ca8ccaSAndroid Build Coastguard Worker perf record -e cs_etm/@tmc_etr0/k --filter 'start 0xffffff800856bc50,stop 0xffffff800856bcb0' --per-thread uname 177*02ca8ccaSAndroid Build Coastguard Worker 178*02ca8ccaSAndroid Build Coastguard Worker perf record -vvv -e cs_etm/@tmc_etr0/u --filter 'start 0x72c@/opt/lib/libcstest.so.1.0, \ 179*02ca8ccaSAndroid Build Coastguard Worker stop 0x40082c@/home/linaro/main' \ 180*02ca8ccaSAndroid Build Coastguard Worker --per-thread ./main 181*02ca8ccaSAndroid Build Coastguard Worker 182*02ca8ccaSAndroid Build Coastguard Worker**Limitation on address filters:** 183*02ca8ccaSAndroid Build Coastguard WorkerThe only limitation on address filters is the amount of address comparator 184*02ca8ccaSAndroid Build Coastguard Workerfound on an implementation and the mutual exclusion between range and 185*02ca8ccaSAndroid Build Coastguard Workerstart stop filters. As such the following example would _not_ work: 186*02ca8ccaSAndroid Build Coastguard Worker 187*02ca8ccaSAndroid Build Coastguard Worker perf record -e cs_etm/@tmc_etr0/k --filter 'start 0xffffff800856bc50,stop 0xffffff800856bcb0, \ // start/stop 188*02ca8ccaSAndroid Build Coastguard Worker filter 0x72c/0x40@/opt/lib/libcstest.so.1.0' \ // address range 189*02ca8ccaSAndroid Build Coastguard Worker --per-thread uname 190*02ca8ccaSAndroid Build Coastguard Worker 191*02ca8ccaSAndroid Build Coastguard WorkerAdditional Trace Options 192*02ca8ccaSAndroid Build Coastguard Worker------------------------ 193*02ca8ccaSAndroid Build Coastguard WorkerAdditional options can be used during trace collection that add information to the captured trace. 194*02ca8ccaSAndroid Build Coastguard Worker 195*02ca8ccaSAndroid Build Coastguard Worker- Timestamps: These packets are added to the trace streams to allow correlation of different sources where tools support this. 196*02ca8ccaSAndroid Build Coastguard Worker- Cycle Counts: These packets are added to get a count of cycles for blocks of executed instructions. Adding cycle counts will considerably increase the amount of generated trace. 197*02ca8ccaSAndroid Build Coastguard WorkerThe relationship between cycle counts and executed instructions differs according to the trace protocol. 198*02ca8ccaSAndroid Build Coastguard WorkerFor example, the ETMv4 protocol will emit counts for groups of instructions according to a minimum count threshold. 199*02ca8ccaSAndroid Build Coastguard WorkerPresently this threshold is fixed at 256 cycles for `perf record`. 200*02ca8ccaSAndroid Build Coastguard Worker 201*02ca8ccaSAndroid Build Coastguard WorkerCommand line options in `perf record` to use these features are part of the options for the `cs_etm` event: 202*02ca8ccaSAndroid Build Coastguard Worker 203*02ca8ccaSAndroid Build Coastguard Worker perf record -e cs_etm/timestamp,cycacc,@tmc_etr0/ --per-thread uname 204*02ca8ccaSAndroid Build Coastguard Worker 205*02ca8ccaSAndroid Build Coastguard WorkerAt current version, `perf record` and `perf script` do not use this additional information. 206*02ca8ccaSAndroid Build Coastguard Worker 207*02ca8ccaSAndroid Build Coastguard WorkerThe cs_etm perf event 208*02ca8ccaSAndroid Build Coastguard Worker--------------------- 209*02ca8ccaSAndroid Build Coastguard Worker 210*02ca8ccaSAndroid Build Coastguard WorkerSystem information for this perf pmu event can be found at: 211*02ca8ccaSAndroid Build Coastguard Worker 212*02ca8ccaSAndroid Build Coastguard Worker /sys/devices/cs_etm 213*02ca8ccaSAndroid Build Coastguard Worker 214*02ca8ccaSAndroid Build Coastguard WorkerThis contains internal format of the parameters described above: 215*02ca8ccaSAndroid Build Coastguard Worker 216*02ca8ccaSAndroid Build Coastguard Worker root@linaro-developer:~# ls /sys/devices/cs_etm/format 217*02ca8ccaSAndroid Build Coastguard Worker contextid cycacc retstack sinkid timestamp 218*02ca8ccaSAndroid Build Coastguard Worker 219*02ca8ccaSAndroid Build Coastguard Workerand names of registered sinks: 220*02ca8ccaSAndroid Build Coastguard Worker 221*02ca8ccaSAndroid Build Coastguard Worker root@linaro-developer:~# ls /sys/devices/cs_etm/sinks 222*02ca8ccaSAndroid Build Coastguard Worker tmc_etf0 tmc_etr0 tpiu0 223*02ca8ccaSAndroid Build Coastguard Worker 224*02ca8ccaSAndroid Build Coastguard WorkerNote: The `sinkid` parameter is there to document the usage of a 32-bit internal parameter to 225*02ca8ccaSAndroid Build Coastguard Workerpass the sink name used in the cs_etm/@sink/ command to the kernel drivers. It can be used 226*02ca8ccaSAndroid Build Coastguard Workerdirectly as cs_etm/sinkid=<hash_value>/ but this is not recommended as the values used are 227*02ca8ccaSAndroid Build Coastguard Workerconsidered opaque and subject to changes. 228*02ca8ccaSAndroid Build Coastguard Worker 229*02ca8ccaSAndroid Build Coastguard WorkerOn Target Trace Collection 230*02ca8ccaSAndroid Build Coastguard Worker-------------------------- 231*02ca8ccaSAndroid Build Coastguard WorkerThe entire program flow will have been recorded in the `perf.data` file. 232*02ca8ccaSAndroid Build Coastguard WorkerInformation about libraries and executable is stored under `$HOME/.debug`: 233*02ca8ccaSAndroid Build Coastguard Worker 234*02ca8ccaSAndroid Build Coastguard Worker linaro@linaro-nano:~/kernel$ tree ~/.debug 235*02ca8ccaSAndroid Build Coastguard Worker .debug 236*02ca8ccaSAndroid Build Coastguard Worker ├── [kernel.kallsyms] 237*02ca8ccaSAndroid Build Coastguard Worker │ └── 0542921808098d591a7acba5a1163e8991897669 238*02ca8ccaSAndroid Build Coastguard Worker │ └── kallsyms 239*02ca8ccaSAndroid Build Coastguard Worker ├── [vdso] 240*02ca8ccaSAndroid Build Coastguard Worker │ └── 551fbbe29579eb63be3178a04c16830b8d449769 241*02ca8ccaSAndroid Build Coastguard Worker │ └── vdso 242*02ca8ccaSAndroid Build Coastguard Worker ├── bin 243*02ca8ccaSAndroid Build Coastguard Worker │ └── uname 244*02ca8ccaSAndroid Build Coastguard Worker │ └── ed95e81f97c4471fb2ccc21e356b780eb0c92676 245*02ca8ccaSAndroid Build Coastguard Worker │ └── elf 246*02ca8ccaSAndroid Build Coastguard Worker └── lib 247*02ca8ccaSAndroid Build Coastguard Worker └── aarch64-linux-gnu 248*02ca8ccaSAndroid Build Coastguard Worker ├── ld-2.21.so 249*02ca8ccaSAndroid Build Coastguard Worker │ └── 94912dc5a1dc8c7ef2c4e4649d4b1639b6ebc8b7 250*02ca8ccaSAndroid Build Coastguard Worker │ └── elf 251*02ca8ccaSAndroid Build Coastguard Worker └── libc-2.21.so 252*02ca8ccaSAndroid Build Coastguard Worker └── 169a143e9c40cfd9d09695333e45fd67743cd2d6 253*02ca8ccaSAndroid Build Coastguard Worker └── elf 254*02ca8ccaSAndroid Build Coastguard Worker 255*02ca8ccaSAndroid Build Coastguard Worker 13 directories, 5 files 256*02ca8ccaSAndroid Build Coastguard Worker linaro@linaro-nano:~/kernel$ 257*02ca8ccaSAndroid Build Coastguard Worker 258*02ca8ccaSAndroid Build Coastguard Worker 259*02ca8ccaSAndroid Build Coastguard WorkerAll this information needs to be collected in order to successfully decode 260*02ca8ccaSAndroid Build Coastguard Workertraces off target: 261*02ca8ccaSAndroid Build Coastguard Worker 262*02ca8ccaSAndroid Build Coastguard Worker linaro@linaro-nano:~/kernel$ tar czf uname.trace.tgz perf.data ~/.debug 263*02ca8ccaSAndroid Build Coastguard Worker 264*02ca8ccaSAndroid Build Coastguard Worker 265*02ca8ccaSAndroid Build Coastguard WorkerNote that file `vmlinux` should also be added to the bundle if kernel traces 266*02ca8ccaSAndroid Build Coastguard Workerhave also been collected. 267*02ca8ccaSAndroid Build Coastguard Worker 268*02ca8ccaSAndroid Build Coastguard Worker 269*02ca8ccaSAndroid Build Coastguard WorkerOff Target OpenCSD Compilation 270*02ca8ccaSAndroid Build Coastguard Worker------------------------------ 271*02ca8ccaSAndroid Build Coastguard WorkerThe openCSD library is not part of the perf tools. It is available on 272*02ca8ccaSAndroid Build Coastguard Worker[github][1] and needs to be compiled before the perf tools. Checkout the 273*02ca8ccaSAndroid Build Coastguard Workerrequired branch/tag version into a local directory. 274*02ca8ccaSAndroid Build Coastguard Worker 275*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight$ git clone https://github.com/Linaro/OpenCSD.git my-opencsd 276*02ca8ccaSAndroid Build Coastguard Worker Cloning into 'OpenCSD'... 277*02ca8ccaSAndroid Build Coastguard Worker remote: Counting objects: 2063, done. 278*02ca8ccaSAndroid Build Coastguard Worker remote: Total 2063 (delta 0), reused 0 (delta 0), pack-reused 2063 279*02ca8ccaSAndroid Build Coastguard Worker Receiving objects: 100% (2063/2063), 2.51 MiB | 1.24 MiB/s, done. 280*02ca8ccaSAndroid Build Coastguard Worker Resolving deltas: 100% (1399/1399), done. 281*02ca8ccaSAndroid Build Coastguard Worker Checking connectivity... done. 282*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight$ ls my-opencsd 283*02ca8ccaSAndroid Build Coastguard Worker decoder LICENSE README.md HOWTO.md TODO 284*02ca8ccaSAndroid Build Coastguard Worker 285*02ca8ccaSAndroid Build Coastguard WorkerOnce the source code has been acquired compilation of the openCSD library can 286*02ca8ccaSAndroid Build Coastguard Workertake place. For Linux two options are available, LINUX and LINUX64, based on 287*02ca8ccaSAndroid Build Coastguard Workerthe host's (which has nothing to do with the target) architecture: 288*02ca8ccaSAndroid Build Coastguard Worker 289*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/$ cd my-opencsd/decoder/build/linux/ 290*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/my-opencsd/decoder/build/linux$ ls 291*02ca8ccaSAndroid Build Coastguard Worker makefile rctdl_c_api_lib ref_trace_decode_lib 292*02ca8ccaSAndroid Build Coastguard Worker 293*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/my-opencsd/decoder/build/linux$ make LINUX64=1 DEBUG=1 294*02ca8ccaSAndroid Build Coastguard Worker ... 295*02ca8ccaSAndroid Build Coastguard Worker ... 296*02ca8ccaSAndroid Build Coastguard Worker 297*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/my-opencsd/decoder/build/linux$ ls ../../lib/linux64/dbg/ 298*02ca8ccaSAndroid Build Coastguard Worker libopencsd.a libopencsd_c_api.a libopencsd_c_api.so libopencsd.so 299*02ca8ccaSAndroid Build Coastguard Worker 300*02ca8ccaSAndroid Build Coastguard WorkerFrom there the header file and libraries need to be installed on the system, 301*02ca8ccaSAndroid Build Coastguard Workersomething that requires root privileges. The default installation path is 302*02ca8ccaSAndroid Build Coastguard Worker/usr/include/opencsd for the header files and /usr/lib/ for the libraries: 303*02ca8ccaSAndroid Build Coastguard Worker 304*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/my-opencsd/decoder/build/linux$ sudo make install 305*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/my-opencsd/decoder/build/linux$ ls -l /usr/include/opencsd 306*02ca8ccaSAndroid Build Coastguard Worker total 60 307*02ca8ccaSAndroid Build Coastguard Worker drwxr-xr-x 2 root root 4096 Dec 12 10:19 c_api 308*02ca8ccaSAndroid Build Coastguard Worker drwxr-xr-x 2 root root 4096 Dec 12 10:19 etmv3 309*02ca8ccaSAndroid Build Coastguard Worker drwxr-xr-x 2 root root 4096 Dec 12 10:19 etmv4 310*02ca8ccaSAndroid Build Coastguard Worker -rw-r--r-- 1 root root 28049 Dec 12 10:19 ocsd_if_types.h 311*02ca8ccaSAndroid Build Coastguard Worker drwxr-xr-x 2 root root 4096 Dec 12 10:19 ptm 312*02ca8ccaSAndroid Build Coastguard Worker drwxr-xr-x 2 root root 4096 Dec 12 10:19 stm 313*02ca8ccaSAndroid Build Coastguard Worker -rw-r--r-- 1 root root 7264 Dec 12 10:19 trc_gen_elem_types.h 314*02ca8ccaSAndroid Build Coastguard Worker -rw-r--r-- 1 root root 3972 Dec 12 10:19 trc_pkt_types.h 315*02ca8ccaSAndroid Build Coastguard Worker 316*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/my-opencsd/decoder/build/linux$ ls -l /usr/lib/libopencsd* 317*02ca8ccaSAndroid Build Coastguard Worker -rw-r--r-- 1 root root 598720 Dec 12 10:19 /usr/lib/libopencsd_c_api.so 318*02ca8ccaSAndroid Build Coastguard Worker -rw-r--r-- 1 root root 4692200 Dec 12 10:19 /usr/lib/libopencsd.so 319*02ca8ccaSAndroid Build Coastguard Worker 320*02ca8ccaSAndroid Build Coastguard WorkerA "clean_install" target is also available so that openCSD installed files can 321*02ca8ccaSAndroid Build Coastguard Workerbe removed from a system. Going forward the goal is to have the openCSD library 322*02ca8ccaSAndroid Build Coastguard Workerpackaged as a Debian or RPM archive so that it can be installed from a 323*02ca8ccaSAndroid Build Coastguard Workerdistribution without having to be compiled. 324*02ca8ccaSAndroid Build Coastguard Worker 325*02ca8ccaSAndroid Build Coastguard Worker 326*02ca8ccaSAndroid Build Coastguard WorkerOff Target Perf Tools Compilation 327*02ca8ccaSAndroid Build Coastguard Worker--------------------------------- 328*02ca8ccaSAndroid Build Coastguard Worker 329*02ca8ccaSAndroid Build Coastguard WorkerAs mentioned above the openCSD library is not part of the perf tools' code base 330*02ca8ccaSAndroid Build Coastguard Workerand needs to be installed on a system prior to compilation. Information about 331*02ca8ccaSAndroid Build Coastguard Workerthe status of the openCSD library on a system is given at compile time by the 332*02ca8ccaSAndroid Build Coastguard Workerperf tools build script: 333*02ca8ccaSAndroid Build Coastguard Worker 334*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/linux-kernel$ make CORESIGHT=1 VF=1 -C tools/perf 335*02ca8ccaSAndroid Build Coastguard Worker Auto-detecting system features: 336*02ca8ccaSAndroid Build Coastguard Worker ... dwarf: [ on ] 337*02ca8ccaSAndroid Build Coastguard Worker ... dwarf_getlocations: [ on ] 338*02ca8ccaSAndroid Build Coastguard Worker ... glibc: [ on ] 339*02ca8ccaSAndroid Build Coastguard Worker ... gtk2: [ on ] 340*02ca8ccaSAndroid Build Coastguard Worker ... libaudit: [ on ] 341*02ca8ccaSAndroid Build Coastguard Worker ... libbfd: [ OFF ] 342*02ca8ccaSAndroid Build Coastguard Worker ... libelf: [ on ] 343*02ca8ccaSAndroid Build Coastguard Worker ... libnuma: [ OFF ] 344*02ca8ccaSAndroid Build Coastguard Worker ... numa_num_possible_cpus: [ OFF ] 345*02ca8ccaSAndroid Build Coastguard Worker ... libperl: [ on ] 346*02ca8ccaSAndroid Build Coastguard Worker ... libpython: [ on ] 347*02ca8ccaSAndroid Build Coastguard Worker ... libslang: [ on ] 348*02ca8ccaSAndroid Build Coastguard Worker ... libcrypto: [ on ] 349*02ca8ccaSAndroid Build Coastguard Worker ... libunwind: [ OFF ] 350*02ca8ccaSAndroid Build Coastguard Worker ... libdw-dwarf-unwind: [ on ] 351*02ca8ccaSAndroid Build Coastguard Worker ... zlib: [ on ] 352*02ca8ccaSAndroid Build Coastguard Worker ... lzma: [ OFF ] 353*02ca8ccaSAndroid Build Coastguard Worker ... get_cpuid: [ on ] 354*02ca8ccaSAndroid Build Coastguard Worker ... bpf: [ on ] 355*02ca8ccaSAndroid Build Coastguard Worker ... libopencsd: [ on ] <------- 356*02ca8ccaSAndroid Build Coastguard Worker 357*02ca8ccaSAndroid Build Coastguard Worker 358*02ca8ccaSAndroid Build Coastguard WorkerAt the end of the compilation a new perf binary is available in `tools/perf/`: 359*02ca8ccaSAndroid Build Coastguard Worker 360*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/linux-kernel$ ldd tools/perf/perf 361*02ca8ccaSAndroid Build Coastguard Worker linux-vdso.so.1 => (0x00007fff135db000) 362*02ca8ccaSAndroid Build Coastguard Worker libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f15f9176000) 363*02ca8ccaSAndroid Build Coastguard Worker librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f15f8f6e000) 364*02ca8ccaSAndroid Build Coastguard Worker libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f15f8c64000) 365*02ca8ccaSAndroid Build Coastguard Worker libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f15f8a60000) 366*02ca8ccaSAndroid Build Coastguard Worker libopencsd_c_api.so => /usr/lib/libopencsd_c_api.so (0x00007f15f884e000) <------- 367*02ca8ccaSAndroid Build Coastguard Worker libelf.so.1 => /usr/lib/x86_64-linux-gnu/libelf.so.1 (0x00007f15f8635000) 368*02ca8ccaSAndroid Build Coastguard Worker libdw.so.1 => /usr/lib/x86_64-linux-gnu/libdw.so.1 (0x00007f15f83ec000) 369*02ca8ccaSAndroid Build Coastguard Worker libaudit.so.1 => /lib/x86_64-linux-gnu/libaudit.so.1 (0x00007f15f81c5000) 370*02ca8ccaSAndroid Build Coastguard Worker libslang.so.2 => /lib/x86_64-linux-gnu/libslang.so.2 (0x00007f15f7e38000) 371*02ca8ccaSAndroid Build Coastguard Worker libperl.so.5.22 => /usr/lib/x86_64-linux-gnu/libperl.so.5.22 (0x00007f15f7a5d000) 372*02ca8ccaSAndroid Build Coastguard Worker libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f15f7693000) 373*02ca8ccaSAndroid Build Coastguard Worker libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007f15f7104000) 374*02ca8ccaSAndroid Build Coastguard Worker libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f15f6eea000) 375*02ca8ccaSAndroid Build Coastguard Worker /lib64/ld-linux-x86-64.so.2 (0x0000559b88038000) 376*02ca8ccaSAndroid Build Coastguard Worker libopencsd.so => /usr/lib/libopencsd.so (0x00007f15f6c62000) <------- 377*02ca8ccaSAndroid Build Coastguard Worker libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f15f68df000) 378*02ca8ccaSAndroid Build Coastguard Worker libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f15f66c9000) 379*02ca8ccaSAndroid Build Coastguard Worker liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f15f64a6000) 380*02ca8ccaSAndroid Build Coastguard Worker libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f15f6296000) 381*02ca8ccaSAndroid Build Coastguard Worker libcrypt.so.1 => /lib/x86_64-linux-gnu/libcrypt.so.1 (0x00007f15f605e000) 382*02ca8ccaSAndroid Build Coastguard Worker libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f15f5e5a000) 383*02ca8ccaSAndroid Build Coastguard Worker 384*02ca8ccaSAndroid Build Coastguard Worker 385*02ca8ccaSAndroid Build Coastguard WorkerAdditional debug output from the decoder can be compiled in by setting the 386*02ca8ccaSAndroid Build Coastguard Worker`CSTRACE_RAW` environment variable. Setting this to `packed` gets trace frame 387*02ca8ccaSAndroid Build Coastguard Workeroutput as follows:- 388*02ca8ccaSAndroid Build Coastguard Worker 389*02ca8ccaSAndroid Build Coastguard Worker Frame Data; Index 576; RAW_PACKED; d6 d6 d6 d6 d6 d6 d6 d6 fc fb d6 d6 d6 d6 e0 7f 390*02ca8ccaSAndroid Build Coastguard Worker Frame Data; Index 576; ID_DATA[0x14]; d7 d6 d7 d6 d7 d6 d7 d6 fd fb d7 d6 d7 d6 e0 391*02ca8ccaSAndroid Build Coastguard Worker 392*02ca8ccaSAndroid Build Coastguard WorkerSet to any other value will remove the RAW_PACKED lines. 393*02ca8ccaSAndroid Build Coastguard Worker 394*02ca8ccaSAndroid Build Coastguard WorkerWorking with an alternate version of the openCSD library 395*02ca8ccaSAndroid Build Coastguard Worker-------------------------------------------------------- 396*02ca8ccaSAndroid Build Coastguard WorkerWhen compiling the perf tools it is possible to reference another version of 397*02ca8ccaSAndroid Build Coastguard Workerthe openCSD library than the one installed on the system. This is useful when 398*02ca8ccaSAndroid Build Coastguard Workerworking with multiple development trees or having the desire to keep system 399*02ca8ccaSAndroid Build Coastguard Workerlibraries intact. Two environment variable are available to tell the perf tools 400*02ca8ccaSAndroid Build Coastguard Workerbuild script where to get the header file and libraries, namely CSINCLUDES and 401*02ca8ccaSAndroid Build Coastguard WorkerCSLIBS: 402*02ca8ccaSAndroid Build Coastguard Worker 403*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/linux-kernel$ export CSINCLUDES=~/linaro/coresight/my-opencsd/decoder/include/ 404*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/linux-kernel$ export CSLIBS=~/linaro/coresight/my-opencsd/decoder/lib/builddir/ 405*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/linux-kernel$ make CORESIGHT=1 VF=1 -C tools/perf 406*02ca8ccaSAndroid Build Coastguard Worker 407*02ca8ccaSAndroid Build Coastguard WorkerThis will have the effect of compiling and linking against the provided library. 408*02ca8ccaSAndroid Build Coastguard WorkerSince the system's openCSD library is in the loader's search patch the 409*02ca8ccaSAndroid Build Coastguard WorkerLD_LIBRARY_PATH environment variable needs to be set. 410*02ca8ccaSAndroid Build Coastguard Worker 411*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/linux-kernel$ export LD_LIBRARY_PATH=$CSLIBS 412*02ca8ccaSAndroid Build Coastguard Worker 413*02ca8ccaSAndroid Build Coastguard Worker 414*02ca8ccaSAndroid Build Coastguard WorkerTrace Decoding with Perf Report 415*02ca8ccaSAndroid Build Coastguard Worker------------------------------- 416*02ca8ccaSAndroid Build Coastguard WorkerBefore working with custom traces it is suggested to use a trace bundle that 417*02ca8ccaSAndroid Build Coastguard Workeris known to be working properly. A sample bundle has been made available 418*02ca8ccaSAndroid Build Coastguard Workerhere [2]. Trace bundles can be extracted anywhere and have no dependencies on 419*02ca8ccaSAndroid Build Coastguard Workerwhere the perf tools and openCSD library have been compiled. 420*02ca8ccaSAndroid Build Coastguard Worker 421*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight$ mkdir sept20 422*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight$ cd sept20 423*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ wget http://people.linaro.org/~mathieu.poirier/openCSD/uname.v4.user.sept20.tgz 424*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ md5sum uname.v4.user.sept20.tgz 425*02ca8ccaSAndroid Build Coastguard Worker f53f11d687ce72bdbe9de2e67e960ec6 uname.v4.user.sept20.tgz 426*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ tar xf uname.v4.user.sept20.tgz 427*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ ls -la 428*02ca8ccaSAndroid Build Coastguard Worker total 1312 429*02ca8ccaSAndroid Build Coastguard Worker drwxrwxr-x 3 linaro linaro 4096 Mar 3 10:26 . 430*02ca8ccaSAndroid Build Coastguard Worker drwxrwxr-x 5 linaro linaro 4096 Mar 3 10:13 .. 431*02ca8ccaSAndroid Build Coastguard Worker drwxr-xr-x 7 linaro linaro 4096 Feb 24 12:21 .debug 432*02ca8ccaSAndroid Build Coastguard Worker -rw------- 1 linaro linaro 78016 Feb 24 12:21 perf.data 433*02ca8ccaSAndroid Build Coastguard Worker -rw-rw-r-- 1 linaro linaro 1245881 Feb 24 12:25 uname.v4.user.sept20.tgz 434*02ca8ccaSAndroid Build Coastguard Worker 435*02ca8ccaSAndroid Build Coastguard WorkerPerf is expecting files related to the trace capture (`perf.data`) to be located in the `buildid` directory. 436*02ca8ccaSAndroid Build Coastguard WorkerBy default this is under `~/.debug`. Alternatively the default `buildid` directory can be changed 437*02ca8ccaSAndroid Build Coastguard Workerusing the command: 438*02ca8ccaSAndroid Build Coastguard Worker 439*02ca8ccaSAndroid Build Coastguard Worker perf config --system buildid.dir=/my/own/buildid/dir 440*02ca8ccaSAndroid Build Coastguard Worker 441*02ca8ccaSAndroid Build Coastguard WorkerThis example will remove the current `~/.debug` directory to be sure everything is clean. 442*02ca8ccaSAndroid Build Coastguard Worker 443*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ rm -rf ~/.debug 444*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ cp -dpR .debug ~/ 445*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ ../perf-opencsd-master/tools/perf/perf report --stdio 446*02ca8ccaSAndroid Build Coastguard Worker 447*02ca8ccaSAndroid Build Coastguard Worker # To display the perf.data header info, please use --header/--header-only options. 448*02ca8ccaSAndroid Build Coastguard Worker # 449*02ca8ccaSAndroid Build Coastguard Worker # 450*02ca8ccaSAndroid Build Coastguard Worker # Total Lost Samples: 0 451*02ca8ccaSAndroid Build Coastguard Worker # 452*02ca8ccaSAndroid Build Coastguard Worker # Samples: 0 of event 'cs_etm//u' 453*02ca8ccaSAndroid Build Coastguard Worker # Event count (approx.): 0 454*02ca8ccaSAndroid Build Coastguard Worker # 455*02ca8ccaSAndroid Build Coastguard Worker # Children Self Command Shared Object Symbol 456*02ca8ccaSAndroid Build Coastguard Worker # ........ ........ ....... ............. ...... 457*02ca8ccaSAndroid Build Coastguard Worker # 458*02ca8ccaSAndroid Build Coastguard Worker 459*02ca8ccaSAndroid Build Coastguard Worker 460*02ca8ccaSAndroid Build Coastguard Worker # Samples: 0 of event 'dummy:u' 461*02ca8ccaSAndroid Build Coastguard Worker # Event count (approx.): 0 462*02ca8ccaSAndroid Build Coastguard Worker # 463*02ca8ccaSAndroid Build Coastguard Worker # Children Self Command Shared Object Symbol 464*02ca8ccaSAndroid Build Coastguard Worker # ........ ........ ....... ............. ...... 465*02ca8ccaSAndroid Build Coastguard Worker # 466*02ca8ccaSAndroid Build Coastguard Worker 467*02ca8ccaSAndroid Build Coastguard Worker 468*02ca8ccaSAndroid Build Coastguard Worker # Samples: 115K of event 'instructions:u' 469*02ca8ccaSAndroid Build Coastguard Worker # Event count (approx.): 522009 470*02ca8ccaSAndroid Build Coastguard Worker # 471*02ca8ccaSAndroid Build Coastguard Worker # Children Self Command Shared Object Symbol 472*02ca8ccaSAndroid Build Coastguard Worker # ........ ........ ....... ................ ...................... 473*02ca8ccaSAndroid Build Coastguard Worker # 474*02ca8ccaSAndroid Build Coastguard Worker 4.13% 4.13% uname libc-2.21.so [.] 0x0000000000078758 475*02ca8ccaSAndroid Build Coastguard Worker 3.81% 3.81% uname libc-2.21.so [.] 0x0000000000078e50 476*02ca8ccaSAndroid Build Coastguard Worker 2.06% 2.06% uname libc-2.21.so [.] 0x00000000000fcaf4 477*02ca8ccaSAndroid Build Coastguard Worker 1.65% 1.65% uname libc-2.21.so [.] 0x00000000000fcae4 478*02ca8ccaSAndroid Build Coastguard Worker 1.59% 1.59% uname ld-2.21.so [.] 0x000000000000a7f4 479*02ca8ccaSAndroid Build Coastguard Worker 1.50% 1.50% uname libc-2.21.so [.] 0x0000000000078e40 480*02ca8ccaSAndroid Build Coastguard Worker 1.43% 1.43% uname libc-2.21.so [.] 0x00000000000fcac4 481*02ca8ccaSAndroid Build Coastguard Worker 1.31% 1.31% uname libc-2.21.so [.] 0x000000000002f0c0 482*02ca8ccaSAndroid Build Coastguard Worker 1.26% 1.26% uname ld-2.21.so [.] 0x0000000000016888 483*02ca8ccaSAndroid Build Coastguard Worker 1.24% 1.24% uname libc-2.21.so [.] 0x0000000000078e7c 484*02ca8ccaSAndroid Build Coastguard Worker 1.24% 1.24% uname libc-2.21.so [.] 0x00000000000fcab8 485*02ca8ccaSAndroid Build Coastguard Worker ... 486*02ca8ccaSAndroid Build Coastguard Worker 487*02ca8ccaSAndroid Build Coastguard WorkerAdditional data can be obtained, which contains a dump of the trace packets received using the command 488*02ca8ccaSAndroid Build Coastguard Worker 489*02ca8ccaSAndroid Build Coastguard Worker mjl@ubuntu-vbox:./perf-opencsd-master/coresight/tools/perf/perf report --stdio --dump 490*02ca8ccaSAndroid Build Coastguard Worker 491*02ca8ccaSAndroid Build Coastguard Workerresulting a large amount of data, trace looking like:- 492*02ca8ccaSAndroid Build Coastguard Worker 493*02ca8ccaSAndroid Build Coastguard Worker 0x618 [0x30]: PERF_RECORD_AUXTRACE size: 0x11ef0 offset: 0 ref: 0x4d881c1f13216016 idx: 0 tid: 15244 cpu: -1 494*02ca8ccaSAndroid Build Coastguard Worker 495*02ca8ccaSAndroid Build Coastguard Worker . ... CoreSight ETM Trace data: size 73456 bytes 496*02ca8ccaSAndroid Build Coastguard Worker 497*02ca8ccaSAndroid Build Coastguard Worker 0: I_ASYNC : Alignment Synchronisation. 498*02ca8ccaSAndroid Build Coastguard Worker 12: I_TRACE_INFO : Trace Info. 499*02ca8ccaSAndroid Build Coastguard Worker 17: I_TRACE_ON : Trace On. 500*02ca8ccaSAndroid Build Coastguard Worker 18: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0x0000007F89F24D80; Ctxt: AArch64,EL0, NS; 501*02ca8ccaSAndroid Build Coastguard Worker 28: I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE 502*02ca8ccaSAndroid Build Coastguard Worker 29: I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE 503*02ca8ccaSAndroid Build Coastguard Worker 30: I_ATOM_F6 : Atom format 6.; EEEEEEEEEEEEEEEEEEEEEEEE 504*02ca8ccaSAndroid Build Coastguard Worker 32: I_ATOM_F6 : Atom format 6.; EEEEN 505*02ca8ccaSAndroid Build Coastguard Worker 33: I_ATOM_F1 : Atom format 1.; E 506*02ca8ccaSAndroid Build Coastguard Worker 34: I_EXCEPT : Exception.; Data Fault; Ret Addr Follows; 507*02ca8ccaSAndroid Build Coastguard Worker 36: I_ADDR_L_64IS0 : Address, Long, 64 bit, IS0.; Addr=0x0000007F89F2832C; 508*02ca8ccaSAndroid Build Coastguard Worker 45: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0xFFFFFFC000083400; Ctxt: AArch64,EL1, NS; 509*02ca8ccaSAndroid Build Coastguard Worker 56: I_TRACE_ON : Trace On. 510*02ca8ccaSAndroid Build Coastguard Worker 57: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0x0000007F89F2832C; Ctxt: AArch64,EL0, NS; 511*02ca8ccaSAndroid Build Coastguard Worker 68: I_ATOM_F3 : Atom format 3.; NEE 512*02ca8ccaSAndroid Build Coastguard Worker 69: I_ATOM_F3 : Atom format 3.; NEN 513*02ca8ccaSAndroid Build Coastguard Worker 70: I_ATOM_F3 : Atom format 3.; NNE 514*02ca8ccaSAndroid Build Coastguard Worker 71: I_ATOM_F5 : Atom format 5.; ENENE 515*02ca8ccaSAndroid Build Coastguard Worker 72: I_ATOM_F5 : Atom format 5.; NENEN 516*02ca8ccaSAndroid Build Coastguard Worker 73: I_ATOM_F5 : Atom format 5.; ENENE 517*02ca8ccaSAndroid Build Coastguard Worker 74: I_ATOM_F5 : Atom format 5.; NENEN 518*02ca8ccaSAndroid Build Coastguard Worker 75: I_ATOM_F5 : Atom format 5.; ENENE 519*02ca8ccaSAndroid Build Coastguard Worker 76: I_ATOM_F3 : Atom format 3.; NNE 520*02ca8ccaSAndroid Build Coastguard Worker 77: I_ATOM_F3 : Atom format 3.; NNE 521*02ca8ccaSAndroid Build Coastguard Worker 78: I_ATOM_F3 : Atom format 3.; NNE 522*02ca8ccaSAndroid Build Coastguard Worker 80: I_ATOM_F3 : Atom format 3.; NNE 523*02ca8ccaSAndroid Build Coastguard Worker 81: I_ATOM_F3 : Atom format 3.; ENN 524*02ca8ccaSAndroid Build Coastguard Worker 82: I_EXCEPT : Exception.; Data Fault; Ret Addr Follows; 525*02ca8ccaSAndroid Build Coastguard Worker 84: I_ADDR_L_64IS0 : Address, Long, 64 bit, IS0.; Addr=0x0000007F89F283F0; 526*02ca8ccaSAndroid Build Coastguard Worker 93: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0xFFFFFFC000083400; Ctxt: AArch64,EL1, NS; 527*02ca8ccaSAndroid Build Coastguard Worker 104: I_TRACE_ON : Trace On. 528*02ca8ccaSAndroid Build Coastguard Worker 105: I_ADDR_CTXT_L_64IS0 : Address & Context, Long, 64 bit, IS0.; Addr=0x0000007F89F283F0; Ctxt: AArch64,EL0, NS; 529*02ca8ccaSAndroid Build Coastguard Worker 116: I_ATOM_F5 : Atom format 5.; NNNNN 530*02ca8ccaSAndroid Build Coastguard Worker 117: I_ATOM_F5 : Atom format 5.; NNNNN 531*02ca8ccaSAndroid Build Coastguard Worker 532*02ca8ccaSAndroid Build Coastguard Worker 533*02ca8ccaSAndroid Build Coastguard WorkerTrace Decoding with Perf Script 534*02ca8ccaSAndroid Build Coastguard Worker------------------------------- 535*02ca8ccaSAndroid Build Coastguard WorkerWorking with perf scripts needs more command line options but yields 536*02ca8ccaSAndroid Build Coastguard Workerinteresting results. 537*02ca8ccaSAndroid Build Coastguard Worker 538*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ export EXEC_PATH=/home/linaro/coresight/perf-opencsd-master/tools/perf/ 539*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ export SCRIPT_PATH=$EXEC_PATH/scripts/python/ 540*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ export XTOOL_PATH=/your/aarch64/toolchain/path/bin/ 541*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ ../perf-opencsd-master/tools/perf/perf --exec-path=${EXEC_PATH} script --script=python:${SCRIPT_PATH}/arm-cs-trace-disasm.py -- -d ${XTOOL_PATH}/aarch64-linux-gnu-objdump 542*02ca8ccaSAndroid Build Coastguard Worker 543*02ca8ccaSAndroid Build Coastguard Worker 7f89f24d80: 910003e0 mov x0, sp 544*02ca8ccaSAndroid Build Coastguard Worker 7f89f24d84: 94000d53 bl 7f89f282d0 <free@plt+0x3790> 545*02ca8ccaSAndroid Build Coastguard Worker 7f89f282d0: d11203ff sub sp, sp, #0x480 546*02ca8ccaSAndroid Build Coastguard Worker 7f89f282d4: a9ba7bfd stp x29, x30, [sp,#-96]! 547*02ca8ccaSAndroid Build Coastguard Worker 7f89f282d8: 910003fd mov x29, sp 548*02ca8ccaSAndroid Build Coastguard Worker 7f89f282dc: a90363f7 stp x23, x24, [sp,#48] 549*02ca8ccaSAndroid Build Coastguard Worker 7f89f282e0: 9101e3b7 add x23, x29, #0x78 550*02ca8ccaSAndroid Build Coastguard Worker 7f89f282e4: a90573fb stp x27, x28, [sp,#80] 551*02ca8ccaSAndroid Build Coastguard Worker 7f89f282e8: a90153f3 stp x19, x20, [sp,#16] 552*02ca8ccaSAndroid Build Coastguard Worker 7f89f282ec: aa0003fb mov x27, x0 553*02ca8ccaSAndroid Build Coastguard Worker 7f89f282f0: 910a82e1 add x1, x23, #0x2a0 554*02ca8ccaSAndroid Build Coastguard Worker 7f89f282f4: a9025bf5 stp x21, x22, [sp,#32] 555*02ca8ccaSAndroid Build Coastguard Worker 7f89f282f8: a9046bf9 stp x25, x26, [sp,#64] 556*02ca8ccaSAndroid Build Coastguard Worker 7f89f282fc: 910102e0 add x0, x23, #0x40 557*02ca8ccaSAndroid Build Coastguard Worker 7f89f28300: f800841f str xzr, [x0],#8 558*02ca8ccaSAndroid Build Coastguard Worker 7f89f28304: eb01001f cmp x0, x1 559*02ca8ccaSAndroid Build Coastguard Worker 7f89f28308: 54ffffc1 b.ne 7f89f28300 <free@plt+0x37c0> 560*02ca8ccaSAndroid Build Coastguard Worker 7f89f28300: f800841f str xzr, [x0],#8 561*02ca8ccaSAndroid Build Coastguard Worker 7f89f28304: eb01001f cmp x0, x1 562*02ca8ccaSAndroid Build Coastguard Worker 7f89f28308: 54ffffc1 b.ne 7f89f28300 <free@plt+0x37c0> 563*02ca8ccaSAndroid Build Coastguard Worker 7f89f28300: f800841f str xzr, [x0],#8 564*02ca8ccaSAndroid Build Coastguard Worker 7f89f28304: eb01001f cmp x0, x1 565*02ca8ccaSAndroid Build Coastguard Worker 7f89f28308: 54ffffc1 b.ne 7f89f28300 <free@plt+0x37c0> 566*02ca8ccaSAndroid Build Coastguard Worker 567*02ca8ccaSAndroid Build Coastguard WorkerKernel Trace Decoding 568*02ca8ccaSAndroid Build Coastguard Worker--------------------- 569*02ca8ccaSAndroid Build Coastguard Worker 570*02ca8ccaSAndroid Build Coastguard WorkerWhen dealing with kernel space traces the vmlinux file has to be communicated 571*02ca8ccaSAndroid Build Coastguard Workerexplicitely to perf using the "--vmlinux" command line option: 572*02ca8ccaSAndroid Build Coastguard Worker 573*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ ../perf-opencsd-master/tools/perf/perf report --stdio --vmlinux=./vmlinux 574*02ca8ccaSAndroid Build Coastguard Worker ... 575*02ca8ccaSAndroid Build Coastguard Worker ... 576*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ ../perf-opencsd-master/tools/perf/perf script --vmlinux=./vmlinux 577*02ca8ccaSAndroid Build Coastguard Worker 578*02ca8ccaSAndroid Build Coastguard WorkerWhen using scripts things get a little more convoluted. Using the same example 579*02ca8ccaSAndroid Build Coastguard Workeran above but for traces but for kernel traces, the command line becomes: 580*02ca8ccaSAndroid Build Coastguard Worker 581*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ export EXEC_PATH=/home/linaro/coresight/perf-opencsd-master/tools/perf/ 582*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ export SCRIPT_PATH=$EXEC_PATH/scripts/python/ 583*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ export XTOOL_PATH=/your/aarch64/toolchain/path/bin/ 584*02ca8ccaSAndroid Build Coastguard Worker linaro@t430:~/linaro/coresight/sept20$ ../perf-opencsd-master/tools/perf/perf --exec-path=${EXEC_PATH} script \ 585*02ca8ccaSAndroid Build Coastguard Worker --vmlinux=./vmlinux \ 586*02ca8ccaSAndroid Build Coastguard Worker --script=python:${SCRIPT_PATH}/arm-cs-trace-disasm.py -- \ 587*02ca8ccaSAndroid Build Coastguard Worker -d ${XTOOLS_PATH}/aarch64-linux-gnu-objdump \ 588*02ca8ccaSAndroid Build Coastguard Worker -k ./vmlinux 589*02ca8ccaSAndroid Build Coastguard Worker ... 590*02ca8ccaSAndroid Build Coastguard Worker ... 591*02ca8ccaSAndroid Build Coastguard Worker 592*02ca8ccaSAndroid Build Coastguard WorkerThe option "--vmlinux=./vmlinux" is interpreted by the "perf script" command 593*02ca8ccaSAndroid Build Coastguard Workerthe same way it if for "perf report". The option "-k ./vmlinux" is dependant 594*02ca8ccaSAndroid Build Coastguard Workeron the script being executed and has no related to the "--vmlinux", though it 595*02ca8ccaSAndroid Build Coastguard Workeris highly advised to keep them synchronized. 596*02ca8ccaSAndroid Build Coastguard Worker 597*02ca8ccaSAndroid Build Coastguard Worker 598*02ca8ccaSAndroid Build Coastguard WorkerPerf Test Environment Scripts 599*02ca8ccaSAndroid Build Coastguard Worker----------------------------- 600*02ca8ccaSAndroid Build Coastguard Worker 601*02ca8ccaSAndroid Build Coastguard WorkerThe decoder library comes with a number of `bash` scripts that ease the setting up of the 602*02ca8ccaSAndroid Build Coastguard Workeroffline build and test environment for perf, and executing tests. 603*02ca8ccaSAndroid Build Coastguard Worker 604*02ca8ccaSAndroid Build Coastguard WorkerThese scripts can be found in 605*02ca8ccaSAndroid Build Coastguard Worker 606*02ca8ccaSAndroid Build Coastguard Worker decoder/tests/perf-test-scripts 607*02ca8ccaSAndroid Build Coastguard Worker 608*02ca8ccaSAndroid Build Coastguard WorkerThere are three scripts provided: 609*02ca8ccaSAndroid Build Coastguard Worker 610*02ca8ccaSAndroid Build Coastguard Worker- `perf-setup-env.bash` : this sets up all the environment variables mentioned above. 611*02ca8ccaSAndroid Build Coastguard Worker- `perf-test-report.bash` : this runs `perf report` - using the environment setup by `perf-setup-env.bash` 612*02ca8ccaSAndroid Build Coastguard Worker- `perf-test-script.bash` : this runs `perf script` - using the environment setup by `perf-setup-env.bash` 613*02ca8ccaSAndroid Build Coastguard Worker 614*02ca8ccaSAndroid Build Coastguard WorkerUse as follows:- 615*02ca8ccaSAndroid Build Coastguard Worker 616*02ca8ccaSAndroid Build Coastguard Worker1. Prior to building perf, edit `perf-setup-env.bash` to conform to your environment. There are four lines at the top of the file that will require editing. 617*02ca8ccaSAndroid Build Coastguard Worker 618*02ca8ccaSAndroid Build Coastguard Worker2. Execute the script using the command: 619*02ca8ccaSAndroid Build Coastguard Worker 620*02ca8ccaSAndroid Build Coastguard Worker source perf-setup-env.bash 621*02ca8ccaSAndroid Build Coastguard Worker 622*02ca8ccaSAndroid Build Coastguard Worker This will set up a perf execute environment for using the perf report and script commands. 623*02ca8ccaSAndroid Build Coastguard Worker 624*02ca8ccaSAndroid Build Coastguard Worker Alternatively use the command: 625*02ca8ccaSAndroid Build Coastguard Worker 626*02ca8ccaSAndroid Build Coastguard Worker source perf-setup-env.base buildenv 627*02ca8ccaSAndroid Build Coastguard Worker 628*02ca8ccaSAndroid Build Coastguard Worker This will add in the build environment variables mentioned in the sections on building above alongside the 629*02ca8ccaSAndroid Build Coastguard Worker environment for using the used by the `perf-test...` scripts to run the tests. 630*02ca8ccaSAndroid Build Coastguard Worker 631*02ca8ccaSAndroid Build Coastguard Worker3. Build perf as described above. 632*02ca8ccaSAndroid Build Coastguard Worker4. Follow the instructions for downloading the test capture, or create a capture from your target. 633*02ca8ccaSAndroid Build Coastguard Worker5. Copy the `perf-test...` scripts into the capture data directory -> the one that contains `perf.data`. 634*02ca8ccaSAndroid Build Coastguard Worker 635*02ca8ccaSAndroid Build Coastguard Worker6. The scripts can now be run. No options are required for the default operation, but any command line options will be added to the perf report / perf script command line. 636*02ca8ccaSAndroid Build Coastguard Worker 637*02ca8ccaSAndroid Build Coastguard Workere.g. 638*02ca8ccaSAndroid Build Coastguard Worker 639*02ca8ccaSAndroid Build Coastguard Worker ./perf-test-report.bash --dump 640*02ca8ccaSAndroid Build Coastguard Worker 641*02ca8ccaSAndroid Build Coastguard Workerwill add the --dump option to the end of the command line and run 642*02ca8ccaSAndroid Build Coastguard Worker 643*02ca8ccaSAndroid Build Coastguard Worker ${PERF_EXEC_PATH}/perf report --stdio --dump 644*02ca8ccaSAndroid Build Coastguard Worker 645*02ca8ccaSAndroid Build Coastguard Worker 646*02ca8ccaSAndroid Build Coastguard WorkerGenerating coverage files for Feedback Directed Optimization: AutoFDO 647*02ca8ccaSAndroid Build Coastguard Worker--------------------------------------------------------------------- 648*02ca8ccaSAndroid Build Coastguard Worker 649*02ca8ccaSAndroid Build Coastguard WorkerSee autofdo.md (@ref AutoFDO) for details and scripts. 650*02ca8ccaSAndroid Build Coastguard Worker 651*02ca8ccaSAndroid Build Coastguard Worker 652*02ca8ccaSAndroid Build Coastguard WorkerThe Linaro CoreSight Team 653*02ca8ccaSAndroid Build Coastguard Worker------------------------- 654*02ca8ccaSAndroid Build Coastguard Worker- Mike Leach 655*02ca8ccaSAndroid Build Coastguard Worker- Mathieu Poirier 656*02ca8ccaSAndroid Build Coastguard Worker 657*02ca8ccaSAndroid Build Coastguard Worker 658*02ca8ccaSAndroid Build Coastguard WorkerOne Last Thing 659*02ca8ccaSAndroid Build Coastguard Worker-------------- 660*02ca8ccaSAndroid Build Coastguard WorkerWe welcome help on this project. If you would like to add features or help 661*02ca8ccaSAndroid Build Coastguard Workerimprove the way things work, we want to hear from you. 662*02ca8ccaSAndroid Build Coastguard Worker 663*02ca8ccaSAndroid Build Coastguard WorkerBest regards, 664*02ca8ccaSAndroid Build Coastguard Worker*The Linaro CoreSight Team* 665*02ca8ccaSAndroid Build Coastguard Worker 666*02ca8ccaSAndroid Build Coastguard Worker-------------------------------------- 667*02ca8ccaSAndroid Build Coastguard Worker[1]: https://github.com/Linaro/OpenCSD 668*02ca8ccaSAndroid Build Coastguard Worker 669*02ca8ccaSAndroid Build Coastguard Worker[2]: http://people.linaro.org/~mathieu.poirier/openCSD/uname.v4.user.sept20.tgz 670