Android 性能优化(22)*性能工具之「Hierarchy Viewer」 Hierarchy Viewer Walkthrough
Hierarchy Viewer Walkthrough
1.In this document
You should also read
This walkthrough shows the basic usage and workflow for the Hierarchy Viewer tool.
The Hierarchy Viewer tool visualizes your app's view hierarchy and profiles the relative rendering speed for each view.
Hierarchy Viewer tool 是应用中view 继承层次,每个view绘制相对速度的分析工具,可以发现有性能瓶颈的view或layout。
What it's good for:
- Simplifying your view hierarchy to reduce overdraw, and make it easier to manage.
- Finding potential rendering performance bottlenecks related to the structure and shape of your view hierarchy.
2.Prerequisites 准备工作
- A mobile device set up to work with Hierarchy Viewer:
- You must have Developer Options enabled on your mobile device. You must use a physical device to get accurate measurements.
在手机、模拟器上设置开发选项。
- Set an
ANDROID_HVPROTOenvironment variable on the desktop machine that is connected to your device. For more information, see Device Setup for Hierarchy Viewer.如果在4.0以上系统上使用Hierarchy Viewer,要在桌面机器上设置
ANDROID_HVPROTO环境变量.方法: Device Setup for Hierarchy Viewer.
- Debuggable app code with a view hierarchy. Use your own code, or the code for the Sunshine sample app from the Android Fundamentals Udacity course.
3.设置环境变量
If you have a device running Android 4.1 or higher, you must set an environment variable on your development machine. For more information, see Setting the ANDROID_HVPROTO variable
3.1 Windows
- Click My Computer > Property > Advanced > Environment Variables.
- Click New.
- In variables name put:
ANDROID_HVPROTO - In variable value put:
ddm - Click OK<./li>
3.2 Mac
- Edit
~/.bash_profile - Add:
#Hierarchy Viewer Variable
export ANDROID_HVPROTO=ddm source ~/.bash_profile
3.3 Linux
- Edit
~/.bash_profile - Add:
#Hierarchy Viewer Variable
export ANDROID_HVPROTO=ddm source ~/.bash_profile
4.开始分析
- Connect your mobile device to your computer.
- Open your application in Android Studio, build the source, and run it on your device.
- From Android Studio, start the Android Device Monitor: Tools > Android > Android Device Monitor.
- Allow USB Debugging on your phone (if asked).

Figure 1. Starting Android Device Monitor.
- Figure 2 illustrates what is initially shown in the Device Monitor tool. This varies depending on your setup.
Make sure your device and the package for your application are showing in the Devices (DDMS mode) or Windows (Hierarchy Viewer mode) tab. You can choose Window > Reset Perspective to get back to the default arrangement.
If the app does not appear, make sure you followed the device setup instructions, then start over at step 1.
- Figure 2 illustrates what is initially shown in the Device Monitor tool. This varies depending on your setup.

Figure 2. Android Device Monitor.
- In Android Device Monitor (ADM), in the menu bar, choose Window > Open Perspective, and in the popup click Hierarchy View.
OR Click the Hierarchy View button if it's already visible.

- In Android Device Monitor (ADM), in the menu bar, choose Window > Open Perspective, and in the popup click Hierarchy View.

Figure 3. Changing Perspective to Hierarchy Viewer.
- If not already open, the Hierarchy View panes open.
The example screen in Figure 4 shows an example of these panes.
- If not already open, the Hierarchy View panes open.

Figure 4. Hierarchy Viewer layout.
- If you see a different window arrangement, in Android Device Manager, use Window > Reset Perspective to return to the default layout for this tutorial.

Figure 5. Resetting the Perspective.
- Double-click your application in the Windows tab. This populates the panes with the view hierarchy of your application. This display is a static representation of the complete view hierarchy defined for the app.
- You can adjust the sizes of the panes and ADM will preserve your arrangement in future sessions.

Figure 6. Populated Hierarchy Viewer.
- If necessary, click the Layout View tab to hide the Console and show a wireframe of your layout. The outline of the currently selected view is red. Click an outline to select it.
- The rest of the panes:
- The Tree Overview in the upper right gives you a bird's-eye view of your app's complete ViewHierarchy.
- In the Tree Overview, move the gray viewport rectangle to change what section of your hierarchy shows in the Tree View pane (in the center).
- In the Tree View, you can drag and zoom the tree using your mouse.

Figure 7. Hierarchy Viewer panes.
- Click on a View node to display details. Here is an annotated close-up of a node and its details.

Figure 8. Parts of the View node display.
- Click the View Properties tab at the top right (next to the Windows tab) to see properties of the selected View node.

Figure 9. Location of View Properties tab.
- Double-click a View node in the Tree View to render it in a popup window.

Figure 10. Rendering a view in a popup.
- Nodes in the Tree View show a Type, which indicates the View class, and an id, which is the view identifier in your code.

Figure 11. Node with its type and id.
使用它开始分析
Android 性能优化(22)*性能工具之「Hierarchy Viewer」 Hierarchy Viewer Walkthrough的更多相关文章
- Android开发学习之路--性能优化之常用工具
android性能优化相关的开发工具有很多很多种,这里对如下六个工具做个简单的使用介绍,主要有Android开发者选项,分析具体耗时的Trace view,布局复杂度工具Hierarchy Vie ...
- Android 性能优化 五 性能分析工具dumpsys的使用
Android提供的dumpsys工具能够用于查看感兴趣的系统服务信息与状态,手机连接电脑后能够直接命令行运行adb shell dumpsys 查看全部支持的Service可是这样输出的太多,能够通 ...
- MYSQL之性能优化 ----MySQL性能优化必备25条
今天,数据库的操作越来越成为整个应用的性能瓶颈了,这点对于Web应用尤其明显.关于数据库的性能,这并不只是DBA才需要担心的事,而这更是我 们程序员需要去关注的事情.当我们去设计数据库表结构,对操作数 ...
- 前端性能优化jQuery性能优化
一.使用合适的选择器 $("#id"); 1.使用id来定位DOM元素无疑是最佳提高性能的方式,因为jQuery底层将直接调用本地方法document.getElementById ...
- Java程序性能优化之性能概述
性能的基本概念 一).什么叫程序的性能? 程序运行所需的内存和时间. 二).性能的表现形式: 1).执行速度: 程序的反应是否迅速,响应时间是否足够短. 2).启动时间:程序从运行到可以处理正常业务所 ...
- Android 性能优化(24)*性能工具之「Traceview,dmtracedump」Profiling with Traceview and dmtracedump :记录并查看函数调用栈*
Profiling with Traceview and dmtracedump In this document Traceview Layout Traceview工具界面介绍 T ...
- Android性能优化之Systrace工具介绍(一) _&& Systrace生成的trace.html打开空白或者打不开的解决办法
1.必须用Chrome打开 2.在mac电脑上,可能Chrome打开也是空白,解决办法是:在chrome地址栏中输入”chrome:tracing”,然后点击load按钮load你的trace.htm ...
- Android 性能优化(4)Optimizing Layout Hierarchies:用Hierarchy Viewer和Layoutopt优化布局
Optimizing Layout Hierarchies This lesson teaches you to Inspect Your Layout Revise Your Layout Use ...
- Android性能优化-线程性能优化
原文链接:Better Performance through Threading 线程的性能 熟练使用Android上的线程可以帮助你提高应用程序的性能. 本篇文章讨论了使用线程的几个方面:使用UI ...
随机推荐
- [NOIP2006] 提高组 洛谷P1066 2^k进制数
题目描述 设r是个2^k 进制数,并满足以下条件: (1)r至少是个2位的2^k 进制数. (2)作为2^k 进制数,除最后一位外,r的每一位严格小于它右边相邻的那一位. (3)将r转换为2进制数q后 ...
- LOJ#541. 「LibreOJ NOIP Round #1」七曜圣贤
有一辆车一开始装了编号0-a的奶茶,现有m次操作,每次操作Pi在[-1,b),若Pi为一个未出现过编号的奶茶,就把他买了并装上车:若Pi为一个在车上的奶茶,则把他丢下车:否则,此次操作为捡起最早丢下去 ...
- openjudge7627 鸡蛋的硬度
描述 最近XX公司举办了一个奇怪的比赛:鸡蛋硬度之王争霸赛.参赛者是来自世 界各地的母鸡,比赛的内容是看谁下的蛋最硬,更奇怪的是XX公司并不使用什么精密仪器来测量蛋的硬度,他们采用了一种最老土的办法- ...
- Aizu - 0558 Cheese (bfs)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=49879 在H * W的地图上有N个奶酪工厂,分别生产硬度为1-N的奶酪.有一 ...
- 携程Apollo(阿波罗)配置中心使用Google代码风格文件(在Eclipse使用Google代码风格)(配合阿里巴巴代码规约快速设置)
Apollo默认使用了Google的代码风格,文件放在这里: https://github.com/ctripcorp/apollo/tree/master/apollo-buildtools/sty ...
- Redis集群方案之使用豌豆荚Codis搭建(待实践)
Codis的模式类似Twemproxy,不过这东西引入了ZooKeeper做为Redis的注册与发现来实现高可用. 部署时需要额外增加应用的部署,请根据业务需求来衡量. 部署图类似如下: 当然,上面的 ...
- pc3-12800
PC3-12800=DDR3 1600 PC3代表DDR3.12800是用带宽来命名,1600*64/8=12800,1600是DDR等效频率.
- linux shell学习一点点
问题,从shell command 交互式地由用户输入密码,但是输入的过程中不会显示用户输入的密码,起到类似于于html中input type=password的作用. #!/bin/bash rea ...
- 百度知道的代码复制粘贴到VB没有换行怎么办
在如下所示的网页中,复制 粘贴到word文档,换行还是有的 再复制到VB6.0中还是可用的
- Mysql数据库再度使用
查看数据库端口: show global variables like 'port'; 谨记:每一条sql结束的语句后都要接上分号. 在连接数据库时遇到过这种问题: Fatal error: Call ...