apitrace consists of a set of tools to:
trace OpenGL, OpenGL ES, Direct3D, and DirectDraw APIs calls to a file;
replay OpenGL and OpenGL ES calls from a file;
inspect OpenGL state at any call while retracing;
visualize and edit trace files.
See the apitrace homepage for more details.
On 64bits Linux and Windows platforms you'll need apitrace binaries that match the architecture (32bits or 64bits) of the application being traced.
Detailed usage instructions are available here.