Have you ever encountered a situation where a game or app on Android suddenly starts to slow down, display artifacts, or even crashes with an error GL_OUT_OF_MEMORY? In 90% of such cases, problems with graphic rendering are to blame - or more precisely, with the operation of the standard API for 2D/3D graphics on mobile devices. This is where OpenGL ES, a standard API for 2D/3D graphics on mobile devices. This is where it comes to the rescue OpenGL tracing comes to the rescue - a tool that allows you to โpeepโ at what commands the application sends to the GPU and identify bottlenecks.
But what is tracing in practice? Imagine that your application is a cook, and OpenGL is a stove. The tracing seems to turn on a camera above the stove and record every step: how much oil is poured, at what temperature the dish is fried, whether the food is burning. Only instead of oil and temperature, function calls like glDrawArrays, texture transfer or shader changes are recorded. These logs help you find why the โdishโ (your graphics) turns out to be spoiled.
In this article we will look at:
- ๐ What is OpenGL tracing and what problems it solves (from bugs in games to performance optimization).
- โ๏ธ How to enable tracing on any Android device - from root methods to ADB tools.
- ๐ How to read and analyze logsto find the root of the problem.
- โ ๏ธ Risks and limitations: why tracing itself can cause lags and how to avoid it.
What is OpenGL tracing and why do you need it
Tracing (or tracing) OpenGL ES is the process of recording all the commands that the application sends to the graphics driver. These commands include:
- ๐จ Calling rendering functions (
glDrawElements,glClear). - ๐ผ๏ธ Loading textures and shaders (
glTexImage2D,glShaderSource). - ๐ Changes of states (changing buffers, setting blending).
- ๐จ Driver errors (for example,
GL_INVALID_OPERATION).
Main scenarios where tracing is indispensable:
- Debugging graphics artifacts: if โtornโ textures, flickering objects or incorrect colors appear in the game, the logs will show which command did not work correctly.
- Performance optimization: Tracing identifies redundant calls (such as loading the same textures over and over) or rendering bottlenecks.
- Compatibility analysis: helps you understand why an application works on one device (for example Samsung Galaxy S23), but crashes on another (Xiaomi Redmi Note 10).
It is important to understand that tracing is not a profiler (like Android GPU Inspector). It does not show FPS or GPU load, but only records sequence of commands and their parameters. This is like the difference between video recording of an operation (tracing) and measuring its duration (profiling).
โ ๏ธ Attention: On some devices (especially those with processors Mediatek or outdated drivers), tracing may lead to additional lags or even application crash. This is due to implementation features OpenGL ES manufacturer.
Ways to enable OpenGL tracing on Android
There are several methods for activating tracing, and their choice depends on your goals and level of access to the device:
| Method | Requires root | Difficulty level | Suitable for |
|---|---|---|---|
adb shell setprop |
โ No | โญโญ | Quick diagnostics without superuser rights |
Change build.prop |
โ Yes | โญโญโญ | Permanent tracing on rooted devices |
| Developer tools (Android Studio) | โ No | โญโญโญโญ | Deep analysis with the ability to filter logs |
| Tracer applications (for example, gfxinfo) | โ No | โญ | Quick viewing of basic logs without ADB |
Let's consider each method in more detail.
Method 1: Enabling via ADB (without root)
The most universal method that works on any device with USB debugging enabled. You will need:
- ๐ฑ Android device with the unlocked option
USB debugging(inSettings โ For developers). - ๐ป Computer with installed ADB drivers and utility
adb(included with Android SDK).
Steps:
- Connect the device to the PC and run the command:
adb shell setprop debug.gl.trace 1This will enable tracing for all applications.
- To trace a specific application (for example, a game) use:
adb shell setprop debug.gl.trace.app <package_name>You can find out
package_namewith the commandadb shell pm list packages | grep "application_name". - Restart the application - logs will begin to be written to
logcat.
USB debugging is enabled on the device|ADB drivers are installed on the PC|Adb utility is available in PATH|The package name of the target application is known-->
To disable tracing:
adb shell setprop debug.gl.trace 0
โ ๏ธ Attention: On some devices (for example, with chipsets Qualcomm Snapdragon 8 Gen 1/2), tracing via setprop may not work due to manufacturer restrictions. In this case, try methods with root access or tools like RenderDoc.
Method 2: Editing build.prop (root required)
If you have root access, you can enable tracing permanently by editing the system file /system/build.prop. This method is useful for long-term debugging, but requires caution.
Instructions:
- Using a file manager with root access (for example, Root Explorer), open the file
/system/build.prop. - Add the following lines to the end of the file:
debug.gl.trace=1debug.gl.trace.app=<package_name> - Save the file and reboot the device.
The advantage of this method is that the tracing will work immediately after the system boots, without the need to enter ADB commands. However, there are also risks:
- ๐ง Incorrect editing
build.propcan lead to bootloop (loop reboot). - ๐ Constant tracing increases the load on the CPU/GPU, which can reduce performance.
adb pull /system/build.prop /sdcard/build.prop.bak-->
Method 3: Android Studio Tools
For developers, the most convenient way is to use the built-in tools Android Studio. They allow you not only to enable tracing, but also to filter logs, save them to a file and visualize calls.
How it works:
- Connect the device to Android Studio and select it in the list of devices.
- Open
Android Profiler(tab at the bottom of the window) and go to the tabOpenGL Tracer. - Click
Start Tracingand select the target application. - After the tracing is completed, the logs will be displayed in the form of a tree of calls with time stamps.
Advantages of this method:
- ๐ Visualization of calls in the form of a graph (you can see the โpeaksโ of the load).
- ๐ Filtering by type of commands (textures, shaders, buffers).
- ๐พ Export logs to format
.gltracefor further analysis.
How to read and analyze OpenGL logs
Trace logs are a stream of commands that can look intimidating to beginners. However, once you understand the structure, you can quickly find problems. A typical log consists of:
- ๐ Time stamp (when the command was executed).
- ๐ Thread ID (important for multi-threaded applications).
- ๐ Function names (for example,
glBindTexture). - ๐ข Parameters (argument values).
- โ ๏ธ Error codes (if the command failed).
Example log (simplified):
[12:34:56.789] Thread-1234: glBindTexture(GL_TEXTURE_2D, 5)[12:34:56.790] Thread-1234: glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0x7f8a1234)
[12:34:56.795] Thread-1234: glDrawArrays(GL_TRIANGLES, 0, 36) โ GL_OUT_OF_MEMORY
In this example, you can see that the application tried to load a texture of size 1024ร1024, and then when calling glDrawArrays it received an error GL_OUT_OF_MEMORY (there was not enough video memory). This is a typical case when you need to either reduce the resolution of textures or optimize them. download.
Checklist for log analysis
To systematize the search for problems, follow this algorithm:
Check for errors (GL_INVALID_*, GL_OUT_OF_MEMORY)|Look for duplicate calls (for example, glBindTexture with the same ID)|Pay attention to large textures (resolution > 2048x2048)|Check the sequence of calls (for example, glUseProgram before glDraw*)|Compare logs with reference behavior (if any)-->
Some common errors and their causes:
| Error | Possible cause | Solution |
|---|---|---|
GL_INVALID_OPERATION |
Incorrect call sequence (for example glDraw* without a shader attached). |
Check the command order in the code. |
GL_OUT_OF_MEMORY |
Textures or buffers are too large for available video memory. | Reduce texture resolution or use compression (ETC2, ASTC). |
GL_INVALID_ENUM |
Incorrect parameter value (for example, non-existent texture format). | Check the documentation for supported formats for your version of OpenGL ES. |
For in-depth analysis, you can use specialized tools:
- ๐ ๏ธ RenderDoc: allows you to capture frames and analyze the state of the GPU at any time moment.
- ๐ Android GPU Inspector (AGI): a tool from Google for profiling graphics (requires Android 10+).
- ๐ gfxinfo: a simple application for viewing logs directly on the device.
An example of analyzing a real bug
In one of the games, users complained about the โpink screenโ on devices c Mali-G78. Trace logs showed that glClearwas not called before rendering, which is why the frame buffer contained โgarbageโ data. Correction: adding glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) before glDraw*.
OpenGL tracing limitations and risks. data-i="192">Despite its usefulness, tracing has a number of limitations that are important to be aware of:
Despite its usefulness, tracing has a number of limitations that are important to be aware of:
1. Performance impact
Recording each OpenGL call requires additional resources (for example, with a Snapdragon 4xx processor or Mediatek Helio G-series) this can lead to:
- ๐ข Slower FPS in games (30โ50% drop).
- ๐ Increased battery consumption (up to 10โ15% per hour).
- ๐ฅ Overheating of the device (especially during long-term tracing).
2. Incomplete logs on some devices
Chipset manufacturers (for example, Qualcomm or ARM) may modify drivers OpenGL ES, which is why some commands will not appear in the logs. This applies to:
- ๐ฅ๏ธ Internal driver optimizations (for example, call merging
glDraw*). - ๐ Proprietary extensions (for example,
GL_QCOM_tiled_rendering).
3. Security and privacy
Trace logs may contain sensitive information:
- ๐ Shader data (including post-processing algorithms).
- ๐ผ๏ธ Texture fragments (if they are loaded as raw data).
- ๐ต๏ธ Information about the structure of the 3D scene (position of objects, UV coordinates).
โ ๏ธ Attention: Do not share raw trace logs in public repositories or forums if they relate to proprietary software (games, commercial applications).
4. Vulkan
If your application uses Vulkan instead of OpenGL ES, OpenGL tracing will not help. Vulkan requires other tools (for example, RenderDoc or Vulkan Layer). via:
- ๐ File
AndroidManifest.xml(tag<uses-feature android:glEsVersion="0x00030001" />indicates OpenGL ES 3.1). - ๐ ๏ธ Logs
logcat(search by key wordseglInitializeorvkCreateInstance).
Alternatives to OpenGL tracing
If tracing does not give the desired results or is not available on your device, consider alternative diagnostic methods:
1. GPU profilers
- ๐ Android GPU Inspector (AGI): shows GPU load, number of calls
draw, memory usage. - ๐ฅ๏ธ ARM Streamline: a tool for analyzing performance at the driver level (requires root).
2. Driver logs
Some manufacturers provide their own diagnostic tools:
- ๐ฑ Qualcomm:
adb shell dumpsys gpu(shows rendering statistics). - ๐ฑ ARM Mali:
adb shell cat /sys/kernel/debug/mali/...(paths depend on the driver version).
3. Emulators and simulators
If the problem occurs only on a specific device, you can try:
- ๐ฅ๏ธ Android Emulator with enabled
GPU Debugging(in the AVD settings). - ๐ฎ RenderDoc or NSight to capture frames on a PC (if the application is cross-platform).
4. Code analysis
If you have application sources, check:
- ๐ Texture leaks (call
glGenTextureswithoutglDeleteTextures). - ๐ Excessive state changes (for example, repeated call
glEnable(GL_BLEND)). - ๐ Buffer sizes (discrepancy between data-i="249">and real data).
glBufferDataand real data).
OpenGL tracing is not a panacea. If the problem is related to the application logic (for example, incorrect transformation matrices), logs will not help. In such cases, code debugging or visual analysis of the scene is needed.
Common mistakes and their solutions
Even after enabling tracing, users often encounter typical problems:
1. Logs are empty or incomplete
Possible causes and solutions:
- ๐ No USB debugging: check that the
Settings โ For Developersoption is enabledUSB Debugging. - ๐ซ Driver blocks tracing: Some devices (for example Huawei or Oppo) require additional permission. Try:
adb shell su -c "setprop debug.gl.trace 1" - ๐ฑ Device does not support tracing: On older versions of Android (< 5.0) or devices with proprietary drivers (for example PowerVR), tracing may be disabled at the kernel level.
2. The application crashes when tracing is enabled
This is typical for applications that:
- ๐ Intensively use multithreading (for example, asynchronous loading of textures).
- ๐ฆ Work with large buffers (for example,
glBufferDatas data > 50 MB). - ๐ Use OpenGL extensions not supported by the driver.
Solutions:
- ๐ ๏ธ Enable tracing only for a specific thread (if you know its ID).
- ๐ Reduce level of log detail (for example, filter only errors).
- ๐ Try tracing on another device with a similar chipset.
3. The logs are too large and unreadable
When tracing complex scenes (for example, in PUBG Mobile or Genshin Impact), the logs can take up gigabytes. To simplify the analysis:
- ๐ Use filters in
logcat:adb logcat | grep "glGetError\|GL_INVALID\|glDraw" - ๐ Export logs to Android Studio and analyze through
OpenGL Tracer. - ๐๏ธ Clear logs before starting tracing:
adb logcat -c
4. The trace does not show an error, but the problem remains. (for example, division by zero in
Possible reasons:
- ๐ฅ๏ธ Problem at the driver level (for example, a bug in the implementation
glCompileShaderon Adreno 6xx). - ๐ Error in the shader not related to the API (for example, division by zero in
GLSL). - ๐ก Problems with synchronization between the CPU and GPU (for example, race condition).
Solutions:
- ๐ ๏ธ Check the driver logs (
dmesgor/proc/kmsg). - ๐ Use RenderDoc to capture a frame and analyze the state of the GPU.
- ๐ Compare behavior on different devices (for example, Samsung Exynos vs Qualcomm Adreno).
FAQ: Answers to frequently asked questions
โ Is it possible to enable OpenGL tracing on a non-rooted device?
Yes, using the ADB command adb shell setprop debug.gl.trace 1. However, on some devices (for example, with chipsets Kirin or Exynos) this may not work without root access.
โ How to save trace logs to a file?
Use the command:
adb logcat -d > opengl_trace.log
To filter only graphical commands:
adb logcat -d | grep "libEGL\|libGLES" > opengl_trace.log
โ Why does tracing work in one game, but not in another?
It depends on how the application initializes OpenGL ES:
- Some games (for example, Call of Duty Mobile) use their own wrappers over OpenGL, which can block tracing.
- Applications on Unity or Unreal Engine may have their own abstraction layers that are not logged by standard means.
In such cases, try tools like RenderDoc, which work at the driver level.
โ Does tracing affect performance in games?
Yes, and sometimes very significantly. For example:
- On Snapdragon 888 the drop in FPS can reach 20โ30%.
- On weak chipsets (for example, Snapdragon 450), the game can become completely unplayable (< 10 FPS).
- On Mali-G77 tracing sometimes causes artifacts due to bugs in the driver.
It is recommended to test on mid-range devices (for example, Snapdragon 7xx or Dimensity 900), where the impact is less critical.
โ Can traces be used to analyze Vulkan?
No, tracing debug.gl.trace works only with OpenGL ES. For Vulkan you need other tools:
- RenderDoc (supports Vulkan frame capture).
- Vulkan Layer (for example,
VK_LAYER_LUNARG_standard_validation). - Android GPU Inspector (partial support for Vulkan on new versions of Android).