Bullet Collision Detection & Physics Library: btQuickprof.h Source File

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
24 class btClock
25 {
26 public:
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
49 btScalar getTimeSeconds();
50
51 private:
52 struct btClockData* m_data;
53 };
54
55 #endif //USE_BT_CLOCK
56
57 typedef void (btEnterProfileZoneFunc)(const char* msg);
58 typedef void (btLeaveProfileZoneFunc)();
59
60 btEnterProfileZoneFunc* btGetCurrentEnterProfileZoneFunc();
61 btLeaveProfileZoneFunc* btGetCurrentLeaveProfileZoneFunc();
62
63
64
65 void btSetCustomEnterProfileZoneFunc(btEnterProfileZoneFunc* enterFunc);
66 void btSetCustomLeaveProfileZoneFunc(btLeaveProfileZoneFunc* leaveFunc);
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]
76 unsigned int btQuickprofGetCurrentThreadIndex2();
77 const 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
93 class CProfileNode {
94
95 public:
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;}
115 protected:
116
117 const char * Name;
118 int TotalCalls;
119 float TotalTime;
120 unsigned long int StartTime;
121 int RecursionCounter;
122
123 CProfileNode * Parent;
124 CProfileNode * Child;
125 CProfileNode * Sibling;
126 void* m_userPtr;
127 };
128
130 class CProfileIterator
131 {
132 public:
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
157 protected:
158
159 CProfileNode * CurrentParent;
160 CProfileNode * CurrentChild;
161
162
163 CProfileIterator( CProfileNode * start );
164 friend class CProfileManager;
165 };
166
167
169 class CProfileManager {
170 public:
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
195 private:
196
197 static int FrameCounter;
198 static unsigned long int ResetTime;
199 };
200
201
202
203
204 #endif //#ifndef BT_NO_PROFILE
205
208 class CProfileSample {
209 public:
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
CProfileNode::Get_Sub_Node
CProfileNode * Get_Sub_Node(const char *name)
Definition: btQuickprof.cpp:353
CProfileNode::GetUserPointer
void * GetUserPointer() const
Definition: btQuickprof.h:113
btSetCustomEnterProfileZoneFunc
void btSetCustomEnterProfileZoneFunc(btEnterProfileZoneFunc *enterFunc)
Definition: btQuickprof.cpp:771
CProfileSample::CProfileSample
CProfileSample(const char *name)
Definition: btQuickprof.cpp:780
btSetCustomLeaveProfileZoneFunc
void btSetCustomLeaveProfileZoneFunc(btLeaveProfileZoneFunc *leaveFunc)
Definition: btQuickprof.cpp:775
CProfileIterator::Next
void Next(void)
Definition: btQuickprof.cpp:428
CProfileNode::Get_Child
CProfileNode * Get_Child(void)
Definition: btQuickprof.h:103
CProfileIterator::Set_Current_UserPointer
void Set_Current_UserPointer(void *ptr)
Definition: btQuickprof.h:149
CProfileManager::Get_Iterator
static CProfileIterator * Get_Iterator(void)
Definition: btQuickprof.cpp:517
CProfileIterator::CProfileIterator
CProfileIterator(CProfileNode *start)
Definition: btQuickprof.cpp:415
CProfileNode::CleanupMemory
void CleanupMemory()
Definition: btQuickprof.cpp:331
CProfileManager::Start_Profile
static void Start_Profile(const char *name)
Definition: btQuickprof.cpp:549
CProfileManager::CleanupMemory
static void CleanupMemory(void)
Definition: btQuickprof.cpp:527
CProfileNode::Get_Total_Calls
int Get_Total_Calls(void)
Definition: btQuickprof.h:111
btEnterProfileZoneFunc
void() btEnterProfileZoneFunc(const char *msg)
Definition: btQuickprof.h:57
CProfileNode::RecursionCounter
int RecursionCounter
Definition: btQuickprof.h:121
CProfileIterator::CurrentParent
CProfileNode * CurrentParent
Definition: btQuickprof.h:159
CProfileManager::dumpAll
static void dumpAll()
Definition: btQuickprof.cpp:673
btClock::getTimeSeconds
btScalar getTimeSeconds()
Returns the time in s since the last call to reset or since the Clock was created.
Definition: btQuickprof.cpp:276
CProfileIterator::First
void First(void)
Definition: btQuickprof.cpp:422
btGetCurrentEnterProfileZoneFunc
btEnterProfileZoneFunc * btGetCurrentEnterProfileZoneFunc()
Definition: btQuickprof.cpp:761
CProfileIterator::Get_Current_Parent_Total_Calls
int Get_Current_Parent_Total_Calls(void)
Definition: btQuickprof.h:152
btClock::getTimeNanoseconds
unsigned long long int getTimeNanoseconds()
Definition: btQuickprof.cpp:212
btGetCurrentLeaveProfileZoneFunc
btLeaveProfileZoneFunc * btGetCurrentLeaveProfileZoneFunc()
Definition: btQuickprof.cpp:765
CProfileIterator::Get_Current_Name
const char * Get_Current_Name(void)
Definition: btQuickprof.h:144
CProfileNode::Return
bool Return(void)
Definition: btQuickprof.cpp:397
CProfileIterator::Get_Current_Parent_Total_Time
float Get_Current_Parent_Total_Time(void)
Definition: btQuickprof.h:153
btClock
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling...
Definition: btQuickprof.h:24
CProfileNode::Reset
void Reset(void)
Definition: btQuickprof.cpp:373
CProfileIterator::Get_Current_Total_Time
float Get_Current_Total_Time(void)
Definition: btQuickprof.h:146
CProfileIterator::Enter_Child
void Enter_Child(int index)
Definition: btQuickprof.cpp:440
btClock::reset
void reset()
Resets the initial reference time.
Definition: btQuickprof.cpp:119
btAlignedAllocator.h
CProfileIterator
An iterator to navigate through the tree.
Definition: btQuickprof.h:130
CProfileNode::TotalTime
float TotalTime
Definition: btQuickprof.h:119
CProfileManager::Stop_Profile
static void Stop_Profile(void)
Definition: btQuickprof.cpp:566
CProfileNode::Child
CProfileNode * Child
Definition: btQuickprof.h:124
CProfileManager::dumpRecursive
static void dumpRecursive(CProfileIterator *profileIterator, int spacing)
Definition: btQuickprof.cpp:624
CProfileManager::ResetTime
static unsigned long int ResetTime
Definition: btQuickprof.h:198
CProfileSample
ProfileSampleClass is a simple way to profile a function&#39;s scope Use the BT_PROFILE macro at the star...
Definition: btQuickprof.h:208
btClock::btClock
btClock()
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling...
Definition: btQuickprof.cpp:91
CProfileNode::m_userPtr
void * m_userPtr
Definition: btQuickprof.h:126
CProfileNode::Get_Sibling
CProfileNode * Get_Sibling(void)
Definition: btQuickprof.h:102
btClock::m_data
struct btClockData * m_data
Definition: btQuickprof.h:52
CProfileIterator::Is_Done
bool Is_Done(void)
Definition: btQuickprof.cpp:434
CProfileNode::Parent
CProfileNode * Parent
Definition: btQuickprof.h:123
btClock::getTimeMicroseconds
unsigned long long int getTimeMicroseconds()
Returns the time in us since the last call to reset or since the Clock was created.
Definition: btQuickprof.cpp:178
CProfileNode::SetUserPointer
void SetUserPointer(void *ptr)
Definition: btQuickprof.h:114
CProfileManager::Release_Iterator
static void Release_Iterator(CProfileIterator *iterator)
Definition: btQuickprof.h:189
btClock::~btClock
~btClock()
Definition: btQuickprof.cpp:100
CProfileManager::Reset
static void Reset(void)
Definition: btQuickprof.cpp:589
CProfileNode::TotalCalls
int TotalCalls
Definition: btQuickprof.h:118
btClock::operator=
btClock & operator=(const btClock &other)
Definition: btQuickprof.cpp:111
CProfileIterator::Get_Current_UserPointer
void * Get_Current_UserPointer(void)
Definition: btQuickprof.h:148
CProfileManager
The Manager for the Profile system.
Definition: btQuickprof.h:169
CProfileManager::Get_Time_Since_Reset
static float Get_Time_Since_Reset(void)
Definition: btQuickprof.cpp:614
btClock::getTimeMilliseconds
unsigned long long int getTimeMilliseconds()
Returns the time in ms since the last call to reset or since the btClock was created.
Definition: btQuickprof.cpp:143
CProfileNode
A node in the Profile Hierarchy Tree.
Definition: btQuickprof.h:93
CProfileNode::Name
const char * Name
Definition: btQuickprof.h:117
CProfileManager::Increment_Frame_Counter
static void Increment_Frame_Counter(void)
Definition: btQuickprof.cpp:605
CProfileNode::Call
void Call(void)
Definition: btQuickprof.cpp:388
CProfileNode::Get_Parent
CProfileNode * Get_Parent(void)
Definition: btQuickprof.h:101
CProfileNode::~CProfileNode
~CProfileNode(void)
Definition: btQuickprof.cpp:339
BT_QUICKPROF_MAX_THREAD_COUNT
const unsigned int BT_QUICKPROF_MAX_THREAD_COUNT
Definition: btQuickprof.h:77
CProfileIterator::Get_Current_Total_Calls
int Get_Current_Total_Calls(void)
Definition: btQuickprof.h:145
btLeaveProfileZoneFunc
void() btLeaveProfileZoneFunc()
Definition: btQuickprof.h:58
btClockData
Definition: btQuickprof.cpp:70
CProfileNode::Get_Name
const char * Get_Name(void)
Definition: btQuickprof.h:110
CProfileIterator::CurrentChild
CProfileNode * CurrentChild
Definition: btQuickprof.h:160
CProfileNode::StartTime
unsigned long int StartTime
Definition: btQuickprof.h:120
CProfileSample::~CProfileSample
~CProfileSample(void)
Definition: btQuickprof.cpp:785
CProfileNode::CProfileNode
CProfileNode(const char *name, CProfileNode *parent)
Definition: btQuickprof.cpp:316
CProfileIterator::Enter_Parent
void Enter_Parent(void)
Definition: btQuickprof.cpp:455
CProfileManager::Get_Frame_Count_Since_Reset
static int Get_Frame_Count_Since_Reset(void)
Definition: btQuickprof.h:181
CProfileNode::Get_Total_Time
float Get_Total_Time(void)
Definition: btQuickprof.h:112
CProfileIterator::Get_Current_Parent_Name
const char * Get_Current_Parent_Name(void)
Definition: btQuickprof.h:151
CProfileIterator::Is_Root
bool Is_Root(void)
Definition: btQuickprof.h:137
btQuickprofGetCurrentThreadIndex2
unsigned int btQuickprofGetCurrentThreadIndex2()
Definition: btQuickprof.cpp:686
CProfileIterator::Enter_Largest_Child
void Enter_Largest_Child(void)
CProfileManager::FrameCounter
static int FrameCounter
Definition: btQuickprof.h:197
CProfileNode::Sibling
CProfileNode * Sibling
Definition: btQuickprof.h:125
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:292
btScalar.h