PDA

View Full Version : measuring FPS in linux....



Adrian P.
12-02-2007, 10:34 AM
My measuring code looks like this (drawing its just simple triangle)



if(frames == 0)
{
gettimeofday(&tp, NULL);
start = tp.tv_usec;
}
drawGLScene();
swapBuffers();
++frames;
if(frames == 200)
{
gettimeofday(&tp, NULL);
stop = tp.tv_usec;
cout << "Time elapsed (ms): " << stop - start <<"FPS = " << 200 / ((stop - start) / 1000) << endl;
frames = 0;
deltas = 0;
start = 0;
stop = 0;
}


And i'm gettin strange output like



Time elapsed (ms): -379370FPS = 0
Time elapsed (ms): 623966FPS = 0
Time elapsed (ms): -383865FPS = 0
Time elapsed (ms): -376072FPS = 0
Time elapsed (ms): 620142FPS = 0



PS vars 'start' and 'stop' are declared as suseconds_t. what i am doing wrong ?

MontyMole
12-02-2007, 12:10 PM
Hi

The tv_usec member counts milliseconds, but rolls back to 0 every second. You need to check the seconds as well:


gettimeofday (&amp;tp, NULL);
sec0 = tp.tv_sec;
usec0 = tp.tv_usec;
and then after doing something


gettimeofday (&amp;tp, NULL);
sec = tp.tv_sec;
usec = tp.tv_usec;

dusec = (sec - sec0) * 1000000 + (usec - usec0)

Timothy Farrar
12-02-2007, 12:26 PM
BTW, if you want something much more useful then FPS, have the GPU return how long parts of your algorithm takes,

// somewhere initialize your query object(s)
glGenQueries(1,&query);


Then when doing GPU stuff or drawing,


// handle result from previous frame
glGetQueryObjectiv(query,GL_QUERY_RESULT,&result);

// start query for new frame
glBeginQuery(GL_TIME_ELAPSED_EXT,query);

... // do something

// end query for new frame
glEndQuery(GL_TIME_ELAPSED_EXT);