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

Bullet Collision Detection & Physics Library

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 //To disable built-in profiling, please comment out next line
19 //#define BT_NO_PROFILE 1
20 #ifndef BT_NO_PROFILE
21 #include <stdio.h>//@todo remove this, backwards compatibility
22 #include "btScalar.h"
23 #include "btAlignedAllocator.h"
24 #include <new>
25
26
27
28
29
30 #define USE_BT_CLOCK 1
31
32 #ifdef USE_BT_CLOCK
33
35 class btClock
36 {
37 public:
38 btClock();
39
40 btClock(const btClock& other);
41 btClock& operator=(const btClock& other);
42
43 ~btClock();
44
46 void reset();
47
50 unsigned long int getTimeMilliseconds();
51
54 unsigned long int getTimeMicroseconds();
55
58 btScalar getTimeSeconds();
59
60 private:
61 struct btClockData* m_data;
62 };
63
64 #endif //USE_BT_CLOCK
65
66
67
68
70 class CProfileNode {
71
72 public:
73 CProfileNode( const char * name, CProfileNode * parent );
74 ~CProfileNode( void );
75
76 CProfileNode * Get_Sub_Node( const char * name );
77
78 CProfileNode * Get_Parent( void ) { return Parent; }
79 CProfileNode * Get_Sibling( void ) { return Sibling; }
80 CProfileNode * Get_Child( void ) { return Child; }
81
82 void CleanupMemory();
83 void Reset( void );
84 void Call( void );
85 bool Return( void );
86
87 const char * Get_Name( void ) { return Name; }
88 int Get_Total_Calls( void ) { return TotalCalls; }
89 float Get_Total_Time( void ) { return TotalTime; }
90 void* GetUserPointer() const {return m_userPtr;}
91 void SetUserPointer(void* ptr) { m_userPtr = ptr;}
92 protected:
93
94 const char * Name;
95 int TotalCalls;
96 float TotalTime;
97 unsigned long int StartTime;
98 int RecursionCounter;
99
100 CProfileNode * Parent;
101 CProfileNode * Child;
102 CProfileNode * Sibling;
103 void* m_userPtr;
104 };
105
107 class CProfileIterator
108 {
109 public:
110 // Access all the children of the current parent
111 void First(void);
112 void Next(void);
113 bool Is_Done(void);
114 bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); }
115
116 void Enter_Child( int index ); // Make the given child the new parent
117 void Enter_Largest_Child( void ); // Make the largest child the new parent
118 void Enter_Parent( void ); // Make the current parent's parent the new parent
119
120 // Access the current child
121 const char * Get_Current_Name( void ) { return CurrentChild->Get_Name(); }
122 int Get_Current_Total_Calls( void ) { return CurrentChild->Get_Total_Calls(); }
123 float Get_Current_Total_Time( void ) { return CurrentChild->Get_Total_Time(); }
124
125 void* Get_Current_UserPointer( void ) { return CurrentChild->GetUserPointer(); }
126 void Set_Current_UserPointer(void* ptr) {CurrentChild->SetUserPointer(ptr);}
127 // Access the current parent
128 const char * Get_Current_Parent_Name( void ) { return CurrentParent->Get_Name(); }
129 int Get_Current_Parent_Total_Calls( void ) { return CurrentParent->Get_Total_Calls(); }
130 float Get_Current_Parent_Total_Time( void ) { return CurrentParent->Get_Total_Time(); }
131
132
133
134 protected:
135
136 CProfileNode * CurrentParent;
137 CProfileNode * CurrentChild;
138
139
140 CProfileIterator( CProfileNode * start );
141 friend class CProfileManager;
142 };
143
144
146 class CProfileManager {
147 public:
148 static void Start_Profile( const char * name );
149 static void Stop_Profile( void );
150
151 static void CleanupMemory(void)
152 {
153 Root.CleanupMemory();
154 }
155
156 static void Reset( void );
157 static void Increment_Frame_Counter( void );
158 static int Get_Frame_Count_Since_Reset( void ) { return FrameCounter; }
159 static float Get_Time_Since_Reset( void );
160
161 static CProfileIterator * Get_Iterator( void )
162 {
163
164 return new CProfileIterator( &Root );
165 }
166 static void Release_Iterator( CProfileIterator * iterator ) { delete ( iterator); }
167
168 static void dumpRecursive(CProfileIterator* profileIterator, int spacing);
169
170 static void dumpAll();
171
172 private:
173 static CProfileNode Root;
174 static CProfileNode * CurrentNode;
175 static int FrameCounter;
176 static unsigned long int ResetTime;
177 };
178
179
182 class CProfileSample {
183 public:
184 CProfileSample( const char * name )
185 {
186 CProfileManager::Start_Profile( name );
187 }
188
189 ~CProfileSample( void )
190 {
191 CProfileManager::Stop_Profile();
192 }
193 };
194
195
196 #define BT_PROFILE( name ) CProfileSample __profile( name )
197
198 #else
199
200 #define BT_PROFILE( name )
201
202 #endif //#ifndef BT_NO_PROFILE
203
204
205
206 #endif //BT_QUICK_PROF_H
207
208
CProfileNode::Get_Sub_Node
CProfileNode * Get_Sub_Node(const char *name)
Definition: btQuickprof.cpp:321
CProfileManager::CurrentNode
static CProfileNode * CurrentNode
Definition: btQuickprof.h:174
CProfileSample::CProfileSample
CProfileSample(const char *name)
Definition: btQuickprof.h:184
CProfileIterator::Next
void Next(void)
Definition: btQuickprof.cpp:395
CProfileNode::Get_Child
CProfileNode * Get_Child(void)
Definition: btQuickprof.h:80
CProfileIterator::Set_Current_UserPointer
void Set_Current_UserPointer(void *ptr)
Definition: btQuickprof.h:126
CProfileIterator::CProfileIterator
CProfileIterator(CProfileNode *start)
Definition: btQuickprof.cpp:382
CProfileNode::CleanupMemory
void CleanupMemory()
Definition: btQuickprof.cpp:299
CProfileManager::Start_Profile
static void Start_Profile(const char *name)
Definition: btQuickprof.cpp:456
CProfileNode::Get_Total_Calls
int Get_Total_Calls(void)
Definition: btQuickprof.h:88
CProfileNode::RecursionCounter
int RecursionCounter
Definition: btQuickprof.h:98
CProfileIterator::CurrentParent
CProfileNode * CurrentParent
Definition: btQuickprof.h:136
CProfileManager::dumpAll
static void dumpAll()
Definition: btQuickprof.cpp:565
btClock::getTimeSeconds
btScalar getTimeSeconds()
Returns the time in s since the last call to reset or since the Clock was created.
Definition: btQuickprof.cpp:247
CProfileIterator::First
void First(void)
Definition: btQuickprof.cpp:389
CProfileIterator::Get_Current_Parent_Total_Calls
int Get_Current_Parent_Total_Calls(void)
Definition: btQuickprof.h:129
CProfileIterator::Get_Current_Name
const char * Get_Current_Name(void)
Definition: btQuickprof.h:121
CProfileNode::Return
bool Return(void)
Definition: btQuickprof.cpp:365
CProfileIterator::Get_Current_Parent_Total_Time
float Get_Current_Parent_Total_Time(void)
Definition: btQuickprof.h:130
btClock::getTimeMicroseconds
unsigned long int getTimeMicroseconds()
Returns the time in us since the last call to reset or since the Clock was created.
Definition: btQuickprof.cpp:187
btClock
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling...
Definition: btQuickprof.h:35
CProfileNode::Reset
void Reset(void)
Definition: btQuickprof.cpp:341
CProfileIterator::Get_Current_Total_Time
float Get_Current_Total_Time(void)
Definition: btQuickprof.h:123
CProfileIterator::Enter_Child
void Enter_Child(int index)
Definition: btQuickprof.cpp:407
btClock::reset
void reset()
Resets the initial reference time.
Definition: btQuickprof.cpp:109
btAlignedAllocator.h
CProfileIterator
An iterator to navigate through the tree.
Definition: btQuickprof.h:107
CProfileNode::TotalTime
float TotalTime
Definition: btQuickprof.h:96
CProfileManager::Stop_Profile
static void Stop_Profile(void)
Definition: btQuickprof.cpp:469
CProfileNode::Child
CProfileNode * Child
Definition: btQuickprof.h:101
btClock::getTimeMilliseconds
unsigned long int getTimeMilliseconds()
Returns the time in ms since the last call to reset or since the btClock was created.
Definition: btQuickprof.cpp:131
CProfileManager::dumpRecursive
static void dumpRecursive(CProfileIterator *profileIterator, int spacing)
Definition: btQuickprof.cpp:516
CProfileManager::ResetTime
static unsigned long int ResetTime
Definition: btQuickprof.h:176
CProfileManager::CleanupMemory
static void CleanupMemory(void)
Definition: btQuickprof.h:151
CProfileSample
ProfileSampleClass is a simple way to profile a function's scope Use the BT_PROFILE macro at the star...
Definition: btQuickprof.h:182
btClock::btClock
btClock()
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling...
Definition: btQuickprof.cpp:81
CProfileNode::m_userPtr
void * m_userPtr
Definition: btQuickprof.h:103
CProfileNode::Get_Sibling
CProfileNode * Get_Sibling(void)
Definition: btQuickprof.h:79
btClock::m_data
struct btClockData * m_data
Definition: btQuickprof.h:61
CProfileIterator::Is_Done
bool Is_Done(void)
Definition: btQuickprof.cpp:401
CProfileNode::Parent
CProfileNode * Parent
Definition: btQuickprof.h:100
CProfileNode::SetUserPointer
void SetUserPointer(void *ptr)
Definition: btQuickprof.h:91
CProfileManager::Release_Iterator
static void Release_Iterator(CProfileIterator *iterator)
Definition: btQuickprof.h:166
btClock::~btClock
~btClock()
Definition: btQuickprof.cpp:90
CProfileManager::Reset
static void Reset(void)
Definition: btQuickprof.cpp:484
CProfileNode::TotalCalls
int TotalCalls
Definition: btQuickprof.h:95
btClock::operator=
btClock & operator=(const btClock &other)
Definition: btQuickprof.cpp:101
CProfileIterator::Get_Current_UserPointer
void * Get_Current_UserPointer(void)
Definition: btQuickprof.h:125
CProfileManager
The Manager for the Profile system.
Definition: btQuickprof.h:146
CProfileManager::Get_Time_Since_Reset
static float Get_Time_Since_Reset(void)
Definition: btQuickprof.cpp:506
CProfileNode
A node in the Profile Hierarchy Tree.
Definition: btQuickprof.h:70
CProfileNode::Name
const char * Name
Definition: btQuickprof.h:94
CProfileManager::Increment_Frame_Counter
static void Increment_Frame_Counter(void)
Definition: btQuickprof.cpp:497
CProfileNode::Call
void Call(void)
Definition: btQuickprof.cpp:356
CProfileNode::Get_Parent
CProfileNode * Get_Parent(void)
Definition: btQuickprof.h:78
CProfileNode::~CProfileNode
~CProfileNode(void)
Definition: btQuickprof.cpp:307
CProfileIterator::Get_Current_Total_Calls
int Get_Current_Total_Calls(void)
Definition: btQuickprof.h:122
btClockData
Definition: btQuickprof.cpp:62
CProfileNode::Get_Name
const char * Get_Name(void)
Definition: btQuickprof.h:87
CProfileIterator::CurrentChild
CProfileNode * CurrentChild
Definition: btQuickprof.h:137
CProfileNode::StartTime
unsigned long int StartTime
Definition: btQuickprof.h:97
CProfileSample::~CProfileSample
~CProfileSample(void)
Definition: btQuickprof.h:189
CProfileNode::CProfileNode
CProfileNode(const char *name, CProfileNode *parent)
Definition: btQuickprof.cpp:284
CProfileManager::Root
static CProfileNode Root
Definition: btQuickprof.h:173
CProfileManager::Get_Iterator
static CProfileIterator * Get_Iterator(void)
Definition: btQuickprof.h:161
CProfileIterator::Enter_Parent
void Enter_Parent(void)
Definition: btQuickprof.cpp:422
CProfileManager::Get_Frame_Count_Since_Reset
static int Get_Frame_Count_Since_Reset(void)
Definition: btQuickprof.h:158
CProfileNode::Get_Total_Time
float Get_Total_Time(void)
Definition: btQuickprof.h:89
CProfileIterator::Get_Current_Parent_Name
const char * Get_Current_Parent_Name(void)
Definition: btQuickprof.h:128
CProfileNode::GetUserPointer
void * GetUserPointer() const
Definition: btQuickprof.h:90
CProfileIterator::Is_Root
bool Is_Root(void)
Definition: btQuickprof.h:114
CProfileIterator::Enter_Largest_Child
void Enter_Largest_Child(void)
CProfileManager::FrameCounter
static int FrameCounter
Definition: btQuickprof.h:175
CProfileNode::Sibling
CProfileNode * Sibling
Definition: btQuickprof.h:102
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:278
btScalar.h