Android性能优化之Systrace工具介绍(一) _&& Systrace生成的trace.html打开空白或者打不开的解决办法
1.必须用Chrome打开
2.在mac电脑上,可能Chrome打开也是空白,解决办法是:在chrome地址栏中输入”chrome:tracing”,然后点击load按钮load你的trace.html文件。
Systrace简单介绍
Systrace是Android4.1中新增的性能数据采样和分析工具。它可帮助开发者收集Android关键子系统(如surfaceflinger、WindowManagerService等Framework部分关键模块、服务,View系统等)的运行信息,从而帮助开发者更直观的分析系统瓶颈,改进性能。
Systrace的功能包括跟踪系统的I/O操作、内核工作队列、CPU负载以及Android各个子系统的运行状况等。在Android平台中,它主要由3部分组成:
- 内核部分:Systrace利用了Linux Kernel中的ftrace功能。所以,如果要使用Systrace的话,必须开启kernel中和ftrace相关的模块。
- 数据采集部分:Android定义了一个Trace类。应用程序可利用该类把统计信息输出给ftrace。同时,Android还有一个atrace程序,它可以从ftrace中读取统计信息然后交给数据分析工具来处理。
- 数据分析工具:Android提供一个systrace.py(python脚本文件,位于Android SDK目录/tools/systrace中,其内部将调用atrace程序)用来配置数据采集的方式(如采集数据的标签、输出文件名等)和收集ftrace统计数据并生成一个结果网页文件供用户查看。 从本质上说,Systrace是对Linux Kernel中ftrace的封装。应用进程需要利用Android提供的Trace类来使用Systrace.
关于Systrace的官方介绍和使用可以看这里:Systrace
Systrace简单使用
使用Systrace前,要先了解一下Systrace在各个平台上的使用方法,鉴于大家使用Eclipse和Android Studio的居多,所以直接摘抄官网关于这个的使用方法,不过不管是什么工具,流程是一样的:
- 手机准备好你要进行抓取的界面
- 点击开始抓取(命令行的话就是开始执行命令)
- 手机上开始操作
- 设定好的时间到了之后,会将生成Trace文件,使用Chrome将这个文件打开进行分析
Using Eclipse
In Eclipse, open an Android application project.
- Switch to the DDMS perspective, by selecting Window > Perspectives > DDMS.
- In the Devices tab, select the device on which to run a trace. If no devices are listed, make sure your device is connected via USB cable and that debugging is enabled on the device.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set the tracing options and click OK to start the trace.
Using Android Studio
In Android Studio, open an Android application project.
- Open the Device Monitor by selecting Tools > Android > Monitor.
- In the Devices tab, select the device on which to run a trace. If no devices are listed, make sure your device is connected via USB cable and that debugging is enabled on the device.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set the tracing options and click OK to start the trace.
Using Device Monitor
Navigate to your SDK tools/ directory.
- Run the monitor program.
- In the Devices tab, select the device on which to run a trace. If no devices are listed, make sure your device is connected via USB cable and that debugging is enabled on the device.
- Click the Systrace icon at the top of the Devices panel to configure tracing.
- Set the tracing options and click OK to start the trace.
Command Line Usage
命令行形式比较灵活,速度也比较快,一次性配置好之后,以后再使用的时候就会很快就出结果(强烈推荐)
1 |
$ cd android-sdk/platform-tools/systrace |
从上面的命令可以看到Systrace工具的位置,只需要在Bash中配置好对应的路径和Alias,使用起来还是很快速的。另外User版本是不可以抓Trace的,只有ENG版本或者Userdebug版本才可以。
抓取结束后,会生成对应的Trace文件,注意这个文件只能被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,配置如下:
1 |
alias st-start='python /home/gaojianwu/Software/android-studio/sdk/platform-tools/systrace/systrace.py' |
这样在使用的时候,可以直接敲 st-start-gfx-mx4 即可,当然为了区分和保持各个文件,还需要加上 -o xxx.Trace .上面的命令和参数不必一次就理解,只需要记住如何简单使用即可,在分析的过程中,这些东西都会慢慢熟悉的。
转自:http://blog.csdn.net/hard_working1/article/details/50602345
Android性能优化之Systrace工具介绍(一) _&& Systrace生成的trace.html打开空白或者打不开的解决办法的更多相关文章
- Android 性能优化之工具和优化点总结
Android性能优化学习 最近公司主抓性能优化工作,借此春风也学习到了许多Android性能优化方面的知识.由于组内队友的给力,优化的成果也是比较喜人.同时也学习和实践了不少知识,特此记录. 1.性 ...
- Android开发学习之路--性能优化之常用工具
android性能优化相关的开发工具有很多很多种,这里对如下六个工具做个简单的使用介绍,主要有Android开发者选项,分析具体耗时的Trace view,布局复杂度工具Hierarchy Vie ...
- (转)Android性能优化——工具篇
Android性能优化是Android开发中经常遇见的一个问题,接下来将对Android性能优化方面的知识点做一个简单的梳理和总结,将从工具和代码两方面进行梳理.所谓工欲善其事必先利其器,本文首先来看 ...
- Linux/Android 性能优化工具 perf
/***************************************************************************** * Linux/Android 性能优化工 ...
- 【腾讯Bugly干货分享】Android性能优化典范——第6季
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/580d91208d80e49771f0a07c 导语 这里是Android性能优 ...
- Android性能优化典范(二)
Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的 ...
- android app性能优化大汇总(google官方Android性能优化典范 - 第2季)
Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的 ...
- Android性能优化典范 - 第2季
Google发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的缩放,缓 ...
- Android性能优化:布局优化 详细解析(含<include>、<ViewStub>、<merge>讲解 )
1. 影响的性能 布局性能的好坏 主要影响 :Android应用中的页面显示速度 2. 如何影响性能 布局影响Android性能的实质:页面的测量 & 绘制时间 1个页面通过递归 完成测量 & ...
随机推荐
- 统计整个Xcode工程代码行数
打开终端,ls 查看目录,用cd命令 定位到工程所在的目录,然后调用以下命名即可把每个源代码文件行数及总数统计出来: find . "(" -name "*.m" ...
- Serena Dimensions 介绍
Serena Dimensions是配置管理工具,基于进程的软件更改和配置管理解决方案. 官方网址:http://www.serena.com/index.php/en/products/applic ...
- mysql技巧之select count的比较
在工作过程中,时不时会有开发咨询几种select count()的区别,我总会告诉他们使用select count(*) 就好.下文我会展示几种sql的执行计划来说明为啥是这样. 1.测试 ...
- Mysql 创建用户 授权
一, 创建用户: 命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明:username - 你将创建的用户名, host - 指 ...
- Jade模板引擎(一)之Attributes
目录: Attributes Boolean Attributes Style Attributes Class Attributes &Attributes Attributes jade中 ...
- LeetCode#227.Basic Calculator II
题目 Implement a basic calculator to evaluate a simple expression string. The expression string contai ...
- JQuery入门——进度条
越来越觉得常规javascript已经跟不上节奏了,打算学点进阶的,从JQuery学起. JQuery是一个Javascript库,可以从JQuery.com下载,放到本地,用 <script ...
- mybatis 插入数据时返回主键
在使用MyBatis做持久层时,insert语句默认是不返回记录的主键值,而是返回插入的记录条数:显然,假如主键是你生成后插入的,自然你已经有主键了,显然不需要我们再去获得,所以我们这里处理的是当主键 ...
- hadoop2.6---windows下开发环境搭建
一.准备插件 1.自己编译 1.1 安装Ant 官网下载Ant,apache-ant-1.9.6-bin.zip 配置环境变量,新建ANT_HOME,值是E:\apache-ant-1.9.6:PAT ...
- Arch Linux sudo: PAM authentication error: Module is unknown [Solved!]
问题描述: 我的 Arch Linux 已经用了快半年多,由于 Arch Linux 的滚挂问题,我从没有直接升级过系统.软件版本以及库自然落后了一些. 就在我准备需要用到 NFS 时,挂载网络文件系 ...