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 CProfileNode * Get_Sub_Node(const char *name)
CProfileSample(const char *name)
CProfileNode * Get_Child(void)
unsigned long long int uint64_t
static CProfileIterator * Get_Iterator(void)
CProfileIterator(CProfileNode *start)
CProfileNode gRoots[BT_QUICKPROF_MAX_THREAD_COUNT]
static void Start_Profile(const char *name)
static void CleanupMemory(void)
void() btEnterProfileZoneFunc(const char *msg)
btEnterProfileZoneFunc * btGetCurrentEnterProfileZoneFunc()
CProfileNode * CurrentParent
btScalar getTimeSeconds()
Returns the time in s since the last call to reset or since the Clock was created.
unsigned int btQuickprofGetCurrentThreadIndex2()
unsigned long long int getTimeNanoseconds()
const char * Get_Current_Name(void)
float Get_Current_Parent_Total_Time(void)
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling.
float Get_Current_Total_Time(void)
void Enter_Child(int index)
void reset()
Resets the initial reference time.
An iterator to navigate through the tree.
static void Stop_Profile(void)
float Profile_Get_Tick_Rate(void)
void btSetCustomEnterProfileZoneFunc(btEnterProfileZoneFunc *enterFunc)
btLeaveProfileZoneFunc * btGetCurrentLeaveProfileZoneFunc()
void btEnterProfileZone(const char *name)
static void dumpRecursive(CProfileIterator *profileIterator, int spacing)
static unsigned long int ResetTime
btClock()
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling.
CProfileNode * Get_Sibling(void)
struct btClockData * m_data
static ThreadsafeCounter gThreadCounter
void btLeaveProfileZone()
void Profile_Get_Ticks(unsigned long int *ticks)
unsigned long long int getTimeMicroseconds()
Returns the time in us since the last call to reset or since the Clock was created.
CProfileNode * gCurrentNodes[BT_QUICKPROF_MAX_THREAD_COUNT]
void btSetCustomLeaveProfileZoneFunc(btLeaveProfileZoneFunc *leaveFunc)
static void Release_Iterator(CProfileIterator *iterator)
btClock & operator=(const btClock &other)
static btClock gProfileClock
static float Get_Time_Since_Reset(void)
unsigned long long int getTimeMilliseconds()
Returns the time in ms since the last call to reset or since the btClock was created.
A node in the Profile Hierarchy Tree.
static void Increment_Frame_Counter(void)
CProfileNode * Get_Parent(void)
const unsigned int BT_QUICKPROF_MAX_THREAD_COUNT
static btEnterProfileZoneFunc * bts_enterFunc
int Get_Current_Total_Calls(void)
void() btLeaveProfileZoneFunc()
void btLeaveProfileZoneDefault()
CProfileNode * CurrentChild
unsigned long int StartTime
CProfileNode(const char *name, CProfileNode *parent)
LARGE_INTEGER mClockFrequency
static int Get_Frame_Count_Since_Reset(void)
unsigned int btGetCurrentThreadIndex()
const char * Get_Current_Parent_Name(void)
static btLeaveProfileZoneFunc * bts_leaveFunc
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
void btEnterProfileZoneDefault(const char *name)