Use of Android performance analysis tools

Use of Android performance analysis tools

1. Android Studio-Memory Monitor

How to use

Run your project, find the Memory Monitor window, select Memory

[Transfer] Memory change waveform

In addition, you can also choose to view the usage of CPU, GPU and NetWork.

Network usage waveform.png

Frequent use of Network is the key factor causing power consumption of applications. About 70% of the power is used for reporting data, checking location information, and regularly retrieving background advertising information. How to balance the power consumption of these two is very important.

2. Android Studio 1.5 Preview New Toy - Heap Snapshot

How to use

Run the project again, perform some operations and click the 'Dump Java Heap' button in the lower left corner

A .hprof file will be generated after each click

Click on a .hprof file and look at the analyzer test on the right. You can see two options

One is 'Detect Leaeked Activites' and the other is 'Find Duplicate Strings'. Click the green play button in the upper right corner to automatically analyze the heap dump to locate the leaked activity and duplicate strings. The following Analysis Results will appear.

There are three types of information in this panel: app heap/image heap/zygote heap.

They represent the app heap memory information, image heap memory information, and zygote process heap memory information respectively.

Chinese and English comparison table of each attribute

name Total Count Heap Count Size of Shallow size Retained Size
significance The number of objects of this class in memory The number of objects of this class in the heap memory Physical size The memory size of the object itself The amount of memory saved after releasing the object
name depth Shallow Size Dominating Size
significance depth The memory size of the object itself Managed memory size

Eclipse-Allocation Tracker

How to use

Click Start Tracking, perform an action in your app, and then click Get Allocations.  

Allocation Tracker

Features

a. Intermittent operation is required

b. Can locate a specific line of code

4. HierarchyViewer

Use hierarchyviewer to view the hierarchy of the page you need to check, and check the deepest number of pages. The official recommendation is to keep it within 10 layers.

hierarchyviewer

Layout level optimization solution:

1). Custom controls use the merge tag to reduce unnecessary root nodes;

2). Use drawableleft instead of adding an extra imageview;

3). Sometimes using relativelayout requires fewer layers than linearlayout to achieve the desired effect;

4). Use viewstub to hide controls. The layout in ViewStub will be rendered to the main interface only when you need it;

...

5. Leakcanary (Android and Java memory leak detection framework)

Android Studio

https://github.com/square/leakcanary

Eclipse

https://github.com/SOFTPOWER1991/LeakcanarySample-Eclipse

6. Phone Settings->Developer Options

1. Show GPU Overdraw

Show GPU Overdraw

Blue, light green, light red, and dark red represent four different degrees of overdraw. Our goal is to minimize red overdraw and see more blue areas.

Optimization plan:

Overdraw sometimes occurs because your UI layout has a lot of overlapping parts, and sometimes it is caused by unnecessary overlapping backgrounds. For example, an Activity has a background, and the Layout inside it has its own background, and the sub-Views also have their own backgrounds. Simply by removing unnecessary background images, you can reduce a lot of red Overdraw areas and increase the proportion of blue areas. This measure can significantly improve program performance.

Profile GPU Rendering - Check the option On screen as bars

Each bar line consists of three parts. The blue part represents the time to measure the drawing of the Display List, the red part represents the time required for OpenGL to render the Display List, and the yellow part represents the time the CPU waits for GPU processing.

There is a green horizontal line in the middle, representing 16ms. We need to ensure that the total time spent on each frame is lower than this horizontal line to avoid lag problems.

<<:  Understand the four deep learning methods of supervised learning, unsupervised learning, semi-supervised learning, and reinforcement learning in one article

>>:  【Practical】Mobile QQ and Qzone Speed ​​Optimization Practice

Recommend

How to promote with limited account budget?

How should a search promotion account with a smal...

They hammered away, hammer after hammer, and made a surprising discovery

The ecological restoration diagram of the spiral ...

WeChat opens WiFi access

We learned from WeChat that its "WeChat WiFi...

How are CarPlay and Android Auto different?

Currently, both Apple and Google have launched th...

QQShare: How did an unknown app in China become a national app in India?

[[167125]] In China, not many people know Yan Fei...

The underlying logic of advertising

Today, let’s analyze the underlying logic of adve...

Professor Bao Aimin: 20 Lectures on New Knowledge in Brain Science

Professor Bao Aimin: 20 Lectures on New Knowledge...