views:

42

answers:

1

Hi, I have the following code, and wanted to get other set of eyes to make sure I have written the right code to calculate the frame rate of a scene. Could you please chime in?

This is written for the iPad using SDK 3.2.

thanks!

- (void)drawView:(id)sender
{
 mach_timebase_info_data_t timer;

 mach_timebase_info(&timer);
 uint64_t t1 = mach_absolute_time();

    [renderer render];

 uint64_t delta = mach_absolute_time() - t1;
 delta *= timer.numer;
 delta /= timer.denom;

 NSLog(@"%lld ms: %.2f FPS", delta, 1000000000.0f/delta);
}
A: 

In case you want to measure the time spent rendering OpenGL, this won't work. OpenGL operations are processed in parallel and will not affect timing on the CPU. You can profile the time it takes to issue the OpenGL calls, but you won't be able to see how long it took them to finish.

This is unfortunate, but it makes sense. This is probably the reason why everyone's just eying their framerate: if the GPU can't finish processing in time, your CPU gets blocked and your timer (most likely CADisplayLink) will not fire "in time".

You may want to look into (expensive) profiling tools like gDEBugger, but I'm not sure they work on iOS.

zmippie