



1 Start Analysis

2 CPU Profiler
2.1 CPU Profiler Overview

-
Green: Indicates that the thread is active or ready to use the CPU. That is, it is in the “running” or “runnable” state. -
Yellow: Indicates that the thread is active but is waiting for an I/O operation (such as disk or network I/O) to complete its work. -
Gray: Indicates that the thread is sleeping and is not consuming any CPU time. This can occasionally happen when a thread needs to access a resource that is not yet available. The thread may enter a self-sleep state or the kernel may put this thread to sleep until the required resource is available.
-
Sampled: Records at fixed intervals. Frequently captures the call stack of the app during execution. The profiler compares the captured datasets to deduce time and resource usage information related to the execution of the app’s code. The problem with “Sampled” tracing is that if the app enters a function after capturing the call stack and exits that function before the next capture, the profiler will not record that function call. If you are interested in tracking such short-lived functions, you should use “Instrumented” tracing. -
Instrumented: Records based on the time of function calls. It sets the app to record timestamps at the start and end of each function call during runtime. It collects timestamps and compares them to generate function trace data, including timing information and CPU usage. Note that the overhead associated with setting this up for each function will impact runtime performance and may affect the analysis data, especially for functions that are relatively short-lived. Additionally, if the app executes a large number of functions in a short time, the profiler may quickly exceed its file size limit and will not be able to record more trace data. -
Edit configurations: Allows you to change certain default values for the above “Sampled” and “Instrumented” recording configurations and save them as custom configurations.
2.2 Recording and Inspecting Function Traces

-
Wall clock time: Actual elapsed time. -
Thread time: Actual elapsed time minus the time the thread did not consume CPU resources.
2.2.1 Inspecting Traces Using Call Chart Tab
The Call Chart tab provides a graphical representation of function traces, where the horizontal axis represents the time of function calls (or callers), and the vertical axis displays their callees. Function calls to system APIs are shown in orange, calls to application-specific functions are shown in green, and calls to third-party APIs (including Java language APIs) are shown in blue. The image below shows an example of a call chart and depicts the concepts of Self time, Children time, and total time for a given function.

2.2.2 Inspecting Traces Using Flame Chart Tab



2.2.3 Inspecting Traces Using Top Down and Bottom Up

-
Self: Indicates the time spent by the function call executing its own code (rather than the code of callees). -
Children: Indicates the time spent by the function call executing its callees (rather than its own code). -
Total: The sum of the Self and Children time for the function. Indicates the total time the application spent executing the function call.

2.3 Creating Recording Configurations

3 Memory Profiler
3.1 Memory Profiler Overview

-
Displays a stacked graph of how much memory is used by each memory category, as shown on the left y-axis and the colored key at the top. -
The dashed line indicates the number of allocated objects, as shown on the right y-axis. -
Icons representing each garbage collection event.

-
Java: Memory allocated for objects from Java or Kotlin code. -
Native: Memory allocated for objects from C or C++ code. -
Graphics: Memory used by graphics buffers to display pixels on the screen (including GL surfaces, GL textures, etc.). (Note that this is memory shared with the CPU, not dedicated GPU memory.) -
Stack: Memory used by native and Java stacks in the application, usually related to how many threads the application is running. -
Code: Memory used by the application to process code and resources (such as dex bytecode, optimized or compiled dex code, .so libraries, and fonts). -
Other: Memory used by the application that the system cannot categorize. -
Allocated: The number of Java/Kotlin objects allocated by the application. Objects allocated in C or C++ are not counted.
3.2 Viewing Memory Allocations
-
What types of objects are allocated and how much space they use. -
The stack trace for each allocation, including which thread it was allocated in. -
When objects are deallocated (Android 8.0+).


-
Arrange by class: Groups all allocations by class name. -
Arrange by package: Groups all allocations by package name. -
Arrange by callstack: Groups all allocations by their corresponding call stacks.
3.3 Capturing Heap Dumps
-
What types of objects have been allocated by the application and how many have been allocated for each type. -
How much memory each object is using. -
Where in the code each object is still referenced. -
The call stack where the object was allocated. (Currently, if a heap dump is captured while recording allocations, the call stack can only be used in Android 7.1 and lower.)


-
Heap Count: The number of instances in the heap. -
Shallow Size: The total size of all instances in this heap (in bytes). -
Retained Size: The total size of memory retained for all instances of this class (in bytes).
-
Default heap: When the system does not specify a heap. -
App heap: The main heap where the application allocates memory. -
Image heap: The system startup image that contains classes preloaded during startup. Allocations here are guaranteed to never move or disappear. -
Zygote heap: A copy-on-write heap from which application processes are derived from the Android system.
-
Depth: The shortest number of hops from any GC root to the selected instance. -
Shallow Size: The size of this instance. -
Retained Size: The size of memory dominated by this instance.
3.4 Saving Heap Dumps as HPROF
3.5 Analyzing Memory Leak Example




4 Network Profiler
4.1 Network Profiler Overview

References
-
https://developer.android.com/studio/profile/android-profiler
-
https://blog.csdn.net/niubitianping/article/details/72617864
-
https://blog.csdn.net/Double2hao/article/details/78784758
Recommended↓↓↓

Long
Press
Close
Note
👉【16 Technical Public Accounts】 are all here!
Covers: Programmer big shots, source code reading, programmer reading, data structures and algorithms, hacker techniques and network security, big data technology, front-end programming, Java, Python, web programming development, Android, iOS development, Linux, database development, humorous programmers, etc.