app_package_name = “com.example.sudogame”
android_studio_project_dir = “/AndroidStudioProjects/SudoGame” # absolute path of the project
record_options = "-e cpu-cycles:u -f 4000 -g --dump-symbols --duration 30"
运行 app_profiler.py:
$python app_profiler.py
INFO:root:profiling is finished.
它将生成的 perf.data 拉到主机上,并从设备的 binary_cache 中收集二进制文件。
使用 report.py 生成报告
$python report.py -g
它生成一个GUI接口来报告数据。
使用 simpleperf_report_lib.py 处理样本
simpleperf_report_lib.py 提供了一个接口从 perf.data 读取样本。一个例子是 report_sample.py。
展示流程图
$python report_sample.py >out.perf
$stackcollapse-perf.pl out.perf >out.folded
$./flamegraph.pl out.folded >a.svg
注解源代码
annotate.py 读取 perf.data 和 binary_cache 下的二进制文件。然后它知道每个样本命中哪个 源文件:line。因此它可以注解源代码。annotate.py 由 annotate.config 配置。下面是一个例子。
annotate.config:
source_dirs = [“/AndroidStudio/SudoGame”] # It is a directory containing source code.
运行 annotate.py:
$python annotate.py
它生成 annotated_files 目录。 annotated_files/summary 文件包含每个源文件的概要信息。例子如下。
/AndroidStudioProjects/SudoGame/app/src/main/jni/sudo-game-jni.cpp: accumulated_period: 25.587937%, period: 1.250961%
function (checkValid(Board const&, int, int)): line 99, accumulated_period: 23.564356%, period: 0.908457%
function (canFindSolution_r(Board&, int, int)): line 135, accumulated_period: 22.260125%, period: 0.142359%
function (canFindSolution(Board&)): line 166, accumulated_period: 22.233101%, period: 0.000000%
function (Java_com_example_sudogame_GameModel_canFindSolution): line 470, accumulated_period: 21.983184%, period: 0.000000%
function (Java_com_example_sudogame_GameModel_initRandomBoard): line 430, accumulated_period: 2.226896%, period: 0.000000%
line 27: accumulated_period: 0.011729%, period: 0.000000%
line 32: accumulated_period: 0.004362%, period: 0.000000%
line 33: accumulated_period: 0.004427%, period: 0.000000%
line 36: accumulated_period: 0.003303%, period: 0.000000%
line 39: accumulated_period: 0.010367%, period: 0.004123%
line 41: accumulated_period: 0.162219%, period: 0.000000%
annotated_files/ 还包含由 annotate.py 找到的经过注解的源文件。比如, libsudo-game-jni.cpp 中的 checkValid() 函数的一部分注解后如下。
/* [func] acc_p: 23.564356%, p: 0.908457% */static bool checkValid(const Board& board, int curR, int curC) {
/* acc_p: 0.037933%, p: 0.037933% */ int digit = board.digits[curR][curC];
/* acc_p: 0.162355%, p: 0.162355% */ for (int r = 0; r < BOARD_ROWS; ++r) {
/* acc_p: 0.020880%, p: 0.020880% */ if (r == curR) {
/* acc_p: 0.034691%, p: 0.034691% */ continue;
/* acc_p: 0.176490%, p: 0.176490% */ if (board.digits[r][curC] == digit) {
/* acc_p: 14.957673%, p: 0.059022% */ LOGI("conflict (%d, %d) (%d, %d)", curR, curC, r, curC);
/* acc_p: 0.016296%, p: 0.016296% */ return false;
什么是simpleperfSimpleperf是Android平台的一个本地层性能分析工具。它的命令行界面支持与linux-tools perf大致相同的选项,但是它还支持许多Android特有的改进。Simpleperf是Android开源项目(AOSP)的一部分。其源代码 位于。其最新的文档 位于。Bugs 和 功能需求可以提交到 githb上。Simpleperf是如何工作的现代的C...
simpleperf介绍
Simpleperf是Android平台的一个本地层性能分析工具。它的命令行界面支持与linux-tools perf大致相同的选项,但是它还支持许多Android特有的改进。
simpleperf原理
CPU具有一个硬件组件,称为性能监控单元(PMU)。PMU具有一些硬件计数器,计数一些诸如 经历了多少次CPU周期,执行了多少条指令,或发生了多少次缓存未命中 等的事件。
Linux内核将这些硬件计数器包装到硬件perf事件 (hardware perf events)中。
Simpleperf下载
下载Android ndk-bundle ,在simpleperf/bin/android目录下包含有不同体系架构的 Android 上运行的静态二进制文件,在arm目录下打开命令窗口,执行命令:
adb push simpleperf data/data/
adb shell
cd data/data/
chmod 777 simpleperf
./simpleperf stat -p xxx(pid 或tid) --duration xxx(时间)
Simpleperf的工
Simpleperf 是Google随NDK一起发布的一款profile工具(注:从NDK r13开始),它是针对Android平台的一个本地层性能分析工具。它的命令行界面支持与linux-tools perf大致相同的选项,但是它还支持许多Android特有的改进。
一、常用命令
1、Simpleperf 的三个主要功能:
(1)Stat 命令:给出了在一个时间段内被分析的进程中发生了多少事件的摘要。
(2)Record 命令:在一段时间内记录剖析进程的样本,生成 perf.data 文件。
(3)Rep
simpleperf 的使用
stat命令获取一段时间内已分析进程中发生的事件数摘要。 最常使用的选项为:
./simpleperf stat -p 进程号 --duration 检测进程的持续时间(秒)
Performance counter statistics:
1,741,676,073 cpu-cycles # 0.029027 GHz (100%)
598,139,456 instructions
android性能分析之Systrace
android性能分析之常用命令
Android Studio 包含 Simpleperf 的图形前端,记录在使用 CPU 性能剖析器检查 CPU 活动中。大多数用户更喜欢使用该图形前端,而不是直接使用 Simpleperf。
Android Profiler分析(一)概述
Android Profiler分析(二) Memory Profiler
Android Profiler分析(三) CPU Profiler
如果您更喜欢使用命令行,可以直接使用 Simpl
关于 simpleperf
simpleperf 是 google 随 NDK 一起发布的一款 profile 工具,从 NDK r13 开始
官方文档请参考 google 在 NDK 里放的 README
HelloWorld 步骤
把 simpleperf 可执行程序 push 到手机上。 simpleperf 在 NDK-r13b 的 simpleperf/android/ 里。根据被测程序和
一、安装准备
1.安装perl:网址:https://www.perl.org/get.html,下载速度可能有点慢,因为是外网,不要着急。
2.安装两个包:FlameGraph-master.zip、simpleperf-master.tar.gz,FlameGraph可以在网址https://github.com/brendangregg/FlameGraph上下载。
如果要抓手机的,还需要下一个文件push到手机里:simpleperf。
以vivo手机为例
1.将simpleperf下载到
Simpleperf是Android的一个命令行工具,用于分析Android设备上的C代码性能。下面是使用Simpleperf分析C代码性能的步骤:
1. 在Android设备上安装Simpleperf:
- 使用adb工具连接到Android设备:
adb connect <device_ip_address>
- 从Android设备的/system/bin目录中拷贝simpleperf:
adb pull /system/bin/simpleperf .
2. 使用Simpleperf收集性能数据:
- 启动应用程序:
adb shell am start -n <package_name>/<activity_name>
- 运行simpleperf record命令,开始收集性能数据:
simpleperf record -g --app=<package_name>
3. 使用Simpleperf分析性能数据:
- 使用simpleperf report命令生成性能报告:
simpleperf report
- 使用simpleperf report --call-graph命令生成调用图:
simpleperf report --call-graph
注意:在使用Simpleperf之前,需要在Android设备上开启内核语言包(Kernel Headers)。如果您使用的是AOSP源代码编译的内核,则可以通过编译内核时添加LOCALVERSION=-simpleperf来开启Kernel Headers。如果您使用的是第三方内核,则可能需要手动安装Kernel Headers。