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_HVPROTO
environment 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.
使用它开始分析
http://www.cnblogs.com/sjjg/p/5391486.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?