summaryrefslogtreecommitdiff
path: root/simpleperf/dso.cpp
AgeCommit message (Collapse)Author
2022-03-14simpleperf: searching for debug files only when needed.Yabin Cui
Currently simpleperf searches for debug files when creating Dso, and may show a warning when a debug file has unmatched build id. But not all debug files are needed. So this creates unnecessary warnings. This CL fixes it by searching for debug files only when needed. Bug: 222563847 Test: run simpleperf_unit_test Test: run pprof_proto_generator.py manually Change-Id: Icc029af805e9cbdf5f53c36ae374b3b1d56dbc23
2021-11-04Update for libunwindstack changes.Christopher Ferris
The libunwindstack change has modified the code so that prev_real_map and next_real_map are not set at map creation time. Instead they are evaluated when needed. Another small change was necessary since the code was modifying the name of some maps. The problem is the new lazy evaluation means that unless all same name maps are modified, a test might fail. This only occurs if there is a read-only map followed by a read-execute map and it is from an apk. The name modification code properly changes the name of all standalone elf files, but when it's an apk, it doesn't change the name in all cases. The lazy evaluation would fail because the name of the read-execute map is different from the read-only map. The small change is to change the name of the apk maps so the lazy evaluation works. Test: Unit tests pass. Change-Id: Ib96ba7083aeeeea14b84ccbdd27759b7b2062ff8
2021-11-03simpleperf: avoid warning for missing dex files.Yabin Cui
This avoids warnings like "python3 W] Failed to read symbols from dex_file /system/framework.jar", which are usually not useful, and may be confusing. Bug: none Test: run simpleperf manually Test: run simpleperf_unit_test Change-Id: Id64cb035ec9e00ffbe3bddb540a5ca20d96eeb9f
2021-08-19simpleperf: use proguard mapping file for compiled java symbols.Yabin Cui
Bug: 195892224 Test: run simpleperf_unit_test Change-Id: Ia74654d5703eb23dc4ae6e6faeb1cbc53615636e
2021-08-16simpleperf: support JIT method name with signature.Yabin Cui
When using debug_info instead of mini_debug_info, ART exports JIT method name with signature. So simpleperf needs to remove the signature when converting JIT frames and deobfuscating method names. Bug: 195892224 Test: run simpleperf_unit_test Change-Id: I08d2b95cf21e8653e946833e442315a09e7bd723
2021-07-13simpleperf: improve debugging reading dex file.Yabin Cui
Print debug_filename in ReadSymbolsFromDexFileInMemory() when failed to read symbols. Simplify the code by removing open_file_cb. Bug: none Test: run simpleperF_unit_test Change-Id: Ie776f3993898be5245e612bf599fa229dc650944
2021-04-15Adjust to libdexfile API changesDavid Srbecky
Test: simpleperf_unit_test --gtest_filter=*dex* Change-Id: I837c1e1669bd7f602da6d86051b2fb666044b1ac
2021-04-14simpleperf: support proguard mapping file in callchain report.Yabin Cui
Also refactor LineReader to make it available on windows. Bug: 169454086 Test: run simpleperf_unit_test Change-Id: I16844f824b3e6bb52884510fe6e93cf4cf90d4e3
2021-03-30Merge changes I91ea3a20,I165d28c4,Ieeb7eee0Yabin Cui
* changes: simpleperf_profcollect: add option for recording scope. simpleperf: support kernel etm data in inject cmd. simpleperf: prepare recording etm data for kernel.
2021-03-30simpleperf: support kernel etm data in inject cmd.Yabin Cui
Add extra info in etm_branch_list.proto to decode kernel etm data. Bug: 183135316 Test: run simpleperf_unit_test Change-Id: I165d28c4e0f3a26c09741238336949bcff3902ca
2021-03-24simpleperf: use callback API to read dex symbols.Yabin Cui
In experiment, it saves about 20% time reading dex symbols. Bug: none Test: run simpleperf_unit_test Change-Id: I0e6bfd1f51f99f57175fece77c2ee3518e676a71
2021-01-11simpleperf: move all source files into simpleperf namespaceYabin Cui
Bug: none Test: run simpleperf_unit_test Change-Id: I348028ee5bea90ce908bc240fc5efc22c4cd540f
2020-12-17simpleperf: fix ReportCommandTest on windows.Yabin Cui
Fix failed tests: ReportCommandTest.report_kernel_symbol ReportCommandTest.kallsyms_option They fail because kallsyms are only used on linux. Bug: 175885920 Test: run simpleperf_unit_test Change-Id: I6a10969a819a4169a173c77178e6fcd67fee40df
2020-12-12Merge changes Ic892ba07,Ic64956cdYabin Cui
* changes: simpleperf: fix confusing recursive call. simpleperf: extract common code into report_utils.cpp
2020-12-11simpleperf: extract common code into report_utils.cppYabin Cui
Extract common code in cmd_report_sample.cpp and report_lib_interface.cpp, into report_utils.cpp. Bug: 175163225 Test: run simpleperf_unit_test. Test: run test.py TestReportLibs*. Change-Id: Ic64956cd1a73ef3165337aa3509a15d14e095959
2020-12-01Refactor loading of /proc/kallsymsThiƩbaud Weksteen
Moves related functions to a new source file (kallsyms.cpp). Adds support for the security.lower_kptr_restrict system property. The implementation of ScopedKptrUnrestrict is based on Perfetto (see aosp/1454882). Test: lunch aosp_crosshatch-userdebug; atest CtsSimpleperfTestCases Change-Id: Ie6ba7aab93d68be915583ad4f8551c627b35f292
2020-11-25simpleperf: fix symbolization for kernel modules.Yabin Cui
Simpleperf makes a wrong assumption that the kernel always load .text section of a kernel module at the start of its module memory. This can map an ip addr of a module to a wrong symbol. To fix it: 1. In KernelModuleDso, calculate min_vaddr and memory_offset, which are used to do the conversion in IpToVaddrInFile(). 2. Change record_file_reader/writer to store min_vaddr and memory_offset of KernelModuleDso in the recording file. 3. To get module start addresses, Use CheckKernelSymbolAddress() in GetLoadedModules(). Bug: 174076407 Test: run simpleperf_unit_test. Test: run simpleperf manually to check symbols of kernel modules. Change-Id: I2498564f78dcc34761c5fe3ae9ffa6b88a98a048
2020-11-11simpleperf: support kernel etm data in inject cmd.Yabin Cui
1. Refactor KernelDso class to handle kernel address randomization. 2. Add Dso::IpToFileOffset() to convert ip addresses to file offsets, and use special operation for KernelDso. 3. Search for vmlinux in symbol dirs. 4. Delay creating KernelDso to use the kernel build id in recording files. Bug: 172933381 Test: run simpleperf_unit_test Test: run `simpleperf inject` manually to inject kernel etm data. Change-Id: Ice7f465a6f1e870740cc8ceaf8da76220026adef
2020-10-23simpleperf: enable .clang-formatThiƩbaud Weksteen
Use the 2-space configuration by default and disable any formatting for the demo/ subdirectory. The following command was used to generate this change: $ find . \( -name \*.cpp -o -name \*.h \) -exec clang-format \ --style=file -i {} \; Test: mm Change-Id: I89ec1f18f6e352f40cfa1a770087f3b586b1d7cb
2020-09-09simpleperf: fix tests broken by jit symfile path change.Yabin Cui
Simpleperf checks if a path is JIT symfile by looking for a colon symbol in it. But a normal path on windows can contain colon symbols. Thus two windows tests are broken. This CL fixs them by adding a function in JITDebugReader class to check JIT symfile paths. Also fix python test TestReportLib.test_merge_java_methods. It was broken by report_lib_interface.cpp dropping support for old jit symfile paths. This CL added the support back. Also add a new test TestReportLib.test_jited_java_methods to test new jit symfile path. Bug: 167604389 Test: run simpleperf_unit_test. Test: run test.py. Change-Id: Ic0f69d224069f708fe20d79d0ce61cf63bd17e5f
2020-08-27simpleperf: add perf symbol map dso + testEvgeny Eltsin
Bug: 164091700 Test: simpleperf_unit_test Change-Id: I73c56d87518e22146dd7ec62c52ed80640369b59
2020-08-06simpleperf: fix jit cache path in report cmd.Yabin Cui
1. Separate app cache and zygote cache in ElfDso::GetReportPath(). 2. Use GetReportPath() in --dsos option in report cmd. So "[JIT app cache]" can be used to filter binaries. Bug: 159155297 Test: run simpleperf_unit_test Change-Id: Idc52bd1b2496aae30721a224d93621f776f2ae03
2020-07-28simpleperf: dump jit symfiles to a single file.Yabin Cui
Currently, each jit symfile is dumped to a distinct temporary file. This creates many temporary files, having two drawbacks: 1. It leaves many junk files if simpleperf is killed in the middle. 2. The names of the temporary files change in different recording files, making them harder to compare. This CL fixes it by making changes below: 1. Store jit symfiles in a single file. The location of a symfile is passed via a special path format: <file_path>:<file_start>-<file_end>. So the unwinder and ElfFile class can read it correctly. 2. Add Dso::GetReportPath() to give a unified name for jit symfiles. And use it in different reporting methods. Also split JITDebugReader::ReadProcess() into smaller functions. Bug: 159155297 Test: run simpleperf_unit_test Test: run simpleperf manually Change-Id: I37cd1888b855b4b88bb83e453e39230b96fb304f
2020-07-17simpleperf: find debug files for kernel modules.Yabin Cui
Also print a warning when a debug file in symfs_dir can't be used because of build_id mismatch. Bug: 161546498 Test: run simpleperf_unit_test Change-Id: I8d1d538a4a62339d236e665141b114428776fb54
2020-07-01simpleperf: Move ReadMinExecutableVaddr into ElfFile class.Yabin Cui
Bug: 160187327 Test: run simpleperf_unit_test. Change-Id: I913baff454ba01be9689712a61a970ffe04416fe
2020-06-30simpleperf: move ParseSymbols* inside ElfFile class.Yabin Cui
Bug: 160187327 Test: run simpleperf_unit_test. Change-Id: I01947eb03847cb3c5a93c7a06abb6d203f750a23
2020-06-29simpleperf: move GetBuildId* functions inside ElfFile class.Yabin Cui
Bug: 160187327 Test: run simpleperf_unit_test. Change-Id: Idd50cf755f10000e3629ec99a291ee35cf6f4cfd
2020-04-01simpleperf inject: support converting branch-list to autofdo.Yabin Cui
Below is a comparation between autofdo and branch-list output, running on a perf.data generated by 10s system wide recording while running monkey test: $ simpleperf inject -o autofdo.data time: 1m58.95s file size: 12M. $ simpleperf inject -o branch.data --output branch-list time: 22.06s. file size: 7.7M. $ simpleperf inject -i branch.data -o branch_autofdo.data time: 7.40s. file size: 12M. In the experiment, generating branch-list is about 5 times faster than generating autofdo output. So it is faster to generate branch-list output. The effect is more significant when more binaries and processes are involved. The generated file size is decreased from 12M to 7.7M, reducing about 36%. In the experiment, it is 15 times faster to generate autofdo output from branch-list than from perf.data. One main reason should be improved locality by decoding binaries one by one. The count of lines in branch_autofdo.data is 0.3% less than that in autofdo.data. It should be because of missing instruction ranges parsed from Exception packets. Bug: 151665001 Test: run simpleperf_unit_test. Change-Id: I2bcf43f5e788b628bf00f55e80ca32b39801837e
2019-11-19simpleperf: support libraries without build ids when recording.Yabin Cui
Simpleperf can download unstripped libraries on device and use them for unwinding during recording, through `app_profiler.py -lib` and `simpleperf record --symfs` options. But it doesn't support libraries without build ids. To support them: 1. In app_profiler.py, download libraries without build ids in native lib dir. 2. In DebugElfFileFinder in dso.cpp, check path with the same basename in symfs_dir. Also add document for downloading unstripped libraries on device. Bug: none Test: run simpleperf_unit_test. Test: run test.py. Change-Id: I5d9015e683f2ecb992d425a42f1f7303307b2cea
2019-11-15simpleperf: fix build_id checking.Yabin Cui
Native libraries in apks may not have build ids. So change to below rules when looking for a debug elf file: 1) If having a build id, the build ids should match. 2) Otherwise, the debug elf file should exist and not have a build id. Bug: none Test: run simpleperf_unit_test. Test: test.py. Change-Id: I01332e3010a6df17e70c6c55e15874d43bfaeb86
2019-05-31simpleperf: check content in build_id_list.Yabin Cui
The content in build_id_list may not match files exist in symfs dir, (like due to interrupted tests). So in simpleperf binary, do build id check for files in build_id_list. Also check if files exist in NativeLibDownloader. Bug: 134164477 Test: run simpleperf_unit_test. Test: run test.py TestNativeLibDownloader* Change-Id: Ida435d17d4fead2ba3a14c7766ecaf7cf12448b2
2019-02-07simpleperf: fix symbolization in multi-executable-segments libraries.Yabin Cui
Apps may run with libraries with multiple executable segments. Symbolization ip addresses in these libraries need to use map.pgoff. The old formula converting ip to vaddr_in_file: vaddr_in_file = ip - map.start + min_executable_vaddr The new formula converting ip to vaddr_in_file: offset_in_file = ip - map.start + map.pgoff vaddr_in_file = offset_in_file - file_offset_of_min_executable_vaddr + min_executable_vaddr Bug: 124056476 Test: run simpleperf_unit_test. Test: use simpleperf to profile facebook app, ip addresses hitting libc.so Test: and libart.so are symbolized correctly. Change-Id: I5fd3ed822a916c4d04a9868d6d209c43ee190c5b
2018-12-13Use libdexfile external API in simpleperf.Martin Stjernholm
Test: device boot Test: atest system/extras/simpleperf/ (lots of failures, but no new ones. 4 of 4 passed in simpleperf_unit_test) Test: mmma system/extras/simpleperf && adb root && adb shell rm -rf /data/test && adb push out/target/product/taimen/testcases/simpleperf_unit_test /data/test && adb shell /data/test/arm64/simpleperf_unit_test && adb shell /data/test/arm/simpleperf_unit_test Bug: 119632407 Change-Id: Id070b8a99cb4d3bf4ec90cae186a2e88bcec72a1
2018-10-30simpleperf: fix simpleperf_unit_test on windows.Yabin Cui
Fix test failures caused by path separator and newline character. Bug: 117568547 Test: run simpleperf_unit_test on windows. Change-Id: I0522268368a2288893ecd52f505382c512d1d7c9
2018-08-14simpleperf: fix removing ART frames.Yabin Cui
ART frames can also exist before or after JITed Java methods. Bug: none Test: run report_html.py manually, and check that ART frames Test: near JITed Java methods are removed. Change-Id: I771cb7503bb62e8d0fc71167bfd887abe069554f
2018-07-23simpleperf: add --symdir option in report-sample command.Yabin Cui
--symdir option is used to provide a directory containing files with symbols. Mutliple --symdir options can be used to provide more than one directories. For each symbol directory, simpleperf collects build id for all elf files under it recursively. Then simpleperf can use the collected build ids to find files with symbols. Also fix an error in GetCompleteProcessName(). Bug: 111687223 Test: run simpleperf_unit_test. Change-Id: Ieac5ebf7451ae85ca15c3eae37bac3c89615580b
2018-06-11simpleperf: support JIT/interpreted java code in system wide profiling.Yabin Cui
It contains below changes: 1. Support monitoring multiple processes in JITDebugReader. 2. Switch from 100ms period to 100ms interval when scanning JIT debug info changes. 3. Limit read entry length by seqlock different instead of a fixed value. 4. Support disable/enable periodic events in IOEventLoop. 5. Remove duplicated dex file offsets in DexFileDso. 6. Enable JITDebugReader for recording on Android P. 7. Remove " (deleted)" suffix in filenames of maps, because some vdex files in map file have this suffix. Bug: http://b/79118393 Test: run `simpleperf record -a` manually. Test: run simpleperf_unit_test. Change-Id: Ia398ddd7bc74cbc5fdca6caa6f548a62447d9729
2018-05-30simpleperf: add a missing null check.Yabin Cui
Bug: none. Test: run simpleperf_unit_test. Change-Id: I206c9c67cd96025956246c1bd080653f532a9112
2018-05-22simpleperf: get symbols from dex files extracted from zip files.Yabin Cui
ART may extract dex files into memory from zip files. This CL supports getting symbols from extracted dex files in below steps: 1. Change map names in "/dev/ashmem/dalvik-xxx extracted in memory from yyy.apk" format into yyy.apk!/xxx format. 2. Support dumping dex files in yyy.apk!/xxx format in JITDebugReader. 3. Support reading symbols from dex files in yyy.apk!/xxx format in DexFileDso. Also refactor FileHelper to return android::base::unique_fd, refactor ArchiveHelper to wrap all operations to zip files. Bug: 79118393 Test: run simpleperf_unit_test. Test: run simpleperf on an app containing extracted dex files. Change-Id: I65dbd98843f2d47272ea72935fd3d2b6d6e8ae40
2018-05-09simpleperf: change interface of read_apk.h.Yabin Cui
1. Remove GetBuildIdFromApkFile and ParseSymbolsFromApkFile, because their function can be supported using ApkInspector::FindElfInApkByName and read_elf.h. 2. Remove ApkInspector::FindOffsetInApkByName, instead the caller can use ApkInspector::FindElfInApkByName directly. 3. In ApkInspector::embedded_elf_cache_, add map for entry_name. So the EmbeddedElfs added by cmd_record.cpp can be used by OfflineUnwinder. Also support reading min executable virtual address from embedded elfs in ElfDso. Also avoid segfault reading build id of elf files with broken section table, and add test. Bug: none. Test: run simpleperf_unit_test. Change-Id: I2e4f51a5e348138cbf7445ec6dd42dbd6ae1b03d
2018-04-19simpleperf: use binary mode for build_id_list.Yabin Cui
As suggested in comments of https://android-review.googlesource.com/c/platform/system/extras/+/667472. Bug: none Test: run test.py. Change-Id: I55882f1cb07d87a5e09b75ab7ef901e478d614de
2018-04-18simpleperf: fix some errors testing on windows.Yabin Cui
Bug: none. Test: run simpleperf_unit_test. Test: run test.py. Change-Id: I9c77ce1704d7d7038c450a5f85c569dc2a728b92
2018-04-17simpleperf: avoid some warning messages.Yabin Cui
Sample records can hit unknown_dso when samples for JITed code are generated before simpleperf read the JIT symfiles. And unknown_dso uses DSO_ELF_FILE type. So simpleperf sometimes tries to read symbols from elf file "unknown" and dump "unknown" file in perf.data. This makes below warning message: simpleperf W dso.cpp:383] failed to read min virtual address of unknown: File not found simpleperf W dso.cpp:315] failed to read symbols from unknown: File not found To solve this, add DSO_UNKNOWN_FILE type for unknown_dso, which does nothing to load symbols. Also avoid dumping "unknown" file in perf.data. Also avoid below warning when reading none ELF file from apk file. simpleperf E read_apk.cpp:103] problems reading ELF from /system/framework/framework-res.apk entry 'res/raw/fallbackring.ogg': Malformed file Bug: http://b/77236599 Test: run simpleperf. Test: run simpleperf_unit_test. Change-Id: I43bc8a7764792ea993b596614668198f5a0cfd74
2018-04-12simpleperf: fix reading dex files for unwinding while recording.Yabin Cui
When simpleperf does unwinding while recording, it processes mmap records before reading dex file linked list (via JITDebugReader). To process mmap records, it creates Dso objects of type ELF_FILE. Then after reading dex file linked list, it realizes some ELF_FILE Dso should actually be DEX_FILE. So this patch supports converting Dso objects of type ELF_FILE into DEX_FILE when they have dex file offsets. Bug: http://b/73126888 Test: run simpleperf_unit_test. Test: run `simpleperf record -g --no-post-unwind` on an app. Change-Id: I580a382724b17c1396a7f52d7b3f5df45bcbcfb7
2018-04-10simpleperf: Improve the way downloading native libs on device.Yabin Cui
Apks are usually built with stripped native libs, so app_profiler.py supports downloading native libs on device, and pass the native lib directory to simpleperf via --symfs option. However, it has below problems: 1. It needs to download native libs each time profiling. 2. It needs to wait until the app starts and read the /proc/pid/maps to know which native libs are needed. This patch solves the problems as below: 1. When app_profiler.py downloads native libs, it will write a build_id_list file in the native lib directory, which is a map from build_id to debug library path. 2. Simpleperf searchs build_id_list in the native lib directory, and uses build_id to find the debug files it needs. 3. Before downloading libs, app_profiler.py checks build_id_list to find libs available on device, thus avoids downloading libs more than once. Add tests in simpleperf_unit_test and test.py. Update demos to Android Studio 3.2. In profiling.gradle, remove the logic preventing stripping native libs in apk to test this patch. Another reason to remove it is because I found it affects release builds. Bug: http://b/69165587 Test: run simpleperf_unit_test && python test.py. Change-Id: I8ecf7ba2c0f58c131c261c1b4546f4916aea1f82
2018-03-28simpleperf: support showing symbols for interpreted java code.Yabin Cui
To convert from a dex_pc (returned by libunwindstack) to a symbol name, we need below things: 1. The mapping info of the vdex file containing the dex_pc. 2. The offsets of dex files in the vdex file. So make below changes: 1. Record none executable maps when profiling java code. 2. Refactor dso code to add a new type for dex file, using DexFileDso to store dex file offsets in a vdex file, and load symbols from that vdex file. 3. Add read_dex_file.cpp to read java symbols using libdexfile. 4. Change the format of file section in record_file_format.h, to store dex file offsets in vdex files. Bug: http://b/73126888 Bug: http://b/77236599 Test: Run simpleperf to profile several apps manually, can see Test: callstacks of both java code and native code. Test: Run simpleperf_unit_test. Change-Id: I08005a03beb3df1a70db034bc463f555934856ba
2018-03-08simpleperf: improve managing temp files.Yabin Cui
Instead of relying on callers to delete temp files, support managing all temp files in ScopedTempFiles. Bug: http://b/73127105 Test: run simpleperf_unit_test and simpleperf manually. Change-Id: Ib73065754657320ebd244f676e3f851544ff2718
2017-11-02simpleperf: fix callchains generated by the kernel.Yabin Cui
The kernel stores return addrs in the callchain, but we want the addrs of call instructions along the callchain. So adjust callchains generated by the kernel. Also avoid using const_cast<> in record.cpp by constructing Record classes with non const buffers. Bug: None. Test: `python report_html.py --add_disassembly`. Test: run simpleperf_unit_test. Change-Id: I8c5f369e333ec9bc96cf5b5166ac670c3e3b5c62
2017-08-11simpleperf: improve warning msg.Yabin Cui
The warning of missing symbol for each lib is shown twice, once in recording, and once in reporting. This is redundant and maybe misleading. Because when reporting we actually don't know if we have collected enough symbols in perf.data. So move warning of missing symbols to debug info if we have symbols in perf.data. Use customized StderrLogger, because simpleperf doesn't need time,pid,tid information in log. Bug: http://b/29574526 Test: run simpleperf manually and run simpleperf_unit_test. Change-Id: I9baf6d8fdcd63907681f2daa45b8fad6bf7e2516
2017-05-19simpleperf: support [vdso].Yabin Cui
Before this CL, there is no way to parse symbols from [vdso] or unwind through it. In this CL, simpleperf dumps [vdso] segment in its own memory space to local file system, so it can be used for getting symbols or unwinding. It takes care that vdso files for 32bit version and 64bit version are not misused. Bug: None. Test: run simpleperf_unit_test. Test: run simpleperf on processes using vdso. Change-Id: I9233daf1d07df262a4a0fcdeadd3e544f3ccc906