Hierarchy Viewer默认打开“Tree View”窗口无法显示显示Performance indicators

但选中根视图再点击按钮“Obtain layout times for tree rooted at selected node”:

就可以显示:

其上该视图性能的颜色指示符从左到右依次为:Measure、Layout和Draw,其中红色代表此树中该视图渲染最慢即占用总渲染时间的80%或其以上,绿色代表此树中该视图渲染时长小于总渲染时间的50%,黄色代表此树种该视图渲染时长50%或其以上但低于80%。

ProfileNodesAction.java

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();
}
...

HierarchyViewerDirector.java

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();
}
});
}
}

DeviceBridge.java

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;
}

ViewNode.java

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();
}
}

DeviceConnection.java

/**
* 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();
}
...

ViewDebug.java


Hierarchy Viewer显示视图性能指标的更多相关文章

  1. Android 实用工具Hierarchy Viewer实战

    在Android的SDK工具包中,有很多十分有用的工具,可以帮助程序员开发和测试Android应用程序,大大提高其工作效率.其中的一款叫Hierachy Viewer的可视化调试工具,可以很方便地在开 ...

  2. Android优化——UI检视利器:Hierarchy Viewer

    在Android的SDK工具包中,有很多十分有用的工具,可以帮助程序员开发和测试Android应用程序,大大提高其工作效率.其中的一款叫 Hierachy Viewer的可视化调试工具,可以很方便地在 ...

  3. Hierarchy Viewer

    http://blog.csdn.net/ddna/article/details/5527072 Hierarchy Viewer是随AndroidSDK发布的工具,位置在tools文件夹下,名为h ...

  4. 看了一本书,说可以利用Hierarchy Viewer优化布局

    看了一本书,说可以利用Hierarchy Viewer优化布局,今以志之. 参考:http://www.cnblogs.com/Rocky_/archive/2011/11/04/2236243.ht ...

  5. 【转】【Android工具】被忽略的UI检视利器:Hierarchy Viewer

    原文:http://blog.csdn.net/ddna/article/details/5527072 Hierarchy Viewer是随AndroidSDK发布的工具,位置在tools文件夹下, ...

  6. 利用Hierarchy Viewer优化布局

    好久没更新博客了,趁着清明来写点什么. 今天来讲下如何使用android中提供的工具优化我们的布局.首先我们写一个最简单的框架布局. <?xml version="1.0" ...

  7. Android 卡顿优化 3 布局优化 工具 Hierarchy Viewer

    欲善其事, 先利其器. 分析布局, 就不得不用到Hierarchy Viewer了. 本文工具使用皆以GithubApp的详情界面RepoDetailActivity为例说明. 为了不影响阅读体验, ...

  8. Android工具 Hierarchy Viewer 分析

    Hierarchy Viewer是随AndroidSDK发布的工具,位置在tools文件夹下,名为hierarchyviewer.bat.它是Android自带的非常有用而且使用简单的工具,可以帮助我 ...

  9. Android官方命令深入分析之Hierarchy Viewer

    Hierarchy Viewer允许你调试和优化用户界面.它提供了一个层可视的方式来显示. 启动Hierarchy Viewer,如下: 在Android Studio中,选择Tools > A ...

随机推荐

  1. codevs1380 没有丧尸的舞会

    /* 树形DP 而然我并不知道树在哪(....) f[x][0]表示x节点不参加舞会 以x为根的子树的最优解 f[x][1]表示x节点参加舞会 以x为根的子树的最优解 方程为:(so为x的儿子 so要 ...

  2. 关于git status

    如果只在本地修改,还没有commit,那么用git status, 打印信息为: 如果我本地没有修改文件,就是:

  3. 委托、 Lambda表达式和事件——委托

    简单示例 /* * 由SharpDevelop创建. * 用户: David Huang * 日期: 2015/7/27 * 时间: 10:22 */ using System; namespace ...

  4. 自定义Window 服务

    自定义window 服务 开发到使用的流程: 1.完成对应的代码之后(代码在底下),右键MyService.cs 添加安装程序 2.添加window服务安装程序打开Service1.cs[设计]页面, ...

  5. [原创] SQLite数据库使用清单(下)

    上文两章对SQLite的功能.语法.和操作进行了介绍,本文讲解SQLite的一些高级语法和操作. 3.

  6. ImageView 设置OnTouchListener

    ImageView的OnTouchListener,onTouch方法要返回true,MotionEvent.ACTION_UP,MotionEvent.ACTION_MOVE 才有效. 其实关于返回 ...

  7. jstl--c:choose标签

    今天使用c:choose标签,一直报错: 严重: Servlet.service() for servlet CheckIncome threw exceptionorg.apache.jasper. ...

  8. hdoj 2601(判断N=i*j+i+j)

    Problem E Time Limit : 6000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Sub ...

  9. SGU 163.Wise King

    一道题目长的水题.... 总结就一句话,给出n个(-3~3)的数,一个数m,取任意个数是使这些数的m次幂之和最大. code #include <iostream> #include &l ...

  10. Codeforces 527E Data Center Drama(欧拉回路)

    题意: 给定一个无向图连通图,把这个的无向边变成有向边,并添加最少的有向边使这个图每个结点的出度为偶数. Solution: 题目很长,并且很多条件说的不太直接,确实不太好懂. 首先先看得到的无向图, ...