android核心技术之性能分析工具Systrace

本文介绍如何利用Systrace工具诊断并解决Android应用在显示动画或进行用户交互时出现的性能问题,通过分析系统行为,找出可能导致帧率下降的原因。

转载自:https://blog.youkuaiyun.com/hfreeman2008/article/details/53538155

Systrace

While developing your application, you should check that user interactions are buttery smooth, running at a consistent 60 frames per second. If something goes wrong, and a frame gets dropped, the first step in fixing the problem is understanding what the system is doing.

一般来说,我们的机器以60帧/秒显示时(也就是16.6 millisecond),用户会感觉机器会流畅。如果出现显示时出现丢帧的情况,我们要知道系统在做什么。

Systrace collects system and application process execution data and generates detailed, interactive reports from devices running Android 4.1 and higher.

Systrace 是用来收集系统和应用的数据信息和一些中间生成数据的细节,在Android 4.1系统和4.1之后的系统。

The Systrace tool is particularly useful in diagnosing display problems where an application is slow to draw or stutters while displaying motion or animation.

Systrace在一些分析显示的问题上特别有用,如应用画图慢,显示动作或动画时变形等。

What it’s good for: 
• Evaluating container performance.(评估性能) 
• Finding performance bottlenecks in the execution of your code.(查找性能瓶颈)

启动Systrace

先把手机的Trace功能打开:Settings > Developer options > Monitoring > Enable traces.

如果是Eclipse,直击点击DDMS的Systrace图标,如果是Android Studio,则Tools–android–Android Device Monitor,再点击DDMS的Systrace图标,如下图:

这里写图片描述

在执行收集信息前,先填写一些配置信息:

这里写图片描述

生成trace.html 文件后,直接在浏览器中打开就可以。

这里写图片描述

我们可以看到此界面的Frame的圆圈会显示三种颜色,绿,黄,红。一般红色就是有问题的,要优化的地方。

我们操作此界面的方法如下:

KeyDescription
wZoom into the trace timeline
sZoom out of the trace timeline
aPan left on the trace timeline
dPan right on the trace timeline.
eCenter the trace timeline on the current mouse location.
gShow grid at the start of the currently selected task.
Shift+gShow grid at the end of the currently selected task.
Right ArrowSelect the next event on the currently selected timeline.
Left ArrowSelect the previous event on the currently selected timeline.

m可以显示选中方法的时间。

Systrace does automatic analysis of the events in the trace, and highlights many performance problems as alerts, suggesting what to do next. 
Systrace会自动分析信息,将性能问题直接以alerts的方式高亮显示,我们只要修改这些alerts就可以。

Alert如下图:

这里写图片描述

我们可以看到Alert的详细信息,描述和建议。这个Alert是可以定位到有问题的方法。如果我们想要知道方法的更详细信息,我们可以结合Traceview来解决问题。

参考资料

1.Android性能优化之Systrace分析UI性能 
http://blog.youkuaiyun.com/neacy_zz/article/details/50404863 
2.Systrace Walkthrough 
https://developer.android.com/studio/profile/systrace-walkthru.html 
3.Systrace 
https://developer.android.com/studio/profile/systrace-commandline.html 
4.Analyzing UI Performance with Systrace 
https://developer.android.com/studio/profile/systrace.html


下载前必看:https://pan.quark.cn/s/a4b39357ea24 在本资料中,将阐述如何运用JavaScript达成单击下拉列表框选定选项后即时转向对应页面的功能。 此种技术适用于网页布局中用户需迅速选取并转向不同页面的情形,诸如网站导航栏或内容目录等场景。 达成此功能,能够显著改善用户交互体验,精简用户的操作流程。 我们须熟悉HTML里的`<select>`组件,该组件用于构建一个选择列表。 用户可从中选定一项,并可引发一个事件来响应用户的这一选择动作。 在本次实例中,我们借助`onchange`事件监听器来实现当用户在下拉列表框中选定某个选项时,页面能自动转向该选项关联的链接地址。 JavaScript里的`window.location`属性旨在获取或设定浏览器当前载入页面的网址,通过变更该属性的值,能够实现页面的转向。 在本次实例的实现方案里,运用了`eval()`函数来动态执行字符串表达式,这在现代的JavaScript开发实践中通常不被推荐使用,因为它可能诱发安全问题及难以排错的错误。 然而,为了本例的简化展示,我们暂时搁置这一问题,因为在更复杂的实际应用中,可选用其他方法,例如ES6中的模板字符串或其他函数来安全地构建和执行字符串。 具体到本例的代码实现,`MM_jumpMenu`函数负责处理转向逻辑。 它接收三个参数:`targ`、`selObj`和`restore`。 其中`targ`代表要转向的页面,`selObj`是触发事件的下拉列表框对象,`restore`是标志位,用以指示是否需在转向后将下拉列表框的选项恢复至默认的提示项。 函数的实现通过获取`selObj`中当前选定的`selectedIndex`对应的`value`属性值,并将其赋予`...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值