mallya's blog

Exploring Mesa Utils to acquire GPU statistics Part 1

14 Mar 2025 · Varun R Mallya · GPUs, Mesa, sysprof

Introduction

I am trying to find ways to add a GPU profiling feature to Sysprof, a GNOME developer utility. Turns out, the people over at Mesa just merged a new feature from which I can export out shader statistics and GPU statistics as well. I am going to be describing the method in which I found these measurable statistics and I’ll explain what they do as well. This blog is the first one in a series of blogs that I’ll be writing about this topic.

Steps to aquire the header file

The first step is to clone the Mesa repository. You can do this by running the following command:

git clone https://gitlab.freedesktop.org/mesa/mesa.git

Once you have cloned the repository, you can navigate to the src/util directory. Here, you can find the ‘src/util/process_shader_stats.py’ file. Create a virtual environment and install the required dependencies by running the following commands:

python3 -m venv venv
source venv/bin/activate
pip install mako textwrap xml

Now, you can run the script by running the following command:

python3 process_shader_stats.py

This will generate the ‘src/util/shader_stats.h’ file which contains all the statistics that you can measure.

The statistics themselves and their relavance to sysprof and profiling

I’ll be posting individually about each architecture and each statistic in that architecture in the coming week. For now, I’ve just checked out the adreno architecture. This is used on Qualcomm GPUs and was the most most detailed one I could find.

Adreno Shader Statistics

General stats

Max Waves Per Core
Instruction Count
Code Size
NOPs Count
MOV Count
COV Count
Registers Used
Half-Registers Used
Last Interpolation Instruction
Last Helper Instruction

Synchronization and Stalling

Instructions with SS Sync Bit
Instructions with SY Sync Bit
Estimated Cycles Stalled on SS
Estimated Cycles Stalled on SY

Instruction Categories

cat0 to cat7 Instructions
Private Memory Access
STP Count
LDP Count
Preamble Statistics
Preamble Instruction Count
Early Preamble

What I understood from this

These are pretty detailed honestly and I have no idea which ones can be used to profile programs. I tried to Google and understand each of these but I’m probably still missing a lot of stuff. Expect a lot more analysis in the coming weeks. Also, what I originally wanted was GPU stats and not shader stats really, but I think profiling programs at the shader level is the actual way to go. This might be a better indicator of bottlenecks in the program