Profiler, a performance optimization tool for Android development

foreword

Performance optimization problems are encountered in our development, but in the case of small factories and not strict requirements on ourselves, I seldom do performance optimization;

In terms of performance optimization, basically everyone finds problems through their own development experience and performance analysis tools. Today, I would like to share with you the Profiler tool I recently used.

What can the Profiler tool do?

Help developers understand the application's CPU, memory, network, battery resource usage, etc.

The relationship between Profiler and developers?

Profiler is a tool for evaluating code performance, and development is to implement functions by writing code;

By using Profiler, developers can identify and resolve performance issues in their code to improve application responsiveness and efficiency;

Profiler also helps developers understand the inner workings of applications so they can be optimized and improved;

The relationship between Profiler and development is interdependent;

Purpose of performance optimization?

Optimize the program to make the program more robust and efficient, provide a faster and smoother user experience, and extend the battery life of the device

How to open Profiler

Method 1: Click View / Tool Windows / Profiler in the upper left corner of the AS

Method 2: Click the Profiler icon in the upper right corner of the AS

Method 3: Click the Profiler button at the bottom of AS

 The three opening methods are shown in the figure below:

Three major analysis directions of the Profiler tool

  • CPU CPU analysis
  • MEMORY memory analysis
  • ENERGY energy consumption analysis

The three analysis directions are shown in the figure below:

Profiler CPU analysis

Here, the editor will borrow the official standard introduction to avoid misleading everyone

When you open the CPU Profiler, it immediately starts showing your app's CPU usage and thread activity, as shown in the image below:

  1. Event Timeline : Shows activities in your app as they transition through the various states throughout their lifecycle and indicates user interactions with the device, including screen rotation events. For information on how to enable the event timeline on devices running Android 7.1 (API level 25) and lower, see Enabling advanced profiling .
  2. CPU Timeline : Shows the app's real-time CPU usage as a percentage of total available CPU time and the total number of threads the app is currently using. This timeline also shows the CPU usage of other processes, such as system processes or other apps, so you can compare it to your app's CPU usage. You can check historical CPU usage data by moving the mouse along the horizontal axis of the time axis.
  3. Thread Activity Timeline : Lists each thread belonging to the app process and indicates their activity on the timeline using the colors listed below. After recording a trace, you can select a thread from this timeline to examine its data in the trace pane.
    • Green : Indicates that the thread is active or ready to use the CPU. That is, the thread is in the running or runnable state.
    • Yellow : Indicates that the thread is active, but it is waiting for an I/O operation (such as disk or network I/O) before it can complete its work.
    • Gray : Indicates that the thread is sleeping and not consuming any CPU time. This situation arises when a thread needs to access a resource that is not yet available. In this case, either the thread is actively put to sleep, or the kernel puts the thread to sleep until the required resources are available.

    The CPU profiler also reports the CPU usage of threads added to the app process by Android Studio and the Android platform, including  JDWP, Profile Saver, Studio:VMStats, Studio:Perfa and  Studio:Heartbeat etc. (however, the exact names they appear on the thread activity timeline may vary) . Android Studio reports this data so that you can determine when thread activity and CPU usage are actually caused by your app's code

Profiler memory analysis

Description of memory performance analysis graph

  1. Button to force a garbage collection event
  2. Button to capture a heap dump
  3. Drop-down menu to specify how often the profiler captures memory allocations
  4. Buttons for zooming the timeline
  5. Button for jumping to live memory data
  6. Event timeline showing activity states, user input events, and screen rotation events
  7. memory usage timeline, it shows the following           
  • A stacked chart showing how much memory each memory category is currently using, as indicated by the y-axis on the left and the colored keys at the top
  • A dashed line representing the number of objects allocated, shown on the right y-axis
  • Icons for each garbage collection event

Profiler energy consumption analysis

When you open the energy consumption performance profiler, it will immediately start to display the estimated power consumption of the application, as shown in the picture below, the picture below is the introduction of the picture I found from the official website

The default view of the Energy Profiler includes the following timelines:

  1. The "Event" timeline : Shows the activities in your application as they transition through various states during their lifecycle. This timeline also indicates user interactions with the device, including screen rotation events.
  2. Energy timeline : Shows the app's estimated power consumption.
  3. System timeline : Displays system events that may affect power consumption.

To see specific power consumption by CPU, network and location (GPS) resources, and related system events, place the mouse pointer over the   bars in the Energy timeline.

If you still need to learn more Profiler knowledge, you can go to Profiler official website documents for more detailed understanding

Guess you like

Origin blog.csdn.net/Ai1114/article/details/131413539