HOWTO see a Game's Frames Per Second and other data in an overlay on GNU/Linux

From LinuxReviews
Jump to navigationJump to search

An overlay in the corner showing your games frames per second and other data such as frame-times, CPU load, GPU temperature may be desireable either your streaming with OBS or just curious about your performance metrics.

There are stand-alone programs that do this such as Fraps on the Windows platform. GNU/Linux doesn't really have anything like that and it does not need it either because a heads-up display is built right into the graphics stack. If you have play OpenGL games on your GNU/Linux machine then you got what you need to have a Heads Up Display showing fancy graphs.

What is a GALLIUM_HUD?[edit | edit source]

Gallium3D is a shared architecture used by MESAs graphics drivers. "HUD" stands for Heads Up Display.

It works with any OpenGL game or application. Actually, it's already working with Vulkan too in the MESA git version.

The trick to invoking the Heads Up Display is to start your application with an environment-variable called GALLIUM_HUD="" with some configuration values followed by your applications executable.

The values you want are a set of .w[widthinpixels] .h[heightinpixels] and probably .c[MaxHighNumberinthegraph] followed directly by a identifier you would like to measure. Add :[Y-axis-max] after the measurement-keyword to set the initial Y-axis to something slightly higher than what value will top out at. For fps 70 makes sense if you are capped at 60fps. This value is only initial, if it's set at 70 and the value goes to 80 it adjust. Thus, you should set .c[value] to the same as :[value] if you want a fixed Y-axis.

For a graph of frames per second at a resolution of 4K you could start your game with:

GALLIUM_HUD=".w550.h280.c70fps:70" supertuxkart

Notice there is no space or nothing between .c70 and fpswhich it measures.

Use lower .width and .height values for lower resolutions. Something like .w250.h140 is fine for 1080p.

If you want more than one graph you can add them separated by a , comma. Thus, if you'd like to see fps and GPU temperature while playing SuperTuxKart you could start it with:

GALLIUM_HUD=".w550.h280.c70fps:70,.w550.h280.c80temperature:80" supertuxkart

You likely also want a graph showing GPU-load

You can have many things in the same graph area, a graph box is not restricted to just one thing. It makes sense to have similar things in the same box while totally different readings look silly. CPU cores is one example where it makes sense. Add + between the items you'd like:

GALLIUM_HUD=".w550.h280cpu0+cpu1+cpu2+cpu3+cpu4+cpu5+cpu6+cpu7+cpu8+cpu9+cpu10+cpu11:100"

Having a dual-core is obviously an advantage if you'd like to monitor all the CPU cores and threads. There is no need for a .c cap on the CPU since a single core will never have more than a 100% load.

You can use the .d option instead of .c to have the graphs ceiling dynamically adjust to the higest value present in the graph. You can also use .d in combination with .c.

What options are available?[edit | edit source]

Start any simple OpenGL program such as glxgears or glmark2 with the GALLIUM_HUD variable set to help and it will show you all the things you can monitor. And there are a lot as in plenty of things you can monitor.

GALLIUM_HUD="help" glxgears

The list of items you can monitor is really long and varies from GPU-driver to GPU-driver. Most are not that useful or interesting unless you are a developer. fps, frametime, cpu, VRAM-usage, temperature, GPU-load, shader-clock and memory-clock are the more interesting values you may like to monitor.

The example heads-up display shown in the video-clip above[edit | edit source]

Combining above the examples above we can show a graph of frames per second, a graph of GPU load, a graph GPU temperature and one showing the load of each CPU thread with:

MONITORGPU=".w550.h280.c70fps:70,.w550.h280GPU-load:100,.w550.h280.c80temperature:80"
MONITORCPU=".w550.h280cpu0+cpu1+cpu2+cpu3+cpu4+cpu5+cpu6+cpu7+cpu8+cpu9+cpu10+cpu11:100"
GALLIUM_HUD=${MONITORGPU},${MONITORCPU} supertuxkart

Saving your HUD settings and starting games with them[edit | edit source]

It is of course possible to always have a HUD on everything OpenGL by exporting a GALLIUM_HUD variable in $HOME/.bashrc. This is not exactly ideal. A better solution would be to put your preferred HUD settings in a script file like $HOME/bin/runwithhud.sh which can be used to run your games.

For a nice HUD at 4k you can put something like

#!/bin/bash
MONITORGPU=".w550.h280fps:70,.w550.h280GPU-load:100,.w550.h280temperature:80"
MONITORCPU=".w550.h280cpu0+cpu1+cpu2+cpu3+cpu4+cpu5+cpu6+cpu7+cpu8+cpu9+cpu10+cpu11:100"
GALLIUM_HUD=${MONITORGPU},${MONITORCPU} "${@}"

in $HOME/bin/runwithhud.sh and make it executable with chmod a+x $HOME/bin/runwithhud.sh and start your games with runwithhud.sh yourgamename

If you are using 1080p then you want smaller values for w and h such as:

#!/bin/bash
MONITORGPU=".w250.h140fps:70,.w250.h140GPU-load:100,.w250.h140temperature:80"
MONITORCPU=".w250.h140cpu0+cpu1+cpu2+cpu3+cpu4+cpu5+cpu6+cpu7+cpu8+cpu9+cpu10+cpu11:100"
GALLIUM_HUD=${MONITORGPU},${MONITORCPU} "${@}"

Steam and other alternative ways to get a FPS counter[edit | edit source]

Steam has it's own built-in in-game FPS counter overlay. Navigate through the menu Steam then Settings and select In-Game and you will be able to enable a FPS counter in one of your monitors corners.

You can use Gallium HUD with Steam too, but there's a catch: It will draw your graphs above every window. You get it on the Steam store, every pop-up and so on. That is not exactly ideal. You can get your game running and start streaming or recording, it can be used - it is just not ideal.

As always, we hope you learned something. Have a nice day.