Bullet Collision Detection & Physics Library
btQuickprof.h
Go to the documentation of this file.
1
2/***************************************************************************************************
3**
4** Real-Time Hierarchical Profiling for Game Programming Gems 3
5**
6** by Greg Hjelstrom & Byon Garrabrant
7**
8***************************************************************************************************/
9
10// Credits: The Clock class was inspired by the Timer classes in
11// Ogre (www.ogre3d.org).
12
13
14
15#ifndef BT_QUICK_PROF_H
16#define BT_QUICK_PROF_H
17
18#include "btScalar.h"
19#define USE_BT_CLOCK 1
20
21#ifdef USE_BT_CLOCK
22
25{
26public:
27 btClock();
28
29 btClock(const btClock& other);
30 btClock& operator=(const btClock& other);
31
32 ~btClock();
33
35 void reset();
36
39 unsigned long long int getTimeMilliseconds();
40
43 unsigned long long int getTimeMicroseconds();
44
45 unsigned long long int getTimeNanoseconds();
46
50
51private:
53};
54
55#endif //USE_BT_CLOCK
56
57typedef void (btEnterProfileZoneFunc)(const char* msg);
58typedef void (btLeaveProfileZoneFunc)();
59
62
63
64
67
68#ifndef BT_NO_PROFILE // FIX redefinition
69//To disable built-in profiling, please comment out next line
70//#define BT_NO_PROFILE 1
71#endif //BT_NO_PROFILE
72
73#ifndef BT_NO_PROFILE
74//btQuickprofGetCurrentThreadIndex will return -1 if thread index cannot be determined,
75//otherwise returns thread index in range [0..maxThreads]
77const unsigned int BT_QUICKPROF_MAX_THREAD_COUNT = 64;
78
79#include <stdio.h>//@todo remove this, backwards compatibility
80
81#include "btAlignedAllocator.h"
82#include <new>
83
84
85
86
87
88
89
90
91
94
95public:
96 CProfileNode( const char * name, CProfileNode * parent );
97 ~CProfileNode( void );
98
99 CProfileNode * Get_Sub_Node( const char * name );
100
101 CProfileNode * Get_Parent( void ) { return Parent; }
102 CProfileNode * Get_Sibling( void ) { return Sibling; }
103 CProfileNode * Get_Child( void ) { return Child; }
104
105 void CleanupMemory();
106 void Reset( void );
107 void Call( void );
108 bool Return( void );
109
110 const char * Get_Name( void ) { return Name; }
111 int Get_Total_Calls( void ) { return TotalCalls; }
112 float Get_Total_Time( void ) { return TotalTime; }
113 void* GetUserPointer() const {return m_userPtr;}
114 void SetUserPointer(void* ptr) { m_userPtr = ptr;}
115protected:
116
117 const char * Name;
120 unsigned long int StartTime;
122
127};
128
131{
132public:
133 // Access all the children of the current parent
134 void First(void);
135 void Next(void);
136 bool Is_Done(void);
137 bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); }
138
139 void Enter_Child( int index ); // Make the given child the new parent
140 void Enter_Largest_Child( void ); // Make the largest child the new parent
141 void Enter_Parent( void ); // Make the current parent's parent the new parent
142
143 // Access the current child
144 const char * Get_Current_Name( void ) { return CurrentChild->Get_Name(); }
145 int Get_Current_Total_Calls( void ) { return CurrentChild->Get_Total_Calls(); }
146 float Get_Current_Total_Time( void ) { return CurrentChild->Get_Total_Time(); }
147
148 void* Get_Current_UserPointer( void ) { return CurrentChild->GetUserPointer(); }
149 void Set_Current_UserPointer(void* ptr) {CurrentChild->SetUserPointer(ptr);}
150 // Access the current parent
151 const char * Get_Current_Parent_Name( void ) { return CurrentParent->Get_Name(); }
152 int Get_Current_Parent_Total_Calls( void ) { return CurrentParent->Get_Total_Calls(); }
153 float Get_Current_Parent_Total_Time( void ) { return CurrentParent->Get_Total_Time(); }
154
155
156
157protected:
158
161
162
164 friend class CProfileManager;
165};
166
167
170public:
171 static void Start_Profile( const char * name );
172 static void Stop_Profile( void );
173
174 static void CleanupMemory(void);
175// {
176// Root.CleanupMemory();
177// }
178
179 static void Reset( void );
180 static void Increment_Frame_Counter( void );
181 static int Get_Frame_Count_Since_Reset( void ) { return FrameCounter; }
182 static float Get_Time_Since_Reset( void );
183
184 static CProfileIterator * Get_Iterator( void );
185// {
186//
187// return new CProfileIterator( &Root );
188// }
189 static void Release_Iterator( CProfileIterator * iterator ) { delete ( iterator); }
190
191 static void dumpRecursive(CProfileIterator* profileIterator, int spacing);
192
193 static void dumpAll();
194
195private:
196
197 static int FrameCounter;
198 static unsigned long int ResetTime;
199};
200
201
202
203
204#endif //#ifndef BT_NO_PROFILE
205
209public:
210 CProfileSample( const char * name );
211
212 ~CProfileSample( void );
213};
214
215#define BT_PROFILE( name ) CProfileSample __profile( name )
216
217
218
219#endif //BT_QUICK_PROF_H
220
221
btEnterProfileZoneFunc * btGetCurrentEnterProfileZoneFunc()
void btSetCustomEnterProfileZoneFunc(btEnterProfileZoneFunc *enterFunc)
void btSetCustomLeaveProfileZoneFunc(btLeaveProfileZoneFunc *leaveFunc)
const unsigned int BT_QUICKPROF_MAX_THREAD_COUNT
Definition btQuickprof.h:77
unsigned int btQuickprofGetCurrentThreadIndex2()
void btLeaveProfileZoneFunc()
Definition btQuickprof.h:58
void btEnterProfileZoneFunc(const char *msg)
Definition btQuickprof.h:57
btLeaveProfileZoneFunc * btGetCurrentLeaveProfileZoneFunc()
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition btScalar.h:292
An iterator to navigate through the tree.
void Enter_Child(int index)
int Get_Current_Parent_Total_Calls(void)
CProfileNode * CurrentChild
void Set_Current_UserPointer(void *ptr)
int Get_Current_Total_Calls(void)
friend class CProfileManager
void Enter_Largest_Child(void)
const char * Get_Current_Name(void)
void Enter_Parent(void)
float Get_Current_Parent_Total_Time(void)
void * Get_Current_UserPointer(void)
bool Is_Root(void)
const char * Get_Current_Parent_Name(void)
CProfileNode * CurrentParent
float Get_Current_Total_Time(void)
CProfileIterator(CProfileNode *start)
The Manager for the Profile system.
static int FrameCounter
static void dumpAll()
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 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.
Definition btQuickprof.h:93
CProfileNode * Child
void Reset(void)
CProfileNode * Sibling
void * m_userPtr
CProfileNode * Parent
const char * Name
CProfileNode * Get_Sub_Node(const char *name)
float Get_Total_Time(void)
CProfileNode * Get_Parent(void)
void * GetUserPointer() const
void Call(void)
void SetUserPointer(void *ptr)
unsigned long int StartTime
CProfileNode(const char *name, CProfileNode *parent)
bool Return(void)
int Get_Total_Calls(void)
void CleanupMemory()
const char * Get_Name(void)
CProfileNode * Get_Child(void)
CProfileNode * Get_Sibling(void)
CProfileSample(const char *name)
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
Definition btQuickprof.h:52
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)