Mobile Development 9 min read

Android Application Performance Testing: Memory and CPU Measurement Methods

This article explains common Android performance problems such as battery drain, slow startup, and lag, and provides step‑by‑step instructions for measuring memory and CPU usage using adb commands, Android Studio tools, and the ActivityManager.MemoryInfo API.

Baidu Intelligent Testing
Baidu Intelligent Testing
Baidu Intelligent Testing
Android Application Performance Testing: Memory and CPU Measurement Methods

Android users often encounter issues like rapid battery drain when the app runs in the background, slow startup times, increasing lag during use, and low frame rates, all of which negatively affect user experience.

Therefore, Android applications must undergo performance testing covering startup time, memory, CPU, power consumption, network traffic, and smoothness. This article focuses on practical methods for testing memory and CPU usage.

Memory and CPU testing aims to detect how much memory and CPU an app consumes under different usage intensities. Excessive memory use can cause stutter, crashes, and affect daily active users and retention. Usage intensity is divided into three states:

Idle: app is launched but not interacted with or moved to background, minimal memory consumption.

Medium intensity: user interacts with the app for an uncertain but relatively long duration.

High intensity: frequent operations (e.g., monkey testing) to simulate heavy usage and reveal memory leaks.

Using adb commands

1. Test method: connect the phone to a computer, enable USB debugging, and enter adb shell .

2. Check CPU usage:

Run top -m 10 -s cpu (‑t shows process name, ‑s sorts by the specified column, ‑n sets the number of refreshes before exit, ‑d sets refresh interval, ‑m limits the number of displayed processes). The output includes fields such as:

PID : process ID

S : process state (S=sleep, R=running, Z=zombie, N=negative priority)

#THR : thread count

VSS : virtual set size (including shared libraries)

RSS : resident set size (actual physical memory used)

UID : user ID

Name : application name

During testing, QA should monitor the target package’s CPU usage; if it stays high after repeated actions, a risk may exist. To filter your own app, use top -d 3 | grep packageName .

3. Check memory usage:

Run dumpsys meminfo <package_name> or dumpsys meminfo <package_id> .

The output contains fields such as:

Native Heap Size, Native Heap Alloc, Native Heap Free (derived from mallinfo )

Dalvik Heap Size, Dalvik Heap Alloc, Dalvik Heap Free (derived from Runtime.totalMemory() and Runtime.freeMemory() )

Key points to watch:

Alloc values in Native/Dalvik heap indicate memory allocation; a continuously growing value suggests a possible memory leak.

Total PSS reflects the actual memory footprint of the app, helping identify apps that consume large amounts of RAM.

Android Studio built‑in CPU and memory profiling

1. Connect the phone, select the device (step 1) and the target app process (step 2) in Android Studio. The “Memory” tab shows memory monitoring, and the “CPU” tab shows CPU monitoring.

During profiling, focus on two aspects:

After leaving a page, does memory drop? If not, trigger a manual GC; if memory still does not drop, a leak may exist.

Does memory increase rapidly after a specific operation? Repeating the operation can confirm the issue.

Summary

Android Studio’s built‑in CPU and memory tools visualize usage curves, making it easy to see performance trends.

Using ActivityManager.MemoryInfo()

The Android API ActivityManager.MemoryInfo() can retrieve an app’s memory data. Tools like Emmagee use this method to collect memory, CPU, and traffic data; after testing, results can be saved on the device’s SD card for further analysis.

Next preview

Upcoming topics include memory leaks, stutter analysis, GPU rendering profiling (Profile GPU Rendering tool), FPS meter testing, drawing a point to measure draw frequency, and Android Studio’s GPU testing features.

AndroidPerformance TestingCPUmemoryandroid-studioADB
Baidu Intelligent Testing
Written by

Baidu Intelligent Testing

Welcome to follow.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.