Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: measuring FPS in linux....

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2007
    Location
    Poland
    Posts
    7

    measuring FPS in linux....

    My measuring code looks like this (drawing its just simple triangle)

    Code :
    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

    Code :
    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 ?

  2. #2
    Junior Member Newbie
    Join Date
    Oct 2007
    Location
    Scotland
    Posts
    5

    Re: measuring FPS in linux....

    Hi

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

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

    Code :
    gettimeofday (&amp;tp, NULL);
    sec = tp.tv_sec;
    usec = tp.tv_usec;
     
    dusec = (sec - sec0) * 1000000 + (usec - usec0)

  3. #3
    Junior Member Regular Contributor
    Join Date
    Oct 2007
    Location
    Madison, WI
    Posts
    163

    Re: measuring FPS in linux....

    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);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •