23 #include <sys/sys_time.h>
24 #include <sys/time_util.h>
28 #if defined (SUNOS) || defined (__SUNOS__)
32 #include <mach/mach_time.h>
33 #include <TargetConditionals.h>
36 #if defined(WIN32) || defined(_WIN32)
38 #define BT_USE_WINDOWS_TIMERS
39 #define WIN32_LEAN_AND_MEAN
50 #define GetTickCount64 GetTickCount
61 #ifdef BT_LINUX_REALTIME
64 #endif //BT_LINUX_REALTIME
68 #define mymin(a,b) (a > b ? a : b)
73 #ifdef BT_USE_WINDOWS_TIMERS
86 #endif //__CELLOS_LV2__
94 #ifdef BT_USE_WINDOWS_TIMERS
121 #ifdef BT_USE_WINDOWS_TIMERS
125 #ifdef __CELLOS_LV2__
130 SYS_TIMEBASE_GET( newTime );
134 m_data->mStartTimeNano = mach_absolute_time();
145 #ifdef BT_USE_WINDOWS_TIMERS
146 LARGE_INTEGER currentTime;
147 QueryPerformanceCounter(¤tTime);
148 LONGLONG elapsedTime = currentTime.QuadPart -
151 unsigned long msecTicks = (
unsigned long)(1000 * elapsedTime /
157 #ifdef __CELLOS_LV2__
158 uint64_t freq=sys_time_get_timebase_frequency();
159 double dFreq=((double) freq) / 1000.0;
162 SYS_TIMEBASE_GET( newTime );
168 struct timeval currentTime;
169 gettimeofday(¤tTime, 0);
172 #endif //__CELLOS_LV2__
180 #ifdef BT_USE_WINDOWS_TIMERS
182 LARGE_INTEGER currentTime, elapsedTime;
184 QueryPerformanceCounter(¤tTime);
185 elapsedTime.QuadPart = currentTime.QuadPart -
187 elapsedTime.QuadPart *= 1000000;
190 return (
unsigned long long) elapsedTime.QuadPart;
193 #ifdef __CELLOS_LV2__
194 uint64_t freq=sys_time_get_timebase_frequency();
195 double dFreq=((double) freq)/ 1000000.0;
199 SYS_TIMEBASE_GET( newTime );
204 struct timeval currentTime;
205 gettimeofday(¤tTime, 0);
208 #endif//__CELLOS_LV2__
214 #ifdef BT_USE_WINDOWS_TIMERS
216 LARGE_INTEGER currentTime, elapsedTime;
218 QueryPerformanceCounter(¤tTime);
219 elapsedTime.QuadPart = currentTime.QuadPart -
221 elapsedTime.QuadPart *= 1000000000;
224 return (
unsigned long long) elapsedTime.QuadPart;
227 #ifdef __CELLOS_LV2__
228 uint64_t freq=sys_time_get_timebase_frequency();
229 double dFreq=((double) freq)/ 1e9;
233 SYS_TIMEBASE_GET( newTime );
239 static long double conversion = 0.0L;
240 if( 0.0L == conversion )
243 mach_timebase_info_data_t info;
244 int err = mach_timebase_info( &info );
250 conversion = info.numer / info.denom;
252 return (ticks * conversion);
257 #ifdef BT_LINUX_REALTIME
259 clock_gettime(CLOCK_REALTIME,&ts);
260 return 1000000000*ts.tv_sec + ts.tv_nsec;
262 struct timeval currentTime;
263 gettimeofday(¤tTime, 0);
266 #endif //BT_LINUX_REALTIME
269 #endif//__CELLOS_LV2__
282 #ifndef BT_NO_PROFILE
321 RecursionCounter( 0 ),
358 if ( child->
Name == name ) {
400 unsigned long int time;
616 unsigned long int time;
626 profileIterator->
First();
627 if (profileIterator->
Is_Done())
633 for (i=0;i<spacing;i++) printf(
".");
634 printf(
"----------------------------------\n");
635 for (i=0;i<spacing;i++) printf(
".");
636 printf(
"Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->
Get_Current_Parent_Name(), parent_time );
637 float totalTime = 0.f;
642 for (i = 0; !profileIterator->
Is_Done(); i++,profileIterator->
Next())
646 accumulated_time += current_total_time;
647 float fraction = parent_time >
SIMD_EPSILON ? (current_total_time / parent_time) * 100 : 0.f;
649 int i;
for (i=0;i<spacing;i++) printf(
".");
651 printf(
"%d -- %s (%.2f %%) :: %.3f ms / frame (%d calls)\n",i, profileIterator->
Get_Current_Name(), fraction,(current_total_time / (
double)frames_since_reset),profileIterator->
Get_Current_Total_Calls());
652 totalTime += current_total_time;
656 if (parent_time < accumulated_time)
660 for (i=0;i<spacing;i++) printf(
".");
661 printf(
"%s (%.3f %%) :: %.3f ms\n",
"Unaccounted:",parent_time >
SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
663 for (i=0;i<numChildren;i++)
690 #else // #if BT_THREADSAFE
691 const unsigned int kNullIndex = ~0
U;
693 #if defined(__MINGW32__) || defined(__MINGW64__)
694 static __thread
unsigned int sThreadIndex = kNullIndex;
696 __declspec( thread )
static unsigned int sThreadIndex = kNullIndex;
701 unsigned int sThreadIndex = 0;
704 static __thread
unsigned int sThreadIndex = kNullIndex;
708 static __thread
unsigned int sThreadIndex = kNullIndex;
710 unsigned int sThreadIndex = 0;
718 if ( sThreadIndex == kNullIndex )
723 #endif // #else // #if BT_THREADSAFE
743 #endif //BT_NO_PROFILE