25 #include <sys/sys_time.h>
26 #include <sys/time_util.h>
30 #if defined (SUNOS) || defined (__SUNOS__)
34 #if defined(WIN32) || defined(_WIN32)
36 #define BT_USE_WINDOWS_TIMERS
37 #define WIN32_LEAN_AND_MEAN
48 #define GetTickCount64 GetTickCount
60 #define mymin(a,b) (a > b ? a : b)
65 #ifdef BT_USE_WINDOWS_TIMERS
74 struct timeval mStartTime;
76 #endif //__CELLOS_LV2__
84 #ifdef BT_USE_WINDOWS_TIMERS
111 #ifdef BT_USE_WINDOWS_TIMERS
116 #ifdef __CELLOS_LV2__
121 SYS_TIMEBASE_GET( newTime );
133 #ifdef BT_USE_WINDOWS_TIMERS
134 LARGE_INTEGER currentTime;
135 QueryPerformanceCounter(¤tTime);
136 LONGLONG elapsedTime = currentTime.QuadPart -
139 unsigned long msecTicks = (
unsigned long)(1000 * elapsedTime /
145 signed long msecOff = (
signed long)(msecTicks - elapsedTicks);
146 if (msecOff < -100 || msecOff > 100)
149 LONGLONG msecAdjustment =
mymin(msecOff *
153 elapsedTime -= msecAdjustment;
156 msecTicks = (
unsigned long)(1000 * elapsedTime /
166 #ifdef __CELLOS_LV2__
167 uint64_t freq=sys_time_get_timebase_frequency();
168 double dFreq=((double) freq) / 1000.0;
171 SYS_TIMEBASE_GET( newTime );
177 struct timeval currentTime;
178 gettimeofday(¤tTime, 0);
181 #endif //__CELLOS_LV2__
189 #ifdef BT_USE_WINDOWS_TIMERS
190 LARGE_INTEGER currentTime;
191 QueryPerformanceCounter(¤tTime);
192 LONGLONG elapsedTime = currentTime.QuadPart -
196 unsigned long msecTicks = (
unsigned long)(1000 * elapsedTime /
203 signed long msecOff = (
signed long)(msecTicks - elapsedTicks);
204 if (msecOff < -100 || msecOff > 100)
207 LONGLONG msecAdjustment =
mymin(msecOff *
211 elapsedTime -= msecAdjustment;
218 unsigned long usecTicks = (
unsigned long)(1000000 * elapsedTime /
224 #ifdef __CELLOS_LV2__
225 uint64_t freq=sys_time_get_timebase_frequency();
226 double dFreq=((double) freq)/ 1000000.0;
230 SYS_TIMEBASE_GET( newTime );
235 struct timeval currentTime;
236 gettimeofday(¤tTime, 0);
239 #endif//__CELLOS_LV2__
289 RecursionCounter( 0 ),
326 if ( child->
Name == name ) {
368 unsigned long int time;
486 gProfileClock.
reset();
508 unsigned long int time;
518 profileIterator->
First();
519 if (profileIterator->
Is_Done())
525 for (i=0;i<spacing;i++) printf(
".");
526 printf(
"----------------------------------\n");
527 for (i=0;i<spacing;i++) printf(
".");
528 printf(
"Profiling: %s (total running time: %.3f ms) ---\n", profileIterator->
Get_Current_Parent_Name(), parent_time );
529 float totalTime = 0.f;
534 for (i = 0; !profileIterator->
Is_Done(); i++,profileIterator->
Next())
538 accumulated_time += current_total_time;
539 float fraction = parent_time >
SIMD_EPSILON ? (current_total_time / parent_time) * 100 : 0.f;
541 int i;
for (i=0;i<spacing;i++) printf(
".");
543 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());
544 totalTime += current_total_time;
548 if (parent_time < accumulated_time)
552 for (i=0;i<spacing;i++) printf(
".");
553 printf(
"%s (%.3f %%) :: %.3f ms\n",
"Unaccounted:",parent_time >
SIMD_EPSILON ? ((parent_time - accumulated_time) / parent_time) * 100 : 0.f, parent_time - accumulated_time);
555 for (i=0;i<numChildren;i++)
578 #endif //BT_NO_PROFILE
CProfileNode * Get_Sub_Node(const char *name)
static CProfileNode * CurrentNode
CProfileNode * Get_Child(void)
unsigned long long int uint64_t
CProfileIterator(CProfileNode *start)
static void Start_Profile(const char *name)
CProfileNode * CurrentParent
btScalar getTimeSeconds()
Returns the time in s since the last call to reset or since the Clock was created.
LONGLONG mPrevElapsedTime
const char * Get_Current_Name(void)
float Get_Current_Parent_Total_Time(void)
unsigned long int getTimeMicroseconds()
Returns the time in us since the last call to reset or since the Clock was created.
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)
unsigned long int getTimeMilliseconds()
Returns the time in ms since the last call to reset or since the btClock was created.
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
void Profile_Get_Ticks(unsigned long int *ticks)
static void Release_Iterator(CProfileIterator *iterator)
btClock & operator=(const btClock &other)
static btClock gProfileClock
static float Get_Time_Since_Reset(void)
A node in the Profile Hierarchy Tree.
static void Increment_Frame_Counter(void)
CProfileNode * Get_Parent(void)
int Get_Current_Total_Calls(void)
const char * Get_Name(void)
CProfileNode * CurrentChild
unsigned long int StartTime
CProfileNode(const char *name, CProfileNode *parent)
LARGE_INTEGER mClockFrequency
static CProfileIterator * Get_Iterator(void)
static int Get_Frame_Count_Since_Reset(void)
const char * Get_Current_Parent_Name(void)
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...