Hierarchy Viewer显示视图性能指标
Hierarchy Viewer默认打开“Tree View”窗口无法显示显示Performance indicators:
但选中根视图再点击按钮“Obtain layout times for tree rooted at selected node”:
就可以显示:
其上该视图性能的颜色指示符从左到右依次为:Measure、Layout和Draw,其中红色代表此树中该视图渲染最慢即占用总渲染时间的80%或其以上,绿色代表此树中该视图渲染时长小于总渲染时间的50%,黄色代表此树种该视图渲染时长50%或其以上但低于80%。


public class ProfileNodesAction extends SelectedNodeEnabledAction implements ImageAction {
...
public ProfileNodesAction() {
super("Profile Node");
ImageLoader imageLoader = ImageLoader.getLoader(HierarchyViewerDirector.class);
mImage = imageLoader.loadImage("profile.png", Display.getDefault()); //$NON-NLS-1$
setImageDescriptor(ImageDescriptor.createFromImage(mImage));
setToolTipText("Obtain layout times for tree rooted at selected node");
}
...
@Override
public void run() {
HierarchyViewerDirector.getDirector().profileCurrentNode();
}
...


public void profileCurrentNode() {
final DrawableViewNode selectedNode = TreeViewModel.getModel().getSelection();
if (selectedNode != null) {
executeInBackground("Profile Node", new Runnable() {
@Override
public void run() {
IHvDevice hvDevice = getHvDevice(selectedNode.viewNode.window.getDevice());
hvDevice.loadProfileData(selectedNode.viewNode.window, selectedNode.viewNode);
// Force the layout viewer to redraw.
TreeViewModel.getModel().notifySelectionChanged();
}
});
}
}


public static boolean loadProfileData(Window window, ViewNode viewNode) {
DeviceConnection connection = null;
try {
connection = new DeviceConnection(window.getDevice());
connection.sendCommand("PROFILE " + window.encode() + "" + viewNode.toString()); //$NON-NLS-1$
BufferedReader in = connection.getInputStream();
int protocol;
synchronized (sViewServerInfo) {
protocol = sViewServerInfo.get(window.getDevice()).protocolVersion;
}
if (protocol < 3) {
return loadProfileData(viewNode, in);
} else {
boolean ret = loadProfileDataRecursive(viewNode, in);
if (ret) {
viewNode.setProfileRatings();
}
return ret;
}
} catch (Exception e) {
Log.e(TAG, "Unable to load profiling data for window " + window.getTitle()
+ " on device " + window.getDevice());
} finally {
if (connection != null) {
connection.close();
}
}
return false;
} private static boolean loadProfileData(ViewNode node, BufferedReader in) throws IOException {
String line;
if ((line = in.readLine()) == null || line.equalsIgnoreCase("-1 -1 -1") //$NON-NLS-1$
|| line.equalsIgnoreCase("DONE.")) { //$NON-NLS-1$
return false;
}
String[] data = line.split("");
node.measureTime = (Long.parseLong(data[0]) / 1000.0) / 1000.0;
node.layoutTime = (Long.parseLong(data[1]) / 1000.0) / 1000.0;
node.drawTime = (Long.parseLong(data[2]) / 1000.0) / 1000.0;
return true;
} public static boolean loadProfileDataRecursive(ViewNode node, BufferedReader in)
throws IOException {
if (!loadProfileData(node, in)) {
return false;
}
for (int i = 0; i < node.children.size(); i++) {
if (!loadProfileDataRecursive(node.children.get(i), in)) {
return false;
}
}
return true;
}


public class ViewNode { public static enum ProfileRating {
RED, YELLOW, GREEN, NONE
}; private static final double RED_THRESHOLD = 0.8; private static final double YELLOW_THRESHOLD = 0.5;
... public void setProfileRatings() {
final int N = children.size();
if (N > 1) {
double totalMeasure = 0;
double totalLayout = 0;
double totalDraw = 0;
for (int i = 0; i < N; i++) {
ViewNode child = children.get(i);
totalMeasure += child.measureTime;
totalLayout += child.layoutTime;
totalDraw += child.drawTime;
}
for (int i = 0; i < N; i++) {
ViewNode child = children.get(i);
if (child.measureTime / totalMeasure >= RED_THRESHOLD) {
child.measureRating = ProfileRating.RED;
} else if (child.measureTime / totalMeasure >= YELLOW_THRESHOLD) {
child.measureRating = ProfileRating.YELLOW;
} else {
child.measureRating = ProfileRating.GREEN;
}
if (child.layoutTime / totalLayout >= RED_THRESHOLD) {
child.layoutRating = ProfileRating.RED;
} else if (child.layoutTime / totalLayout >= YELLOW_THRESHOLD) {
child.layoutRating = ProfileRating.YELLOW;
} else {
child.layoutRating = ProfileRating.GREEN;
}
if (child.drawTime / totalDraw >= RED_THRESHOLD) {
child.drawRating = ProfileRating.RED;
} else if (child.drawTime / totalDraw >= YELLOW_THRESHOLD) {
child.drawRating = ProfileRating.YELLOW;
} else {
child.drawRating = ProfileRating.GREEN;
}
}
}
for (int i = 0; i < N; i++) {
children.get(i).setProfileRatings();
}
}


/**
* This class is used for connecting to a device in debug mode running the view
* server.
*/
public class DeviceConnection {
...
public void sendCommand(String command) throws IOException {
BufferedWriter out = getOutputStream();
out.write(command);
out.newLine();
out.flush();
}
...


Hierarchy Viewer显示视图性能指标的更多相关文章
- Android 实用工具Hierarchy Viewer实战
在Android的SDK工具包中,有很多十分有用的工具,可以帮助程序员开发和测试Android应用程序,大大提高其工作效率.其中的一款叫Hierachy Viewer的可视化调试工具,可以很方便地在开 ...
- Android优化——UI检视利器:Hierarchy Viewer
在Android的SDK工具包中,有很多十分有用的工具,可以帮助程序员开发和测试Android应用程序,大大提高其工作效率.其中的一款叫 Hierachy Viewer的可视化调试工具,可以很方便地在 ...
- Hierarchy Viewer
http://blog.csdn.net/ddna/article/details/5527072 Hierarchy Viewer是随AndroidSDK发布的工具,位置在tools文件夹下,名为h ...
- 看了一本书,说可以利用Hierarchy Viewer优化布局
看了一本书,说可以利用Hierarchy Viewer优化布局,今以志之. 参考:http://www.cnblogs.com/Rocky_/archive/2011/11/04/2236243.ht ...
- 【转】【Android工具】被忽略的UI检视利器:Hierarchy Viewer
原文:http://blog.csdn.net/ddna/article/details/5527072 Hierarchy Viewer是随AndroidSDK发布的工具,位置在tools文件夹下, ...
- 利用Hierarchy Viewer优化布局
好久没更新博客了,趁着清明来写点什么. 今天来讲下如何使用android中提供的工具优化我们的布局.首先我们写一个最简单的框架布局. <?xml version="1.0" ...
- Android 卡顿优化 3 布局优化 工具 Hierarchy Viewer
欲善其事, 先利其器. 分析布局, 就不得不用到Hierarchy Viewer了. 本文工具使用皆以GithubApp的详情界面RepoDetailActivity为例说明. 为了不影响阅读体验, ...
- Android工具 Hierarchy Viewer 分析
Hierarchy Viewer是随AndroidSDK发布的工具,位置在tools文件夹下,名为hierarchyviewer.bat.它是Android自带的非常有用而且使用简单的工具,可以帮助我 ...
- Android官方命令深入分析之Hierarchy Viewer
Hierarchy Viewer允许你调试和优化用户界面.它提供了一个层可视的方式来显示. 启动Hierarchy Viewer,如下: 在Android Studio中,选择Tools > A ...
随机推荐
- .NET中TextBox控件设置ReadOnly=true后台取不到值三种解决方法
当TextBox设置了ReadOnly=true后要是在前台为控件添加了值,后台是取不到的,值为空,多么郁闷的一个问题经过尝试,发现可以通过如下的方式解决这个问题.感兴趣的朋友可以了解下 当TextB ...
- "_Default"同时存在于两个dll文件中的解决办法
编译器错误消息:CS0433: 类型“_Default”同时存在于“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Fi ...
- iBatis 的删除一条记录
Student.xml 设置删除参数的类型,可以是一个对象的 <delete id="delStudent" parameterClass="int" & ...
- 让我们写的程序生成单个的exe文件(C#winform程序举例)
一准备: 首先你要有自己写好的代码程序 然后你需要在百度搜索Enigma Virtual Box 6.90并下载,运行后可看到如何的界面 注意:首次启动是英文的,更改语言后再次启动就是中文了. 二制作 ...
- iOS如何准确获取通知
iOS获取通知需要注意以下三个地方iOS 设备收到一条推送(APNs),用户点击推送通知打开应用时,应用程序根据状态不同进行处理需在 AppDelegate 中的以下两个方法中添加代码以获取apn内容 ...
- [转]Delphi中ShellExecute的妙用
Delphi中ShellExecute的妙用 ShellExecute的功能是运行一个外部程序(或者是打开一个已注册的文件.打开一个目录.打印一个文件等等),并对外部程序有一定的控制. ...
- 英语学习[ZZ]
本文作者三年间从四级勉强及格到高级口译笔试210,口试232.找工作面试时给其口试的老外考官听了一分钟就说你的英语不用考了.虽不敢说方法一定是最好的,但从现在开始随便谁不要再去找学习资料,每天花两个钟 ...
- SGU 152.Making round
不断向下取直到,忽略的数累计到一个百分比,给当前百分比加1. 这道题要避免处理浮点数,用余数来处理,不然会wa 9 #include <iostream> #include <cma ...
- CSS3中动画transform必须要了解的Skew变化原理
transform是CSS3中比较安全的动画(对于性能来说),其中有一些动画属性,来执行不同的变化.今天我们来了解skew的变化原理. skew,其实使用的频率不是很高,当然也没有最低.但是往往,一直 ...
- 多选select实现左右添加删除
案例:实现效果 1.选择监控城市,车辆列表显示对应城市所有车辆 2.从左边选择车辆 单击 >> 实现右侧显示添加车辆 ,左侧对应移除已选择车辆 3.右侧选中车辆 单击 &l ...