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