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.
๐Ÿ“Š Why do you want to enable OpenGL tracing?
Debugging your games/applications
Fixing bugs in other people's software
Optimizing performance
Curiosity/learning
Other

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:

  1. 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.
  2. Performance optimization: Tracing identifies redundant calls (such as loading the same textures over and over) or rendering bottlenecks.
  3. 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 (in Settings โ†’ For developers).
  • ๐Ÿ’ป Computer with installed ADB drivers and utility adb (included with Android SDK).

Steps:

  1. Connect the device to the PC and run the command:
    adb shell setprop debug.gl.trace 1

    This will enable tracing for all applications.

  2. To trace a specific application (for example, a game) use:
    adb shell setprop debug.gl.trace.app <package_name>

    You can find out package_name with the command adb shell pm list packages | grep "application_name".

  3. 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:

  1. Using a file manager with root access (for example, Root Explorer), open the file /system/build.prop.
  2. Add the following lines to the end of the file:
    debug.gl.trace=1
    

    debug.gl.trace.app=<package_name>

  3. 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.prop can 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:

  1. Connect the device to Android Studio and select it in the list of devices.
  2. Open Android Profiler (tab at the bottom of the window) and go to the tab OpenGL Tracer.
  3. Click Start Tracing and select the target application.
  4. 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 .gltrace for 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 words eglInitialize or vkCreateInstance).

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 glGenTextures without glDeleteTextures).
  • ๐Ÿ”„ Excessive state changes (for example, repeated call glEnable(GL_BLEND)).
  • ๐Ÿ“ Buffer sizes (discrepancy between data-i="249">and real data). glBufferData and 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 Developers option is enabled USB 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, glBufferData s 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 glCompileShader on 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 (dmesg or /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).