本文是Systrace系列文章的第一篇,主要对Systrace进行简要介绍,并介绍其简单使用方法; 怎么去看Systrace; 如何结合其他工具分析Systrace现象。
本系列的目的是通过一个名为Systrace的工具,从另一个角度观察整个Android系统的行为,同时也从另一个角度学习Framework。 你可能读过很多关于Framework的故事,但是代码很难记住,或者执行的流程不清晰。 从Systrace这个图形化的观点来看,也许可以更深入地理解。
系列文章目录
系统介绍
Systrace基础知识- Systrace预备知识
Systrace基础知识- Why 60 fps?
Systrace基础知识- SystemServer解读
Systrace基础知识- SurfaceFlinger解读
Systrace基础知识-输入解读
Systrace基础知识- Vsync解读
Systrace基础知识- vsync-app :详细了解基于choreographer的渲染机制
Systrace基础知识-解读- MainThread和RenderThread
Systrace基础知识- Binder与锁定冲突解读
Systrace基础知识- CPU Info解读
正文
Systrace是Android4.1中新增的性能数据采样和分析工具。 这是开发人员收集框架的主要模块、服务和安卓子系统(如surfaceflinger/systemserver/kernel/input/display )的运行信息
Systrace功能包括跟踪系统I/O操作、内核工作队列、CPU负载和Android子系统的运行状况。 在安卓平台上,主要由三部分组成。
内核部分: Systrace使用Linux Kernel的ftrace功能。 因此,如果使用Systrace,则必须打开kernel和ftrace相关的模块。
数据收集部: Android定义了Trace类。 该APP应用程序可以利用该类将统计信息输出到ftrace。 另一方面,Android还有另一个atrace程序,可以从ftrace读取统计信息并传递给数据分析工具。
数据分析工具: Android提供了systrace.py(python脚本文件,位于Android SDK目录/platform-tools/systrace中,内部为atrace程序应用进程必须使用Android提供的Trace类来使用Systrace。
有关Systrace的官方介绍和使用: Systrace
系统易于使用
在使用Systrace之前,必须知道在每个平台上使用Systrace。 因为大家经常使用Eclipse和Android Studio,所以直接摘录官方网站来说明这个的使用方法。 但是,任何工具的流程都是一样的:
手机准备好你要抓住的接口
单击以开始捕获(如果是命令行,则开始执行命令) )。
用手机开始操作(不要太长)
到了设定的时间后,生成Trace.html文件,并使用Chrome打开此文件进行分析
一般情况下捕捉到的Systrace文件如下
命令行使用
命令行格式灵活,速度也快,因此一次放置后,以后使用时会立即产生结果。 (强烈推荐) ) ) ) ) ) ) ) ) ) ) ) ) )。
Systrace工具位于Android-SDK目录中的平台工具中。 简单的使用方法如下所示
$ CD安卓- SDK /平台-工具/系统
$ python systrace.py
复制代码
Bash可以放置相应的路径和Alias,但使用起来还很快。 此外,包含用户版本的Systrce文件包含的信息少于eng或User调试版本,因此建议使用计算机的用户调试版本进行调试。 这可以在确保性能的同时获得更详细的输出结果。
捕获完成后,将生成相应的Trace.html文件。 请注意,此文件只能在Chrome中打开。 Trace文件的分析方法将在下一章中介绍。 无论使用什么工具,
在抓取之前都可以选择参数,下面说一下这些参数的意思:-h, --help Show the help message.(帮助)
-o Write the HTML trace report to the specified file.(即输出文件名,)
-t N, --time=N Trace activity for N seconds. The default value is 5 seconds. (Trace抓取的时间,一般是 : -t 8)
-b N, --buf-size=N Use a trace buffer size of N kilobytes. This option lets you limit the total size of the data collected during a trace.
-k
—ktrace= Trace the activity of specific kernel functions, specified in a comma-separated list.
-l, --list-categories List the available tracing category tags. The available tags are(下面的参数不用翻译了估计大家也看得懂,贴官方的解释也会比较权威,后面分析的时候我们会看到这些参数的作业的):
gfx - Graphics
input - Input
view - View
webview - WebView
wm - Window Manager
am - Activity Manager
audio - Audio
video - Video
camera - Camera
hal - Hardware Modules
res - Resource Loading
dalvik - Dalvik VM
rs - RenderScript
sched - CPU Scheduling
freq - CPU Frequency
membus - Memory Bus Utilization
idle - CPU Idle
disk - Disk input and output
load - CPU Load
sync - Synchronization Manager
workq - Kernel Workqueues Note: Some trace categories are not supported on all devices. Tip: If you want to see the names of tasks in the trace output, you must include the sched category in your command parameters.
-a
—app= Enable tracing for applications, specified as a comma-separated list of package names. The apps must contain tracing instrumentation calls from the Trace class. For more information, see Analyzing Display and Performance.
—link-assets Link to the original CSS or JavaScript resources instead of embedding them in the HTML trace report.
—from-file= Create the interactive Systrace report from a file, instead of running a live trace.
—asset-dir= Specify a directory for the trace report assets. This option is useful for maintaining a single set of assets for multiple Systrace reports.
-e
—serial= Conduct the trace on a specific connected device, identified by its device serial number.
上面的参数虽然比较多,但使用工具的时候不需考虑这么多,在对应的项目前打钩即可,命令行的时候才会去手动加参数:
我们一般会把这个命令配置成Alias,配置如下:
alias st-start='python /sdk/platform-tools/systrace/systrace.py'
alias st-start-gfx-trace = ‘st-start -t 8 gfx input view sched freq wm am hwui workq res dalvik sync disk load perf hal rs idle mmc’
复制代码
这样在使用的时候,可以直接敲 st-start 即可,当然为了区分和保持各个文件,还需要加上 -o xxx.html .上面的命令和参数不必一次就理解,只需要记住如何简单使用即可,在分析的过程中,这些东西都会慢慢熟悉的。
一般来说比较常用的是
-o : 指示输出文件的路径和名字
-t : 抓取时间(最新版本可以不用指定, 按 Enter 即可结束)
-b : 指定 buffer 大小(一般情况下,默认的 Buffer 是够用的,如果你要抓很长的 Trae , 那么建议调大 Buffer )
-a : 指定 app 包名 (如果要 Debug 自定义的 Trace 点, 记得要加这个)
关于我 && 博客
关于我 , 非常希望和大家一起交流 , 共同进步 .
博客内容导航
优秀博客文章记录 - Android 性能优化必知必会
一个人可以走的更快 , 一群人可以走的更远
更多内容可以进入 Android Performance 查看
关于找一找教程网
本站文章仅代表作者观点,不代表本站立场,所有文章非营利性免费分享。
本站提供了软件编程、网站开发技术、服务器运维、人工智能等等IT技术文章,希望广大程序员努力学习,让我们用科技改变世界。
[Android Systrace 基础知识 -- Systrace 简介]http://www.zyiz.net/tech/detail-136282.html