Friday, September 3, 2010

Writing the output of running glxgears to file

glxgears is a API that people frequently use to test if their graphical user interface works, and though it not a standardized benchmark of how good your GUI is, it does (at least, theoretically) give you some idea of the frames per second that are being rendered on your screen.

When you type the command glxgears in your terminal you should see an animation of rotating gears in the foreground and in the background, the terminal outputs every 5 or so seconds the frames per second that are being used in the rendering...

So now, my problem was simply to get the output of the terminal, that is the FPS values that are getting printed after roughly 5 seconds into a file.

The most obvious solution, that is:
glxgears >> out.txt
does not work. Apparently, glxgears does not flush the values if the output is redirected to file.

I was unable to "solve" the problem (that would require changing the source code of glxgears to make it not only print the output values but also flush it). For now I got something to work which is alright for me. I manually kill the glxgears every 5 seconds, store the output, and then restart another glxgears process.

This is not so trivial actually. If you kill the glxgears using something like
killall glxgears
no FPS values are returned or written to file. Instead you need to shutdown glxgears by telling x-server to withdraw its window resource!