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

2

$ cd android-sdk/platform-tools/systrace

$ python systrace.py --time=10 -o mynewtrace.html sched gfx view wm

从上面的命令可以看到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

2

alias st-start='python /home/gaojianwu/Software/android-studio/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-gfx-mx4 即可,当然为了区分和保持各个文件,还需要加上 -o xxx.Trace .上面的命令和参数不必一次就理解,只需要记住如何简单使用即可,在分析的过程中,这些东西都会慢慢熟悉的。

转自:http://blog.csdn.net/hard_working1/article/details/50602345

systrace html空白,Android性能优化之Systrace工具介绍(一) _ Systrace生成的trace.html打开空白或者打不开的解决办法...相关推荐

  1. android profile分析器,Android性能优化之分析工具Profile的使用

    Profile 是AndroidStudio3.0之后新加的功能,Profile分为三大块分析:CPU.内存和网络,本篇主要介绍内存分析. 一.首先我们开下Profile怎么开始使用? 点击下图按钮运 ...

  2. Android性能优化之分析工具Profile的使用

    Profile 是AndroidStudio3.0之后新加的功能,Profile分为三大块分析:CPU.内存和网络,本篇主要介绍内存分析. 一.首先我们开下Profile怎么开始使用? 点击下图按钮运 ...

  3. Android性能优化典范第二季

    原文链接:http://hukai.me/android-performance-patterns-season-2/ 1)Battery Drain and Networking 对于手机程序,网络 ...

  4. Android 系统性能优化(14)---Android性能优化典范 - 第2季

    1)Battery Drain and Networking 对于手机程序,网络操作相对来说是比较耗电的行为.优化网络操作能够显著节约电量的消耗.在性能优化第1季里面有提到过,手机硬件的各个模块的耗电 ...

  5. Android 性能优化探究

    使用ViewStub动态载入布局.避免一些不常常的视图长期握住引用: ViewStub的一些特点: 1. ViewStub仅仅能Inflate一次,之后ViewStub对象被置空:某个被ViewStu ...

  6. Android 性能优化(62)---存检测、卡顿优化、耗电优化、APK瘦身——详解篇

    Android 性能优化,内存检测.卡顿优化.耗电优化.APK瘦身--详解篇 自2008年智能时代开始,Android操作系统一路高歌,10年智能机发展之路,如今 Android 9.0 代号P  都 ...

  7. Android 性能优化探究,不愧是Alibaba技术官

    4)Why 60fps? 我们通常都会提到60fps与16ms,可是知道为何会是以程序是否达到60fps来作为App性能的衡量标准吗?这是因为人眼与大脑之间的协作无法感知超过60fps的画面更新. 1 ...

  8. Android性能优化典范 - 第2季

    Google前几天刚发布了Android性能优化典范第2季的课程,一共20个短视频,包括的内容大致有:电量优化,网络优化,Wear上如何做优化,使用对象池来提高效率,LRU Cache,Bitmap的 ...

  9. Android性能优化典范(二)

    转自: http://www.csdn.net/article/2015-04-29/2824583-android-performance-patterns-season-2/1 摘要:Google ...

最新文章

  1. spring之AOP的简单实例
  2. MyBatis学习总结(一)——MyBatis快速入门
  3. 字节跳动2019暑期实习生算法岗笔试题
  4. 最强的Attention函数诞生啦,带给你意想不到的巨大提升!
  5. [转]GridView导出Excel总结
  6. 2015年第六届蓝桥杯C/C++ A组国赛 —— 第三题:显示二叉树
  7. 如何开启/关闭SMTP路由调试
  8. dedecms如何调用当前栏目的子栏目及子栏目文章
  9. tableau使用_使用Tableau升级Kaplan-Meier曲线
  10. 支付宝前端推出《Web前端开发入门手册》
  11. QT 015 【数据库】 QSqlTableModel Class
  12. 解决int和Integer不能互转
  13. modbus发送接收_自己编写MODBUS协议代码所踩过的坑
  14. excel中的颜色代码(colorIndex)
  15. 百度推广怎么调整计算机优先,百度竞价优化关于帐户层级的一些设置方法与技巧...
  16. 自定义安装官方Microsoft Office 2019
  17. 双线虚拟主机服务器,国内双线虚拟主机是什么
  18. 大数据工程师面临哪些行业机遇与挑战?
  19. OSPF报文与LSA
  20. 练习:排序数组中查找元素的第一个和最后一个位置

热门文章

  1. 使用.Net Core实现FNV分布式hash一致性算法
  2. 尝鲜.net core2.1 ——编写一个global tool
  3. ASP.NET Core MVC 控制器创建与依赖注入
  4. React-引领未来的用户界面开发框架-读书笔记(三)
  5. C#(Sharp)进阶篇:文件操作
  6. 【ArcGIS风暴】ArcGIS 10.8中计算体积的方法总结
  7. C语言试题七十一之请编写函数求出这个数的阶乘
  8. Wireshark和 TcpDump抓包分析心得
  9. Android之PullToRefresh(ListView 、GridView 、WebView)使用详解和总结
  10. bootstrap 一排5个_Bootstrap5 列(Columns)