Game Development Community

Fix for bad profiler data on Mac

by Paul Scott · in Torque Game Engine · 05/14/2004 (6:44 pm) · 1 replies

The built in profiler gives some strange numbers when run on a macintosh.
This is because the functions startHighResolutionTimer and endHighResolutionTimer are not implemented for mac.

This resulted in some truly bizzare output from the profiler, that did not jibe with the windows side output for the same game code.

I don't know if what I've got is an optimal solution. It's just the product of an afternoon's casual hacking. But hey, it seems to be an improvement. The fix is very easy to apply:

in torque/engine/platform/profiler.cc, around line 87, right after
U32 endHighResolutionTimer(U32 time[2])
{
   U32 ticks;
   __asm__ __volatile__(
      "rdtsc\n"
      "sub  0x4(%%ecx),  %%edx\n"
      "sbb  (%%ecx),  %%eax\n"
      : "=a" (ticks) : "c" (time)
      );
   return ticks;
}
before the #else, add the following:
#elif defined(TORQUE_OS_MAC_CARB)
#include <Timer.h>
#include <Math64.h>
void startHighResolutionTimer(U32 time[2]) {
    UnsignedWide t;
    Microseconds(&t);
    time[0] = t.lo;
    time[1] = t.hi;
}
U32 endHighResolutionTimer(U32 time[2])  {
    UnsignedWide t;
    F64 a,b;
    Microseconds(&t);
    a = t.lo + (double)(t.hi) * 0x100000000;
    b = time[0] + (double)(time[1]) * 0x100000000;
    
    return a-b;
    
}

I started with the most recent HEAD from May 11, 2004.
I used TORQUE_OS_MAC_CARB, as opposed to TORQUE_OS_MAC_OSX, for no particular reason.
I know that there is some overhead involved in converting to a double & back again to make the math easier, but it is not signifigant, compared to the other overhead of Profiler::hashPush and Profiler::hashPop.

hope this helps!

#1
05/18/2004 (12:26 pm)
Thanks :)

I will double-check this fix sometime this week and get it into HEAD. Thank you very much for offering this. Rockin.

Edit: Fix checked in 7/18/04. Thanks again, Paul.