View Full Version : query grahpics memory stats
05-08-2009, 05:48 PM
I need a way to programatically (C/C++) determine the total amount of graphics memory and the amount of free graphics memory in Linux (and maybe other UNIX platforms as well). Does anybody know how to do that?
Thanks in advance.
05-08-2009, 08:37 PM
cat /var/log/Xorg.0.log|grep -i nvidia|grep memory:
This gives you the total amount of memory as the driver reports it. As you see this is only for NVIDIA cards, I don't know anything about ATI. You should be able to translate this to C/C++ easily.
AFAIK querying the amount of free memory is not possible.
05-09-2009, 10:20 AM
satan, I tried your solution. I need "|grep Memory" instead of "|grep memory" at this end.
Here is a solution that works for me:
* For nVidia, for the total amount of graphics memory only:
1. download nvidia-settings at:
2. there is some code example here:
This example uses the NVCtrl library. It gives access to the NV-CONTROL X extension. (X extension, not OpenGL extension)
Look for the part that query attribute NV_CTRL_VIDEO_RAM, it returns the amount of VRAM in kB.
you first need a Display connection:
then check if the X extension is available on the X server:
iterate over all the screens:
check if a screen is managed by nVidia:
if so, get the amount of VRAM in kB:
Bool status=XNVCTRLQueryAttribute(dpy,i,0, NV_CTRL_VIDEO_RAM,&ramSize);
then you can install the library yourself from this archive (the relevant files are in src/libXNVCtrl) or
rely on your Linux distribution. For example, Ubuntu package
"nvidia-settings" provides libXNVCtrl.a in /usr/lib/ and the header files NVCtrlLib.h and NVCtrl.h in /usr/include/NVCtrl/
Regarding the license, pick a version not older than 177.82:
prior to 177.82, nVidia picked the GPL by mistake. Now the code is MIT-X11 / BSD.
* For ATI (never tried), there is the following recent (March 2009) OpenGL extension, for the free memory only:
05-11-2009, 06:48 AM
Thanks for the tip. Sifting headers, there's lots of good GPU info you can query and set through that extension.
05-12-2009, 12:03 AM
Yet another fun way to do this with NV...
$ nvidia-settings --query=[gpu:0]/VideoRam
$ nvidia-settings -e all
to get a list of all attributes.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.