# Simpleperf
Android Studio includes a graphical front end to Simpleperf, documented in
[Inspect CPU activity with CPU Profiler](https://developer.android.com/studio/profile/cpu-profiler).
Most users will prefer to use that instead of using Simpleperf directly.
Simpleperf is a native CPU profiling tool for Android. It can be used to profile
both Android applications and native processes running on Android. It can
profile both Java and C++ code on Android. The simpleperf executable can run on Android >=L,
and Python scripts can be used on Android >= N.
Simpleperf is part of the Android Open Source Project.
The source code is [here](https://android.googlesource.com/platform/system/extras/+/master/simpleperf/).
The latest document is [here](https://android.googlesource.com/platform/system/extras/+/master/simpleperf/doc/README.md).
[TOC]
## Introduction
An introduction slide deck is [here](./introduction.pdf).
Simpleperf contains two parts: the simpleperf executable and Python scripts.
The simpleperf executable works similar to linux-tools-perf, but has some specific features for
the Android profiling environment:
1. It collects more info in profiling data. Since the common workflow is "record on the device, and
report on the host", simpleperf not only collects samples in profiling data, but also collects
needed symbols, device info and recording time.
2. It delivers new features for recording.
1) When recording dwarf based call graph, simpleperf unwinds the stack before writing a sample
to file. This is to save storage space on the device.
2) Support tracing both on CPU time and off CPU time with --trace-offcpu option.
3) Support recording callgraphs of JITed and interpreted Java code on Android >= P.
3. It relates closely to the Android platform.
1) Is aware of Android environment, like using system properties to enable profiling, using
run-as to profile in application's context.
2) Supports reading symbols and debug information from the .gnu_debugdata section, because
system libraries are built with .gnu_debugdata section starting from Android O.
3) Supports profiling shared libraries embedded in apk files.
4) It uses the standard Android stack unwinder, so its results are consistent with all other
Android tools.
4. It builds executables and shared libraries for different usages.
1) Builds static executables on the device. Since static executables don't rely on any library,
simpleperf executables can be pushed on any Android device and used to record profiling data.
2) Builds executables on different hosts: Linux, Mac and Windows. These executables can be used
to report on hosts.
3) Builds report shared libraries on different hosts. The report library is used by different
Python scripts to parse profiling data.
Detailed documentation for the simpleperf executable is [here](#executable-commands-reference).
Python scripts are split into three parts according to their functions:
1. Scripts used for recording, like app_profiler.py, run_simpleperf_without_usb_connection.py.
2. Scripts used for reporting, like report.py, report_html.py, inferno.
3. Scripts used for parsing profiling data, like simpleperf_report_lib.py.
The python scripts are tested on Python >= 3.9. Older versions may not be supported.
Detailed documentation for the Python scripts is [here](#scripts-reference).
## Tools in simpleperf
The simpleperf executables and Python scripts are located in simpleperf/ in ndk releases, and in
system/extras/simpleperf/scripts/ in AOSP. Their functions are listed below.
bin/: contains executables and shared libraries.
bin/android/${arch}/simpleperf: static simpleperf executables used on the device.
bin/${host}/${arch}/simpleperf: simpleperf executables used on the host, only supports reporting.
bin/${host}/${arch}/libsimpleperf_report.${so/dylib/dll}: report shared libraries used on the host.
*.py, inferno, purgatorio: Python scripts used for recording and reporting. Details are in [scripts_reference.md](scripts_reference.md).
## Android application profiling
See [android_application_profiling.md](./android_application_profiling.md).
## Android platform profiling
See [android_platform_profiling.md](./android_platform_profiling.md).
## Executable commands reference
See [executable_commands_reference.md](./executable_commands_reference.md).
## Scripts reference
See [scripts_reference.md](./scripts_reference.md).
## View the profile
See [view_the_profile.md](./view_the_profile.md).
## Answers to common issues
### Support on different Android versions
On Android < N, the kernel may be too old (< 3.18) to support features like recording DWARF
based call graphs.
On Android M - O, we can only profile C++ code and fully compiled Java code.
On Android >= P, the ART interpreter supports DWARF based unwinding. So we can profile Java code.
On Android >= Q, we can used simpleperf shipped on device to profile released Android apps, with
`<profileable android:shell="true" />`.
### Comparing DWARF based and stack frame based call graphs
Simpleperf supports two ways recording call stacks with samples. One is DWARF based call graph,
the other is stack frame based call graph. Below is their comparison:
Recording DWARF based call graph:
1. Needs support of debug information in binaries.
2. Behaves normally well on both ARM and ARM64, for both Java code and C++ code.
3. Can only unwind 64K stack for each sample. So it isn't always possible to unwind to the bottom.
However, this is alleviated in simpleperf, as explained in the next section.
4. Takes more CPU time than stack frame based call graphs. So it has higher overhead, and can't
sample at very high frequency (usually <= 4000 Hz).
Recording stack frame based call graph:
1. Needs support of stack frame registers.
2. Doesn't work well on ARM. Because ARM is short of registers, and ARM and THUMB code have
different stack frame registers. So the kernel can't unwind user stack containing both ARM and
THUMB code.
3. Also doesn't work well on Java code. Because the ART compiler doesn't reserve stack frame
registers. And it can't get frames for interpreted Java code.
4. Works well when profiling native programs on ARM64. One example is profiling surfacelinger. And
usually shows complete flamegraph when it works well.
5. Takes much less CPU time than DWARF based call graphs. So the sample frequency can be 10000 Hz or
higher.
So if you need to profile code on ARM or profile Java code, DWARF based call graph is better. If you
need to profile C++ code on ARM64, stack frame based call graphs may be better. After all, you can
fisrt try DWARF based call graph, which is also the default option when `-g` is used. Because it
always produces reasonable results. If it doesn't work well enough, then try stack frame based call
graph instead.
### Fix broken DWARF based call graph
A DWARF-based call graph is generated by unwinding thread stacks. When a sample is recorded, a
kernel dumps up to 64 kilobytes of stack data. By unwinding the stack based on DWARF information,
we can get a call stack.
Two reasons may cause a broken call stack:
1. The kernel can only dump up to 64 kilobytes of stack data for each sample, but a thread can have
much larger stack. In this case, we can't unwind to the thread start point.
2. We need binaries containing DWARF call frame information to unwind stack frames. The binary
should have one of the following sections: .eh_frame, .debug_frame, .ARM.exidx or .gnu_debugdata.
To mitigate these problems,
For the missing stack data problem:
1. To alleviate it, simpleperf joins callchains (call stacks) after recording. If two callchains of
a thread have an entry containing the same ip and sp address, then simpleperf tries to join them
to make the callchains longer. So we can get more complete callchains by recording longer and
joining more samples. This do
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
android-ndk-r26d-linux.zip (2000个子文件)
NdkCameraMetadataTags.h 523KB
NeuralNetworksTypes.h 300KB
gl2ext.h 213KB
uchar.h 167KB
urename.h 136KB
gl32.h 125KB
OpenMAXAL.h 107KB
NeuralNetworks.h 107KB
gl31.h 105KB
ubidi.h 93KB
gl3.h 81KB
OpenSLES.h 80KB
v4l2-controls.h 76KB
binder_parcel_utils.h 70KB
nl80211.h 62KB
ustring.h 61KB
shared_ptr.h 60KB
input.h 55KB
uloc.h 54KB
videodev2.h 54KB
math.h 52KB
glext.h 52KB
utf_old.h 52KB
jni.h 51KB
kvm.h 48KB
NdkCameraCaptureSession.h 47KB
NdkCameraDevice.h 47KB
binder_parcel.h 45KB
sort.h 44KB
gl2.h 43KB
imagedecoder.h 41KB
ucol.h 40KB
sensor.h 38KB
expected.h 37KB
function.h 36KB
uscript.h 35KB
binder_ibinder.h 35KB
bpf.h 34KB
pci_regs.h 34KB
i915_drm.h 34KB
parser_std_format_spec.h 33KB
path.h 33KB
utypes.h 33KB
habanalabs_accel.h 33KB
platform.h 32KB
NdkImage.h 32KB
formatter_floating_point.h 31KB
gl.h 31KB
utf8.h 31KB
ethtool.h 30KB
bitvect.h 30KB
keycodes.h 30KB
extended_grapheme_cluster_table.h 30KB
char_traits.h 28KB
zorro_ids.h 28KB
formatter.h 28KB
v4l2-dv-timings.h 28KB
format_functions.h 27KB
soundcard.h 27KB
surface_control.h 27KB
NdkCaptureRequest.h 27KB
radeon_drm.h 27KB
unique_ptr.h 27KB
NdkMediaDrm.h 26KB
bytecode.h 26KB
configuration.h 25KB
ib_user_verbs.h 25KB
uninitialized_algorithms.h 25KB
nf_tables.h 25KB
pair.h 25KB
mersenne_twister_engine.h 25KB
utf16.h 25KB
cec.h 24KB
utext.h 24KB
hardware_buffer.h 23KB
formatter_output.h 23KB
NdkImageReader.h 23KB
NdkMediaCodec.h 23KB
comedi.h 22KB
amdgpu_drm.h 22KB
compat-queue.h 22KB
if_link.h 22KB
duration.h 21KB
unorm2.h 21KB
buffer.h 21KB
unistd-oabi.h 21KB
arch.h 21KB
input-event-codes.h 20KB
unistd-eabi.h 20KB
reverse_iterator.h 20KB
btrfs.h 20KB
sysctl.h 20KB
pkt_sched.h 20KB
ethtool_netlink.h 20KB
utrans.h 20KB
drm.h 20KB
escaped_output_table.h 20KB
hash.h 20KB
NdkCameraManager.h 19KB
file.h 19KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
m0_60881280
- 粉丝: 1
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 【小程序毕业设计】讲座预约系统微信小程序源码(完整前后端+mysql+说明文档+LW).zip
- 【小程序毕业设计】驾校报名小程序源码(完整前后端+mysql+说明文档+LW).zip
- 程序设计竞赛-在线判题系统(OJ系统)【含Web端+判题端】+项目源码+文档说明
- 大数据时代下短视频观看行为数据采集与分析的设计与实现
- 【小程序毕业设计】图书馆座位再利用系统源码(完整前后端+mysql+说明文档).zip
- 【小程序毕业设计】自习室预约系统源码(完整前后端+mysql+说明文档).zip
- 【小程序毕业设计】智能停车场管理系统源码(完整前后端+mysql+说明文档+LW).zip
- ssm练习项目-Java《基于ssm框架实现在线医院挂号系统》+项目源码+文档说明
- 【小程序毕业设计】游泳馆管理系统源码(完整前后端+mysql+说明文档+LW).zip
- 【小程序毕业设计】药店管理系统源码(完整前后端+mysql+说明文档).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功