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