- Timestamp:
- Feb 27, 2011, 7:43:24 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/kicklib/src/external/bullet/LinearMath/btQuickprof.cpp
r5781 r7983 1 1 /* 2 2 3 /***************************************************************************************************3 *************************************************************************************************** 4 4 ** 5 5 ** profile.cpp … … 14 14 // Ogre (www.ogre3d.org). 15 15 16 #include " LinearMath/btQuickprof.h"17 18 19 #ifdef USE_BT_CLOCK 16 #include "btQuickprof.h" 17 18 #ifndef BT_NO_PROFILE 19 20 20 21 21 static btClock gProfileClock; 22 23 24 #ifdef __CELLOS_LV2__ 25 #include <sys/sys_time.h> 26 #include <sys/time_util.h> 27 #include <stdio.h> 28 #endif 29 30 #if defined (SUNOS) || defined (__SUNOS__) 31 #include <stdio.h> 32 #endif 33 34 #if defined(WIN32) || defined(_WIN32) 35 36 #define BT_USE_WINDOWS_TIMERS 37 #define WIN32_LEAN_AND_MEAN 38 #define NOWINRES 39 #define NOMCX 40 #define NOIME 41 42 #ifdef _XBOX 43 #include <Xtl.h> 44 #else //_XBOX 45 #include <windows.h> 46 #endif //_XBOX 47 48 #include <time.h> 49 50 51 #else //_WIN32 52 #include <sys/time.h> 53 #endif //_WIN32 54 55 #define mymin(a,b) (a > b ? a : b) 56 57 struct btClockData 58 { 59 60 #ifdef BT_USE_WINDOWS_TIMERS 61 LARGE_INTEGER mClockFrequency; 62 DWORD mStartTick; 63 LONGLONG mPrevElapsedTime; 64 LARGE_INTEGER mStartTime; 65 #else 66 #ifdef __CELLOS_LV2__ 67 uint64_t mStartTime; 68 #else 69 struct timeval mStartTime; 70 #endif 71 #endif //__CELLOS_LV2__ 72 73 }; 74 75 ///The btClock is a portable basic clock that measures accurate time in seconds, use for profiling. 76 btClock::btClock() 77 { 78 m_data = new btClockData; 79 #ifdef BT_USE_WINDOWS_TIMERS 80 QueryPerformanceFrequency(&m_data->mClockFrequency); 81 #endif 82 reset(); 83 } 84 85 btClock::~btClock() 86 { 87 delete m_data; 88 } 89 90 btClock::btClock(const btClock& other) 91 { 92 m_data = new btClockData; 93 *m_data = *other.m_data; 94 } 95 96 btClock& btClock::operator=(const btClock& other) 97 { 98 *m_data = *other.m_data; 99 return *this; 100 } 101 102 103 /// Resets the initial reference time. 104 void btClock::reset() 105 { 106 #ifdef BT_USE_WINDOWS_TIMERS 107 QueryPerformanceCounter(&m_data->mStartTime); 108 m_data->mStartTick = GetTickCount(); 109 m_data->mPrevElapsedTime = 0; 110 #else 111 #ifdef __CELLOS_LV2__ 112 113 typedef uint64_t ClockSize; 114 ClockSize newTime; 115 //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); 116 SYS_TIMEBASE_GET( newTime ); 117 m_data->mStartTime = newTime; 118 #else 119 gettimeofday(&m_data->mStartTime, 0); 120 #endif 121 #endif 122 } 123 124 /// Returns the time in ms since the last call to reset or since 125 /// the btClock was created. 126 unsigned long int btClock::getTimeMilliseconds() 127 { 128 #ifdef BT_USE_WINDOWS_TIMERS 129 LARGE_INTEGER currentTime; 130 QueryPerformanceCounter(¤tTime); 131 LONGLONG elapsedTime = currentTime.QuadPart - 132 m_data->mStartTime.QuadPart; 133 // Compute the number of millisecond ticks elapsed. 134 unsigned long msecTicks = (unsigned long)(1000 * elapsedTime / 135 m_data->mClockFrequency.QuadPart); 136 // Check for unexpected leaps in the Win32 performance counter. 137 // (This is caused by unexpected data across the PCI to ISA 138 // bridge, aka south bridge. See Microsoft KB274323.) 139 unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick; 140 signed long msecOff = (signed long)(msecTicks - elapsedTicks); 141 if (msecOff < -100 || msecOff > 100) 142 { 143 // Adjust the starting time forwards. 144 LONGLONG msecAdjustment = mymin(msecOff * 145 m_data->mClockFrequency.QuadPart / 1000, elapsedTime - 146 m_data->mPrevElapsedTime); 147 m_data->mStartTime.QuadPart += msecAdjustment; 148 elapsedTime -= msecAdjustment; 149 150 // Recompute the number of millisecond ticks elapsed. 151 msecTicks = (unsigned long)(1000 * elapsedTime / 152 m_data->mClockFrequency.QuadPart); 153 } 154 155 // Store the current elapsed time for adjustments next time. 156 m_data->mPrevElapsedTime = elapsedTime; 157 158 return msecTicks; 159 #else 160 161 #ifdef __CELLOS_LV2__ 162 uint64_t freq=sys_time_get_timebase_frequency(); 163 double dFreq=((double) freq) / 1000.0; 164 typedef uint64_t ClockSize; 165 ClockSize newTime; 166 SYS_TIMEBASE_GET( newTime ); 167 //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); 168 169 return (unsigned long int)((double(newTime-m_data->mStartTime)) / dFreq); 170 #else 171 172 struct timeval currentTime; 173 gettimeofday(¤tTime, 0); 174 return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000 + 175 (currentTime.tv_usec - m_data->mStartTime.tv_usec) / 1000; 176 #endif //__CELLOS_LV2__ 177 #endif 178 } 179 180 /// Returns the time in us since the last call to reset or since 181 /// the Clock was created. 182 unsigned long int btClock::getTimeMicroseconds() 183 { 184 #ifdef BT_USE_WINDOWS_TIMERS 185 LARGE_INTEGER currentTime; 186 QueryPerformanceCounter(¤tTime); 187 LONGLONG elapsedTime = currentTime.QuadPart - 188 m_data->mStartTime.QuadPart; 189 190 // Compute the number of millisecond ticks elapsed. 191 unsigned long msecTicks = (unsigned long)(1000 * elapsedTime / 192 m_data->mClockFrequency.QuadPart); 193 194 // Check for unexpected leaps in the Win32 performance counter. 195 // (This is caused by unexpected data across the PCI to ISA 196 // bridge, aka south bridge. See Microsoft KB274323.) 197 unsigned long elapsedTicks = GetTickCount() - m_data->mStartTick; 198 signed long msecOff = (signed long)(msecTicks - elapsedTicks); 199 if (msecOff < -100 || msecOff > 100) 200 { 201 // Adjust the starting time forwards. 202 LONGLONG msecAdjustment = mymin(msecOff * 203 m_data->mClockFrequency.QuadPart / 1000, elapsedTime - 204 m_data->mPrevElapsedTime); 205 m_data->mStartTime.QuadPart += msecAdjustment; 206 elapsedTime -= msecAdjustment; 207 } 208 209 // Store the current elapsed time for adjustments next time. 210 m_data->mPrevElapsedTime = elapsedTime; 211 212 // Convert to microseconds. 213 unsigned long usecTicks = (unsigned long)(1000000 * elapsedTime / 214 m_data->mClockFrequency.QuadPart); 215 216 return usecTicks; 217 #else 218 219 #ifdef __CELLOS_LV2__ 220 uint64_t freq=sys_time_get_timebase_frequency(); 221 double dFreq=((double) freq)/ 1000000.0; 222 typedef uint64_t ClockSize; 223 ClockSize newTime; 224 //__asm __volatile__( "mftb %0" : "=r" (newTime) : : "memory"); 225 SYS_TIMEBASE_GET( newTime ); 226 227 return (unsigned long int)((double(newTime-m_data->mStartTime)) / dFreq); 228 #else 229 230 struct timeval currentTime; 231 gettimeofday(¤tTime, 0); 232 return (currentTime.tv_sec - m_data->mStartTime.tv_sec) * 1000000 + 233 (currentTime.tv_usec - m_data->mStartTime.tv_usec); 234 #endif//__CELLOS_LV2__ 235 #endif 236 } 237 238 239 240 22 241 23 242 inline void Profile_Get_Ticks(unsigned long int * ticks) … … 343 562 344 563 345 #endif //USE_BT_CLOCK 346 564 565 #endif //BT_NO_PROFILE
Note: See TracChangeset
for help on using the changeset viewer.