simple-perf工具(一)

前言:

Android性能工具离不开的就是systrace,还有traceview,那么在系统的性能优化中,还有哪些工具比较好而且易于使用呢?今天我们就来聊一下aosp的simple-perf工具。

原理:

现代CPU中有一个硬件组件,称为性能监控单元(PMU),PMU具有一些硬件技术器,技术一些诸如经理了多少次cpu周期,执行了多少条指令,或者发生了多少次缓存未命中的情况。linux内核将这些硬件计数器包装到硬件perf时间中,此外,linux内核还提供了独立于硬件的软件时间和跟踪点时间,linux内核通过perf_event_open系统调用将这些都暴露给了用户控件,这正是simpleperf所使用的机制。

简介:

simple-perf由两部分组成,一部分是可执行程序,而另外一部分就是python脚本。可执行程序是用来记录信息用的,而脚本文件呢,则是有3个功能:1.调用执行文件。2.上传结果。3.解析结果。

代码结构:

simpleperf是在ndk的发行版中,或者在AOSP的system/extrassimpleperf中。 可执行文件存放位置:在/system/extras/simpleperf/scripts/bin/

bin
|-android
     |-arm
       |-simpleperf
     |-arm64
       |-simpleperf
     |-x86
       |-simpleperf
     |-x86-64
       |-simpleperf
|-darwin
|-linux
|-windows 

脚本的一些功能:

具体可以查看文档
app_profiler.py: record profiling data for Android applications and native executables.
run_simpleperf_without_usb_connection.py: records profiling data while the USB cable isn’t connected. Below is an example.
binary_cache_builder.py:
run_simpleperf_on_device.py:This script pushes the simpleperf executable on the device, and run a simpleperf command on the device. It is more convenient than running adb commands manually.
report_html.py: generates report.html based on the profiling data.
pprof_proto_generator.py:It converts a profiling data file into pprof.proto, a format used by pprof.
report_sample.py: It converts a profiling data file into a format used by FlameGraph. simpleperf_report_lib.py: Python library used to parse profiling data files generated by the record command.

参考文档:

官方文档