1569f64afd3db2b43003978765b833669f99477d2Yabin Cui/* 2569f64afd3db2b43003978765b833669f99477d2Yabin Cui * Copyright (C) 2015 The Android Open Source Project 3569f64afd3db2b43003978765b833669f99477d2Yabin Cui * 4569f64afd3db2b43003978765b833669f99477d2Yabin Cui * Licensed under the Apache License, Version 2.0 (the "License"); 5569f64afd3db2b43003978765b833669f99477d2Yabin Cui * you may not use this file except in compliance with the License. 6569f64afd3db2b43003978765b833669f99477d2Yabin Cui * You may obtain a copy of the License at 7569f64afd3db2b43003978765b833669f99477d2Yabin Cui * 8569f64afd3db2b43003978765b833669f99477d2Yabin Cui * http://www.apache.org/licenses/LICENSE-2.0 9569f64afd3db2b43003978765b833669f99477d2Yabin Cui * 10569f64afd3db2b43003978765b833669f99477d2Yabin Cui * Unless required by applicable law or agreed to in writing, software 11569f64afd3db2b43003978765b833669f99477d2Yabin Cui * distributed under the License is distributed on an "AS IS" BASIS, 12569f64afd3db2b43003978765b833669f99477d2Yabin Cui * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13569f64afd3db2b43003978765b833669f99477d2Yabin Cui * See the License for the specific language governing permissions and 14569f64afd3db2b43003978765b833669f99477d2Yabin Cui * limitations under the License. 15569f64afd3db2b43003978765b833669f99477d2Yabin Cui */ 16569f64afd3db2b43003978765b833669f99477d2Yabin Cui 17569f64afd3db2b43003978765b833669f99477d2Yabin Cui#ifndef SIMPLE_PERF_GET_TEST_DATA_H_ 18569f64afd3db2b43003978765b833669f99477d2Yabin Cui#define SIMPLE_PERF_GET_TEST_DATA_H_ 19569f64afd3db2b43003978765b833669f99477d2Yabin Cui 20569f64afd3db2b43003978765b833669f99477d2Yabin Cui#include <string> 21569f64afd3db2b43003978765b833669f99477d2Yabin Cui 22b1a885b014540a2f7798b5a35ea0f0ec150d93eeYabin Cui#include "build_id.h" 23b1a885b014540a2f7798b5a35ea0f0ec150d93eeYabin Cui 24569f64afd3db2b43003978765b833669f99477d2Yabin Cuistd::string GetTestData(const std::string& filename); 25b1a885b014540a2f7798b5a35ea0f0ec150d93eeYabin Cuiconst std::string& GetTestDataDir(); 26b1a885b014540a2f7798b5a35ea0f0ec150d93eeYabin Cui 278f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// The source code of elf and elf_with_mini_debug_info is testdata/elf_file_source.cpp. 288f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cuistatic const std::string ELF_FILE = "elf"; 298f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cuistatic const std::string ELF_FILE_WITH_MINI_DEBUG_INFO = "elf_with_mini_debug_info"; 308f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// perf.data is generated by sampling on three processes running different 318f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// executables: elf, t1, t2 (all generated by elf_file_source.cpp, but with different 328f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// executable name). 336e51bef9aa101307523946df301ca90215d0ee82Yabin Cuistatic const std::string PERF_DATA = "perf.data"; 34861f655538b17ed37cf5d9bcadc71f22d3a0a6e9Yabin Cui 35861f655538b17ed37cf5d9bcadc71f22d3a0a6e9Yabin Cui// perf_with_multiple_pids_and_tids.data is generated by sampling on two processes, each 36861f655538b17ed37cf5d9bcadc71f22d3a0a6e9Yabin Cui// process running two threads. 37861f655538b17ed37cf5d9bcadc71f22d3a0a6e9Yabin Cuistatic const std::string PERF_DATA_WITH_MULTIPLE_PIDS_AND_TIDS = "perf_with_multiple_pids_and_tids.data"; 38861f655538b17ed37cf5d9bcadc71f22d3a0a6e9Yabin Cui 398f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// perf_g_fp.data is generated by sampling on one process running elf using --call-graph fp option. 406e51bef9aa101307523946df301ca90215d0ee82Yabin Cuistatic const std::string CALLGRAPH_FP_PERF_DATA = "perf_g_fp.data"; 418f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// perf_b.data is generated by sampling on one process running elf using -b option. 426e51bef9aa101307523946df301ca90215d0ee82Yabin Cuistatic const std::string BRANCH_PERF_DATA = "perf_b.data"; 438f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// perf_with_mini_debug_info.data is generated by sampling on one process running 448f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// elf_with_mini_debug_info. 4505400539d15c50a52a388daba2e831b86824cc8eYabin Cuistatic const std::string PERF_DATA_WITH_MINI_DEBUG_INFO = "perf_with_mini_debug_info.data"; 466e51bef9aa101307523946df301ca90215d0ee82Yabin Cui 478f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cuistatic BuildId elf_file_build_id("0b12a384a9f4a3f3659b7171ca615dbec3a81f71"); 486e51bef9aa101307523946df301ca90215d0ee82Yabin Cui 498f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui 508f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// To generate apk supporting execution on shared libraries in apk: 518f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// 1. Add android:extractNativeLibs=false in AndroidManifest.xml. 528f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// 2. Use `zip -0` to store native libraries in apk without compression. 538f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// 3. Use `zipalign -p 4096` to make native libraries in apk start at page boundaries. 548f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// 558f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// The logical in libhello-jni.so is as below: 568f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// volatile int GlobalVar; 578f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// 588f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// while (true) { 598f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// GlobalFunc() -> Func1() -> Func2() 608f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// } 618f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// And most time is spent in Func2(). 62b1a885b014540a2f7798b5a35ea0f0ec150d93eeYabin Cuistatic const std::string APK_FILE = "data/app/com.example.hellojni-1/base.apk"; 63b1a885b014540a2f7798b5a35ea0f0ec150d93eeYabin Cuistatic const std::string NATIVELIB_IN_APK = "lib/arm64-v8a/libhello-jni.so"; 648f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// has_embedded_native_libs_apk_perf.data is generated by sampling on one process running 658f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// APK_FILE using -g --no-unwind option. 66b1a885b014540a2f7798b5a35ea0f0ec150d93eeYabin Cuistatic const std::string NATIVELIB_IN_APK_PERF_DATA = "has_embedded_native_libs_apk_perf.data"; 678f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cui// The offset and size info are extracted from the generated apk file to run read_apk tests. 688f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cuiconstexpr size_t NATIVELIB_OFFSET_IN_APK = 0x639000; 698f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cuiconstexpr size_t NATIVELIB_SIZE_IN_APK = 0x1678; 70b1a885b014540a2f7798b5a35ea0f0ec150d93eeYabin Cui 718f680f60dc800bec880c5c35bfbc1ac36165e1f3Yabin Cuistatic BuildId native_lib_build_id("8ed5755a7fdc07586ca228b8ee21621bce2c7a97"); 72569f64afd3db2b43003978765b833669f99477d2Yabin Cui 732d6efe4b167da4e6b77f168b1820239ee65599e2Yabin Cui// perf_with_two_event_types.data is generated by sampling using -e cpu-cycles,cpu-clock option. 742d6efe4b167da4e6b77f168b1820239ee65599e2Yabin Cuistatic const std::string PERF_DATA_WITH_TWO_EVENT_TYPES = "perf_with_two_event_types.data"; 752d6efe4b167da4e6b77f168b1820239ee65599e2Yabin Cui 76b42129797f17f990ea5a88c6bdc7446000cc361cYabin Cui// perf_with_kernel_symbol.data is generated by `sudo simpleperf record ls -l`. 77b42129797f17f990ea5a88c6bdc7446000cc361cYabin Cuistatic const std::string PERF_DATA_WITH_KERNEL_SYMBOL = "perf_with_kernel_symbol.data"; 78b42129797f17f990ea5a88c6bdc7446000cc361cYabin Cui 79dcb2a3e580f155bb28621c4cbad019d104e8f300Yabin Cui// perf_with_symbols.data is generated by `sudo simpleperf record` a process calling func2(int,int). 80767dd17947f1ae9dd3d02f738d442a23ed76f2f6Yabin Cuistatic const std::string PERF_DATA_WITH_SYMBOLS = "perf_with_symbols.data"; 81dcb2a3e580f155bb28621c4cbad019d104e8f300Yabin Cui// perf_with_symbols.data is generated by `sudo simpleperf record` a process using 82c855ecc6becfe5d1c2445094aa525856e4538f7cYabin Cui// a binary having non zero min virtual address. 83c855ecc6becfe5d1c2445094aa525856e4538f7cYabin Cuistatic const std::string PERF_DATA_WITH_SYMBOLS_FOR_NONZERO_MINVADDR_DSO = 84c855ecc6becfe5d1c2445094aa525856e4538f7cYabin Cui "perf_with_symbols_for_nonzero_minvaddr_dso.data"; 85767dd17947f1ae9dd3d02f738d442a23ed76f2f6Yabin Cui 861761a271faf98050891ba6e918993225782c811aYabin Cui// perf_kmem_slab_callgraph.data is generated by `simpleperf kmem record --slab --call-graph fp -f 100 sleep 0.0001`. 876965d42c43f12fd2dfcca3c490b51edc67822586Yabin Cuistatic const std::string PERF_DATA_WITH_KMEM_SLAB_CALLGRAPH_RECORD = "perf_with_kmem_slab_callgraph.data"; 886965d42c43f12fd2dfcca3c490b51edc67822586Yabin Cui 89eec606cfefcb8cb20ac0f9e3465daff09fb31ffdYabin Cui 90eec606cfefcb8cb20ac0f9e3465daff09fb31ffdYabin Cui// perf_for_build_id_check.data is generated by recording a process running 91eec606cfefcb8cb20ac0f9e3465daff09fb31ffdYabin Cui// testdata/data/correct_symfs_for_build_id_check/elf_for_build_id_check. 92eec606cfefcb8cb20ac0f9e3465daff09fb31ffdYabin Cuistatic const std::string PERF_DATA_FOR_BUILD_ID_CHECK = "perf_for_build_id_check.data"; 93eec606cfefcb8cb20ac0f9e3465daff09fb31ffdYabin Cuistatic const std::string CORRECT_SYMFS_FOR_BUILD_ID_CHECK = "data/correct_symfs_for_build_id_check"; 94eec606cfefcb8cb20ac0f9e3465daff09fb31ffdYabin Cuistatic const std::string WRONG_SYMFS_FOR_BUILD_ID_CHECK = "data/wrong_symfs_for_build_id_check"; 95eec606cfefcb8cb20ac0f9e3465daff09fb31ffdYabin Cui 96dec43c18d06415a955b8f32355bca925be901905Yabin Cuistatic const std::string SYMFS_FOR_NO_SYMBOL_TABLE_WARNING = "data/symfs_for_no_symbol_table_warning"; 97dec43c18d06415a955b8f32355bca925be901905Yabin Cuistatic const std::string SYMFS_FOR_READ_ELF_FILE_WARNING = "data/symfs_for_read_elf_file_warning"; 98eafa7188ac41584555d36ac0c19f3c7fc66d42ccYabin Cui 99eafa7188ac41584555d36ac0c19f3c7fc66d42ccYabin Cui// generated_by_linux_perf.data is generated by `perf record -F 1 -a -g -- sleep 0.1`. 100eafa7188ac41584555d36ac0c19f3c7fc66d42ccYabin Cuistatic const std::string PERF_DATA_GENERATED_BY_LINUX_PERF = "generated_by_linux_perf.data"; 101eafa7188ac41584555d36ac0c19f3c7fc66d42ccYabin Cui 102c0565bb21e2997d7a01dda40ea2b16e067e7e28cYabin Cui// generated by `simpleperf record -g ls`. 103c0565bb21e2997d7a01dda40ea2b16e067e7e28cYabin Cuistatic const std::string PERF_DATA_MAX_STACK_AND_PERCENT_LIMIT = "perf_test_max_stack_and_percent_limit.data"; 104c0565bb21e2997d7a01dda40ea2b16e067e7e28cYabin Cui 105044861ba8d71688940b6500f68458fae0791517cYabin Cui// generated by `dd if=/dev/zero of=invalid_perf.data bs=1024 count=1`. 106044861ba8d71688940b6500f68458fae0791517cYabin Cuistatic const std::string INVALID_PERF_DATA = "invalid_perf.data"; 107044861ba8d71688940b6500f68458fae0791517cYabin Cui 10898c7584c1c6cb93ad3e0f66e2a6f1d6b2d8fb878Yabin Cui// generated by recording an app. 10998c7584c1c6cb93ad3e0f66e2a6f1d6b2d8fb878Yabin Cuistatic const std::string PERF_DATA_WITH_WRONG_IP_IN_CALLCHAIN = "wrong_ip_callchain_perf.data"; 11098c7584c1c6cb93ad3e0f66e2a6f1d6b2d8fb878Yabin Cui 11168b8383d76a7a18bdaee13949cc66ca012cc3deeYabin Cui// generated by `simpleperf record --trace-offcpu --duration 2 -g ./simpleperf_runtest_run_and_sleep64`. 11268b8383d76a7a18bdaee13949cc66ca012cc3deeYabin Cuistatic const std::string PERF_DATA_WITH_TRACE_OFFCPU = "perf_with_trace_offcpu.data"; 11368b8383d76a7a18bdaee13949cc66ca012cc3deeYabin Cui 11481a9d33dd0d753e4d4915dfb6f453b916be08813Yabin Cui// generated by `simpleperf record -g --log debug sleep 1`. 11581a9d33dd0d753e4d4915dfb6f453b916be08813Yabin Cuistatic const std::string PERF_DATA_WITH_CALLCHAIN_RECORD = "perf_with_callchain_record.data"; 11681a9d33dd0d753e4d4915dfb6f453b916be08813Yabin Cui 117c3bf9d08671e8d41d24eeb5978a01b2dd40d0bc4Yabin Cui// generated by `simpleperf record -g --no-unwind`. 118c3bf9d08671e8d41d24eeb5978a01b2dd40d0bc4Yabin Cuistatic const std::string PERF_DATA_NO_UNWIND = "perf_no_unwind.data"; 119c3bf9d08671e8d41d24eeb5978a01b2dd40d0bc4Yabin Cui 120569f64afd3db2b43003978765b833669f99477d2Yabin Cui#endif // SIMPLE_PERF_GET_TEST_DATA_H_ 121