add include file, necessary for PS3 platform

This commit is contained in:
erwin.coumans
2008-04-02 17:23:52 +00:00
parent ba27e0522b
commit 285163b31a

View File

@@ -1,4 +1,4 @@
/*************************************************************************************************** /***************************************************************************************************
** **
** Real-Time Hierarchical Profiling for Game Programming Gems 3 ** Real-Time Hierarchical Profiling for Game Programming Gems 3
@@ -25,203 +25,207 @@
#ifdef USE_BT_CLOCK #ifdef USE_BT_CLOCK
#ifdef __CELLOS_LV2__ #ifdef __CELLOS_LV2__
#include <sys/sys_time.h> #include <sys/sys_time.h>
#include <sys/time_util.h>
#include <stdio.h> #include <stdio.h>
typedef uint64_t __int64; typedef uint64_t __int64;
#endif #endif
#if defined (SUNOS) || defined (__SUNOS__) #if defined (SUNOS) || defined (__SUNOS__)
#include <stdio.h> #include <stdio.h>
#endif #endif
#if defined(WIN32) || defined(_WIN32) #if defined(WIN32) || defined(_WIN32)
#define USE_WINDOWS_TIMERS #define USE_WINDOWS_TIMERS
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOWINRES #define NOWINRES
#define NOMCX #define NOMCX
#define NOIME #define NOIME
#ifdef _XBOX #ifdef _XBOX
#include <Xtl.h> #include <Xtl.h>
#else #else
#include <windows.h> #include <windows.h>
#endif #endif
#include <time.h> #include <time.h>
#else #else
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#define mymin(a,b) (a > b ? a : b) #define mymin(a,b) (a > b ? a : b)
/// basic clock /// basic clock
class btClock class btClock
{
public:
btClock()
{ {
public:
btClock()
{
#ifdef USE_WINDOWS_TIMERS #ifdef USE_WINDOWS_TIMERS
QueryPerformanceFrequency(&mClockFrequency); QueryPerformanceFrequency(&mClockFrequency);
#endif #endif
reset(); reset();
} }
~btClock() ~btClock()
{ {
} }
/// Resets the initial reference time. /// Resets the initial reference time.
void reset() void reset()
{ {
#ifdef USE_WINDOWS_TIMERS #ifdef USE_WINDOWS_TIMERS
QueryPerformanceCounter(&mStartTime); QueryPerformanceCounter(&mStartTime);
mStartTick = GetTickCount(); mStartTick = GetTickCount();
mPrevElapsedTime = 0; mPrevElapsedTime = 0;
#else #else
#ifdef __CELLOS_LV2__ #ifdef __CELLOS_LV2__
typedef uint64_t __int64; typedef uint64_t __int64;
typedef __int64 ClockSize; typedef __int64 ClockSize;
ClockSize newTime; ClockSize newTime;
__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
mStartTime = newTime; SYS_TIMEBASE_GET( newTime );
mStartTime = newTime;
#else #else
gettimeofday(&mStartTime, 0); gettimeofday(&mStartTime, 0);
#endif #endif
#endif #endif
} }
/// Returns the time in ms since the last call to reset or since /// Returns the time in ms since the last call to reset or since
/// the btClock was created. /// the btClock was created.
unsigned long int getTimeMilliseconds() unsigned long int getTimeMilliseconds()
{ {
#ifdef USE_WINDOWS_TIMERS #ifdef USE_WINDOWS_TIMERS
LARGE_INTEGER currentTime; LARGE_INTEGER currentTime;
QueryPerformanceCounter(&currentTime); QueryPerformanceCounter(&currentTime);
LONGLONG elapsedTime = currentTime.QuadPart - LONGLONG elapsedTime = currentTime.QuadPart -
mStartTime.QuadPart; mStartTime.QuadPart;
// Compute the number of millisecond ticks elapsed. // Compute the number of millisecond ticks elapsed.
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime / unsigned long msecTicks = (unsigned long)(1000 * elapsedTime /
mClockFrequency.QuadPart);
// Check for unexpected leaps in the Win32 performance counter.
// (This is caused by unexpected data across the PCI to ISA
// bridge, aka south bridge. See Microsoft KB274323.)
unsigned long elapsedTicks = GetTickCount() - mStartTick;
signed long msecOff = (signed long)(msecTicks - elapsedTicks);
if (msecOff < -100 || msecOff > 100)
{
// Adjust the starting time forwards.
LONGLONG msecAdjustment = mymin(msecOff *
mClockFrequency.QuadPart / 1000, elapsedTime -
mPrevElapsedTime);
mStartTime.QuadPart += msecAdjustment;
elapsedTime -= msecAdjustment;
// Recompute the number of millisecond ticks elapsed.
msecTicks = (unsigned long)(1000 * elapsedTime /
mClockFrequency.QuadPart); mClockFrequency.QuadPart);
}
// Check for unexpected leaps in the Win32 performance counter. // Store the current elapsed time for adjustments next time.
// (This is caused by unexpected data across the PCI to ISA mPrevElapsedTime = elapsedTime;
// bridge, aka south bridge. See Microsoft KB274323.)
unsigned long elapsedTicks = GetTickCount() - mStartTick;
signed long msecOff = (signed long)(msecTicks - elapsedTicks);
if (msecOff < -100 || msecOff > 100)
{
// Adjust the starting time forwards.
LONGLONG msecAdjustment = mymin(msecOff *
mClockFrequency.QuadPart / 1000, elapsedTime -
mPrevElapsedTime);
mStartTime.QuadPart += msecAdjustment;
elapsedTime -= msecAdjustment;
// Recompute the number of millisecond ticks elapsed. return msecTicks;
msecTicks = (unsigned long)(1000 * elapsedTime /
mClockFrequency.QuadPart);
}
// Store the current elapsed time for adjustments next time.
mPrevElapsedTime = elapsedTime;
return msecTicks;
#else #else
#ifdef __CELLOS_LV2__ #ifdef __CELLOS_LV2__
__int64 freq=sys_time_get_timebase_frequency(); __int64 freq=sys_time_get_timebase_frequency();
double dFreq=((double) freq) / 1000.0; double dFreq=((double) freq) / 1000.0;
typedef uint64_t __int64; typedef uint64_t __int64;
typedef __int64 ClockSize; typedef __int64 ClockSize;
ClockSize newTime; ClockSize newTime;
__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); SYS_TIMEBASE_GET( newTime );
//__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
return (newTime-mStartTime) / dFreq;
return (newTime-mStartTime) / dFreq;
#else #else
struct timeval currentTime; struct timeval currentTime;
gettimeofday(&currentTime, 0); gettimeofday(&currentTime, 0);
return (currentTime.tv_sec - mStartTime.tv_sec) * 1000 + return (currentTime.tv_sec - mStartTime.tv_sec) * 1000 +
(currentTime.tv_usec - mStartTime.tv_usec) / 1000; (currentTime.tv_usec - mStartTime.tv_usec) / 1000;
#endif //__CELLOS_LV2__ #endif //__CELLOS_LV2__
#endif #endif
}
/// Returns the time in us since the last call to reset or since
/// the Clock was created.
unsigned long int getTimeMicroseconds()
{
#ifdef USE_WINDOWS_TIMERS
LARGE_INTEGER currentTime;
QueryPerformanceCounter(&currentTime);
LONGLONG elapsedTime = currentTime.QuadPart -
mStartTime.QuadPart;
// Compute the number of millisecond ticks elapsed.
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime /
mClockFrequency.QuadPart);
// Check for unexpected leaps in the Win32 performance counter.
// (This is caused by unexpected data across the PCI to ISA
// bridge, aka south bridge. See Microsoft KB274323.)
unsigned long elapsedTicks = GetTickCount() - mStartTick;
signed long msecOff = (signed long)(msecTicks - elapsedTicks);
if (msecOff < -100 || msecOff > 100)
{
// Adjust the starting time forwards.
LONGLONG msecAdjustment = mymin(msecOff *
mClockFrequency.QuadPart / 1000, elapsedTime -
mPrevElapsedTime);
mStartTime.QuadPart += msecAdjustment;
elapsedTime -= msecAdjustment;
} }
/// Returns the time in us since the last call to reset or since // Store the current elapsed time for adjustments next time.
/// the Clock was created. mPrevElapsedTime = elapsedTime;
unsigned long int getTimeMicroseconds()
{
#ifdef USE_WINDOWS_TIMERS
LARGE_INTEGER currentTime;
QueryPerformanceCounter(&currentTime);
LONGLONG elapsedTime = currentTime.QuadPart -
mStartTime.QuadPart;
// Compute the number of millisecond ticks elapsed. // Convert to microseconds.
unsigned long msecTicks = (unsigned long)(1000 * elapsedTime / unsigned long usecTicks = (unsigned long)(1000000 * elapsedTime /
mClockFrequency.QuadPart); mClockFrequency.QuadPart);
// Check for unexpected leaps in the Win32 performance counter. return usecTicks;
// (This is caused by unexpected data across the PCI to ISA
// bridge, aka south bridge. See Microsoft KB274323.)
unsigned long elapsedTicks = GetTickCount() - mStartTick;
signed long msecOff = (signed long)(msecTicks - elapsedTicks);
if (msecOff < -100 || msecOff > 100)
{
// Adjust the starting time forwards.
LONGLONG msecAdjustment = mymin(msecOff *
mClockFrequency.QuadPart / 1000, elapsedTime -
mPrevElapsedTime);
mStartTime.QuadPart += msecAdjustment;
elapsedTime -= msecAdjustment;
}
// Store the current elapsed time for adjustments next time.
mPrevElapsedTime = elapsedTime;
// Convert to microseconds.
unsigned long usecTicks = (unsigned long)(1000000 * elapsedTime /
mClockFrequency.QuadPart);
return usecTicks;
#else #else
#ifdef __CELLOS_LV2__ #ifdef __CELLOS_LV2__
__int64 freq=sys_time_get_timebase_frequency(); __int64 freq=sys_time_get_timebase_frequency();
double dFreq=((double) freq)/ 1000000.0; double dFreq=((double) freq)/ 1000000.0;
typedef uint64_t __int64; typedef uint64_t __int64;
typedef __int64 ClockSize; typedef __int64 ClockSize;
ClockSize newTime; ClockSize newTime;
__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
SYS_TIMEBASE_GET( newTime );
return (newTime-mStartTime) / dFreq;
return (newTime-mStartTime) / dFreq;
#else #else
struct timeval currentTime; struct timeval currentTime;
gettimeofday(&currentTime, 0); gettimeofday(&currentTime, 0);
return (currentTime.tv_sec - mStartTime.tv_sec) * 1000000 + return (currentTime.tv_sec - mStartTime.tv_sec) * 1000000 +
(currentTime.tv_usec - mStartTime.tv_usec); (currentTime.tv_usec - mStartTime.tv_usec);
#endif//__CELLOS_LV2__ #endif//__CELLOS_LV2__
#endif #endif
} }
private: private:
#ifdef USE_WINDOWS_TIMERS #ifdef USE_WINDOWS_TIMERS
LARGE_INTEGER mClockFrequency; LARGE_INTEGER mClockFrequency;
DWORD mStartTick; DWORD mStartTick;
LONGLONG mPrevElapsedTime; LONGLONG mPrevElapsedTime;
LARGE_INTEGER mStartTime; LARGE_INTEGER mStartTime;
#else #else
#ifdef __CELLOS_LV2__ #ifdef __CELLOS_LV2__
uint64_t mStartTime; uint64_t mStartTime;
#else #else
struct timeval mStartTime; struct timeval mStartTime;
#endif #endif
#endif //__CELLOS_LV2__ #endif //__CELLOS_LV2__
}; };
#endif //USE_BT_CLOCK #endif //USE_BT_CLOCK
@@ -274,7 +278,7 @@ public:
void First(void); void First(void);
void Next(void); void Next(void);
bool Is_Done(void); bool Is_Done(void);
bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); } bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); }
void Enter_Child( int index ); // Make the given child the new parent void Enter_Child( int index ); // Make the given child the new parent
void Enter_Largest_Child( void ); // Make the largest child the new parent void Enter_Largest_Child( void ); // Make the largest child the new parent
@@ -334,7 +338,7 @@ public:
{ {
CProfileManager::Start_Profile( name ); CProfileManager::Start_Profile( name );
} }
~CProfileSample( void ) ~CProfileSample( void )
{ {
CProfileManager::Stop_Profile(); CProfileManager::Stop_Profile();