Back to index

supertuxkart  0.5+dfsg1
Public Member Functions
btClock Class Reference

basic clock More...

#include <btQuickprof.h>

List of all members.

Public Member Functions

 btClock ()
 ~btClock ()
void reset ()
 Resets the initial reference time.
unsigned long int getTimeMilliseconds ()
 Returns the time in ms since the last call to reset or since the btClock was created.
unsigned long int getTimeMicroseconds ()
 Returns the time in us since the last call to reset or since the Clock was created.

Detailed Description

basic clock

Definition at line 58 of file btQuickprof.h.


Constructor & Destructor Documentation

btClock::btClock ( ) [inline]

Definition at line 61 of file btQuickprof.h.

       {
#ifdef USE_WINDOWS_TIMERS
              QueryPerformanceFrequency(&mClockFrequency);
#endif
              reset();
       }

Here is the call graph for this function:

btClock::~btClock ( ) [inline]

Definition at line 69 of file btQuickprof.h.

       {
       }

Member Function Documentation

unsigned long int btClock::getTimeMicroseconds ( ) [inline]

Returns the time in us since the last call to reset or since the Clock was created.

Definition at line 157 of file btQuickprof.h.

       {
#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;
              }

              // 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

#ifdef __CELLOS_LV2__
              __int64 freq=sys_time_get_timebase_frequency();
              double dFreq=((double) freq)/ 1000000.0;
              typedef uint64_t __int64;
              typedef __int64  ClockSize;
              ClockSize newTime;
              //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
              SYS_TIMEBASE_GET( newTime );

              return (newTime-mStartTime) / dFreq;
#else

              struct timeval currentTime;
              gettimeofday(&currentTime, 0);
              return (currentTime.tv_sec - mStartTime.tv_sec) * 1000000 + 
                     (currentTime.tv_usec - mStartTime.tv_usec);
#endif//__CELLOS_LV2__
#endif 
       }

Here is the caller graph for this function:

unsigned long int btClock::getTimeMilliseconds ( ) [inline]

Returns the time in ms since the last call to reset or since the btClock was created.

Definition at line 98 of file btQuickprof.h.

       {
#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;

                     // Recompute the number of millisecond ticks elapsed.
                     msecTicks = (unsigned long)(1000 * elapsedTime / 
                            mClockFrequency.QuadPart);
              }

              // Store the current elapsed time for adjustments next time.
              mPrevElapsedTime = elapsedTime;

              return msecTicks;
#else

#ifdef __CELLOS_LV2__
              __int64 freq=sys_time_get_timebase_frequency();
              double dFreq=((double) freq) / 1000.0;
              typedef uint64_t __int64;
              typedef __int64  ClockSize;
              ClockSize newTime;
              SYS_TIMEBASE_GET( newTime );
              //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");

              return (newTime-mStartTime) / dFreq;
#else

              struct timeval currentTime;
              gettimeofday(&currentTime, 0);
              return (currentTime.tv_sec - mStartTime.tv_sec) * 1000 + 
                     (currentTime.tv_usec - mStartTime.tv_usec) / 1000;
#endif //__CELLOS_LV2__
#endif
       }
void btClock::reset ( ) [inline]

Resets the initial reference time.

Definition at line 74 of file btQuickprof.h.

       {
#ifdef USE_WINDOWS_TIMERS
              QueryPerformanceCounter(&mStartTime);
              mStartTick = GetTickCount();
              mPrevElapsedTime = 0;
#else
#ifdef __CELLOS_LV2__

              typedef uint64_t __int64;
              typedef __int64  ClockSize;
              ClockSize newTime;
              //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory");
              SYS_TIMEBASE_GET( newTime );
              mStartTime = newTime;
#else
              gettimeofday(&mStartTime, 0);
#endif

#endif
       }

Here is the caller graph for this function:


The documentation for this class was generated from the following file: