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
69 //To disable built-in profiling, please comment out next line
70 //#define BT_NO_PROFILE 1
71 #ifndef BT_NO_PROFILE
72 //btQuickprofGetCurrentThreadIndex will return -1 if thread index cannot be determined,
73 //otherwise returns thread index in range [0..maxThreads]
74 unsigned int btQuickprofGetCurrentThreadIndex2();
75 const unsigned int BT_QUICKPROF_MAX_THREAD_COUNT = 64;
76
77 #include <stdio.h>//@todo remove this, backwards compatibility
78
79 #include "btAlignedAllocator.h"
80 #include <new>
81
82
83
84
85
86
87
88
89
91 class CProfileNode {
92
93 public:
94 CProfileNode( const char * name, CProfileNode * parent );
95 ~CProfileNode( void );
96
97 CProfileNode * Get_Sub_Node( const char * name );
98
99 CProfileNode * Get_Parent( void ) { return Parent; }
100 CProfileNode * Get_Sibling( void ) { return Sibling; }
101 CProfileNode * Get_Child( void ) { return Child; }
102
103 void CleanupMemory();
104 void Reset( void );
105 void Call( void );
106 bool Return( void );
107
108 const char * Get_Name( void ) { return Name; }
109 int Get_Total_Calls( void ) { return TotalCalls; }
110 float Get_Total_Time( void ) { return TotalTime; }
111 void* GetUserPointer() const {return m_userPtr;}
112 void SetUserPointer(void* ptr) { m_userPtr = ptr;}
113 protected:
114
115 const char * Name;
116 int TotalCalls;
117 float TotalTime;
118 unsigned long int StartTime;
119 int RecursionCounter;
120
121 CProfileNode * Parent;
122 CProfileNode * Child;
123 CProfileNode * Sibling;
124 void* m_userPtr;
125 };
126
128 class CProfileIterator
129 {
130 public:
131 // Access all the children of the current parent
132 void First(void);
133 void Next(void);
134 bool Is_Done(void);
135 bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); }
136
137 void Enter_Child( int index ); // Make the given child the new parent
138 void Enter_Largest_Child( void ); // Make the largest child the new parent
139 void Enter_Parent( void ); // Make the current parent's parent the new parent
140
141 // Access the current child
142 const char * Get_Current_Name( void ) { return CurrentChild->Get_Name(); }
143 int Get_Current_Total_Calls( void ) { return CurrentChild->Get_Total_Calls(); }
144 float Get_Current_Total_Time( void ) { return CurrentChild->Get_Total_Time(); }
145
146 void* Get_Current_UserPointer( void ) { return CurrentChild->GetUserPointer(); }
147 void Set_Current_UserPointer(void* ptr) {CurrentChild->SetUserPointer(ptr);}
148 // Access the current parent
149 const char * Get_Current_Parent_Name( void ) { return CurrentParent->Get_Name(); }
150 int Get_Current_Parent_Total_Calls( void ) { return CurrentParent->Get_Total_Calls(); }
151 float Get_Current_Parent_Total_Time( void ) { return CurrentParent->Get_Total_Time(); }
152
153
154
155 protected:
156
157 CProfileNode * CurrentParent;
158 CProfileNode * CurrentChild;
159
160
161 CProfileIterator( CProfileNode * start );
162 friend class CProfileManager;
163 };
164
165
167 class CProfileManager {
168 public:
169 static void Start_Profile( const char * name );
170 static void Stop_Profile( void );
171
172 static void CleanupMemory(void);
173 // {
174 // Root.CleanupMemory();
175 // }
176
177 static void Reset( void );
178 static void Increment_Frame_Counter( void );
179 static int Get_Frame_Count_Since_Reset( void ) { return FrameCounter; }
180 static float Get_Time_Since_Reset( void );
181
182 static CProfileIterator * Get_Iterator( void );
183 // {
184 //
185 // return new CProfileIterator( &Root );
186 // }
187 static void Release_Iterator( CProfileIterator * iterator ) { delete ( iterator); }
188
189 static void dumpRecursive(CProfileIterator* profileIterator, int spacing);
190
191 static void dumpAll();
192
193 private:
194
195 static int FrameCounter;
196 static unsigned long int ResetTime;
197 };
198
199
200
201
202 #endif //#ifndef BT_NO_PROFILE
203
206 class CProfileSample {
207 public:
208 CProfileSample( const char * name );
209
210 ~CProfileSample( void );
211 };
212
213 #define BT_PROFILE( name ) CProfileSample __profile( name )
214
215
216
217 #endif //BT_QUICK_PROF_H
218
219
CProfileNode::GetUserPointer
void * GetUserPointer() const
Definition: btQuickprof.h:111
btSetCustomEnterProfileZoneFunc
void btSetCustomEnterProfileZoneFunc(btEnterProfileZoneFunc *enterFunc)
Definition: btQuickprof.cpp:763
btSetCustomLeaveProfileZoneFunc
void btSetCustomLeaveProfileZoneFunc(btLeaveProfileZoneFunc *leaveFunc)
Definition: btQuickprof.cpp:767
CProfileNode::Get_Child
CProfileNode * Get_Child(void)
Definition: btQuickprof.h:101
CProfileIterator::Set_Current_UserPointer
void Set_Current_UserPointer(void *ptr)
Definition: btQuickprof.h:147
CProfileNode::Get_Total_Calls
int Get_Total_Calls(void)
Definition: btQuickprof.h:109
CProfileNode::RecursionCounter
int RecursionCounter
Definition: btQuickprof.h:119
CProfileIterator::CurrentParent
CProfileNode * CurrentParent
Definition: btQuickprof.h:157
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
btGetCurrentEnterProfileZoneFunc
btEnterProfileZoneFunc * btGetCurrentEnterProfileZoneFunc()
Definition: btQuickprof.cpp:753
CProfileIterator::Get_Current_Parent_Total_Calls
int Get_Current_Parent_Total_Calls(void)
Definition: btQuickprof.h:150
btClock::getTimeNanoseconds
unsigned long long int getTimeNanoseconds()
Definition: btQuickprof.cpp:212
btGetCurrentLeaveProfileZoneFunc
btLeaveProfileZoneFunc * btGetCurrentLeaveProfileZoneFunc()
Definition: btQuickprof.cpp:757
CProfileIterator::Get_Current_Name
const char * Get_Current_Name(void)
Definition: btQuickprof.h:142
CProfileIterator::Get_Current_Parent_Total_Time
float Get_Current_Parent_Total_Time(void)
Definition: btQuickprof.h:151
btClock
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling...
Definition: btQuickprof.h:24
CProfileIterator::Get_Current_Total_Time
float Get_Current_Total_Time(void)
Definition: btQuickprof.h:144
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:128
CProfileNode::TotalTime
float TotalTime
Definition: btQuickprof.h:117
CProfileNode::Child
CProfileNode * Child
Definition: btQuickprof.h:122
CProfileManager::ResetTime
static unsigned long int ResetTime
Definition: btQuickprof.h:196
CProfileSample
ProfileSampleClass is a simple way to profile a function&#39;s scope Use the BT_PROFILE macro at the star...
Definition: btQuickprof.h:206
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:124
CProfileNode::Get_Sibling
CProfileNode * Get_Sibling(void)
Definition: btQuickprof.h:100
btClock::m_data
struct btClockData * m_data
Definition: btQuickprof.h:52
CProfileNode::Parent
CProfileNode * Parent
Definition: btQuickprof.h:121
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:112
CProfileManager::Release_Iterator
static void Release_Iterator(CProfileIterator *iterator)
Definition: btQuickprof.h:187
btClock::~btClock
~btClock()
Definition: btQuickprof.cpp:100
CProfileNode::TotalCalls
int TotalCalls
Definition: btQuickprof.h:116
btClock::operator=
btClock & operator=(const btClock &other)
Definition: btQuickprof.cpp:111
CProfileIterator::Get_Current_UserPointer
void * Get_Current_UserPointer(void)
Definition: btQuickprof.h:146
btLeaveProfileZoneFunc
void( btLeaveProfileZoneFunc)()
Definition: btQuickprof.h:58
CProfileManager
The Manager for the Profile system.
Definition: btQuickprof.h:167
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:91
CProfileNode::Name
const char * Name
Definition: btQuickprof.h:115
CProfileNode::Get_Parent
CProfileNode * Get_Parent(void)
Definition: btQuickprof.h:99
BT_QUICKPROF_MAX_THREAD_COUNT
const unsigned int BT_QUICKPROF_MAX_THREAD_COUNT
Definition: btQuickprof.h:75
CProfileIterator::Get_Current_Total_Calls
int Get_Current_Total_Calls(void)
Definition: btQuickprof.h:143
btClockData
Definition: btQuickprof.cpp:70
CProfileNode::Get_Name
const char * Get_Name(void)
Definition: btQuickprof.h:108
CProfileIterator::CurrentChild
CProfileNode * CurrentChild
Definition: btQuickprof.h:158
CProfileNode::StartTime
unsigned long int StartTime
Definition: btQuickprof.h:118
CProfileManager::Get_Frame_Count_Since_Reset
static int Get_Frame_Count_Since_Reset(void)
Definition: btQuickprof.h:179
CProfileNode::Get_Total_Time
float Get_Total_Time(void)
Definition: btQuickprof.h:110
btEnterProfileZoneFunc
void( btEnterProfileZoneFunc)(const char *msg)
Definition: btQuickprof.h:57
CProfileIterator::Get_Current_Parent_Name
const char * Get_Current_Parent_Name(void)
Definition: btQuickprof.h:149
CProfileIterator::Is_Root
bool Is_Root(void)
Definition: btQuickprof.h:135
btQuickprofGetCurrentThreadIndex2
unsigned int btQuickprofGetCurrentThreadIndex2()
Definition: btQuickprof.cpp:686
CProfileManager::FrameCounter
static int FrameCounter
Definition: btQuickprof.h:195
CProfileNode::Sibling
CProfileNode * Sibling
Definition: btQuickprof.h:123
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:279
btScalar.h