Collect Android App FPS with ADB and a Multithreaded Java Helper

This guide shows how to use the adb shell dumpsys gfxinfo command to capture frame‑per‑second metrics for an Android app and provides a reusable Java class that runs in a separate thread, parses the output, and stores the results for performance analysis.

FunTester
FunTester
FunTester
Collect Android App FPS with ADB and a Multithreaded Java Helper

When testing Android app performance, developers often need precise FPS (frames‑per‑second) data for different usage scenarios. The standard way to obtain this data from a device is the adb shell dumpsys gfxinfo <package_name> command, which prints detailed rendering statistics.

The article shares a complete Java implementation named Fps that runs as a background thread, repeatedly executes the ADB command, extracts numeric FPS values using regular expressions, aggregates them, and saves the results to a local MySQL database.

Key Components of the Fps Class

Thread control : A boolean flag KEY determines the loop lifecycle; stopFps() sets the flag to false to end the thread.

Command execution : execCmdAdb(String cmd) builds the appropriate system command based on the host OS (Mac or Windows) and launches it via Runtime.getRuntime().exec().

Output handling : The method reads both the standard output and error streams, line by line, using BufferedReader. Lines that start with three spaces are filtered for FPS data.

Pattern matching : A Pattern with the regex " ([0-9]{1,2}+\.[0-9]{2})" extracts numeric FPS values from each relevant line.

Result aggregation : getMatcher(String text, Pattern pattern) collects all matches, converts them to double, sums them, adds a small random offset, and returns an integer total.

Persistence : The extracted FPS value is stored via AppLocalMySql.getInstance().saveFps(testName, mark).

Usage Example

Fps fps = new Fps();
fps.start();
// ... perform app actions ...
fps.stopFps();
fps.join();

The Fps thread continuously runs the ADB command every five seconds (as defined by Common.getInstance().sleep(5000)), allowing developers to monitor FPS in real time while interacting with the app.

All helper methods for logging ( output(String) and output(Object...)) are included to print status messages and error information to the console, facilitating debugging.

This self‑contained solution can be integrated into any Android testing suite to automate FPS collection without manual command‑line interaction.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaMobile DevelopmentAndroidPerformance TestingmultithreadingfpsADB
FunTester
Written by

FunTester

10k followers, 1k articles | completely useless

0 followers
Reader feedback

How this landed with the community

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.