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(); }
147
150 // Access the current parent
151 const char * Get_Current_Parent_Name( void ) { return CurrentParent->Get_Name(); }
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() btLeaveProfileZoneFunc()
Definition: btQuickprof.h:58
void btSetCustomEnterProfileZoneFunc(btEnterProfileZoneFunc *enterFunc)
void btSetCustomLeaveProfileZoneFunc(btLeaveProfileZoneFunc *leaveFunc)
const unsigned int BT_QUICKPROF_MAX_THREAD_COUNT
Definition: btQuickprof.h:77
unsigned int btQuickprofGetCurrentThreadIndex2()
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.
Definition: btQuickprof.h:131
void Enter_Child(int index)
int Get_Current_Parent_Total_Calls(void)
Definition: btQuickprof.h:152
CProfileNode * CurrentChild
Definition: btQuickprof.h:160
void Set_Current_UserPointer(void *ptr)
Definition: btQuickprof.h:149
int Get_Current_Total_Calls(void)
Definition: btQuickprof.h:145
bool Is_Done(void)
void Enter_Largest_Child(void)
const char * Get_Current_Name(void)
Definition: btQuickprof.h:144
void Enter_Parent(void)
float Get_Current_Parent_Total_Time(void)
Definition: btQuickprof.h:153
void * Get_Current_UserPointer(void)
Definition: btQuickprof.h:148
bool Is_Root(void)
Definition: btQuickprof.h:137
void First(void)
const char * Get_Current_Parent_Name(void)
Definition: btQuickprof.h:151
CProfileNode * CurrentParent
Definition: btQuickprof.h:159
float Get_Current_Total_Time(void)
Definition: btQuickprof.h:146
CProfileIterator(CProfileNode *start)
The Manager for the Profile system.
Definition: btQuickprof.h:169
static int FrameCounter
Definition: btQuickprof.h:197
static void dumpAll()
static void Increment_Frame_Counter(void)
static void Release_Iterator(CProfileIterator *iterator)
Definition: btQuickprof.h:189
static float Get_Time_Since_Reset(void)
static CProfileIterator * Get_Iterator(void)
static int Get_Frame_Count_Since_Reset(void)
Definition: btQuickprof.h:181
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
Definition: btQuickprof.h:198
A node in the Profile Hierarchy Tree.
Definition: btQuickprof.h:93
float TotalTime
Definition: btQuickprof.h:119
CProfileNode * Child
Definition: btQuickprof.h:124
void Reset(void)
CProfileNode * Sibling
Definition: btQuickprof.h:125
void * m_userPtr
Definition: btQuickprof.h:126
CProfileNode * Parent
Definition: btQuickprof.h:123
~CProfileNode(void)
const char * Name
Definition: btQuickprof.h:117
CProfileNode * Get_Sub_Node(const char *name)
float Get_Total_Time(void)
Definition: btQuickprof.h:112
CProfileNode * Get_Parent(void)
Definition: btQuickprof.h:101
void * GetUserPointer() const
Definition: btQuickprof.h:113
void Call(void)
void SetUserPointer(void *ptr)
Definition: btQuickprof.h:114
unsigned long int StartTime
Definition: btQuickprof.h:120
CProfileNode(const char *name, CProfileNode *parent)
bool Return(void)
int Get_Total_Calls(void)
Definition: btQuickprof.h:111
void CleanupMemory()
const char * Get_Name(void)
Definition: btQuickprof.h:110
CProfileNode * Get_Child(void)
Definition: btQuickprof.h:103
CProfileNode * Get_Sibling(void)
Definition: btQuickprof.h:102
int RecursionCounter
Definition: btQuickprof.h:121
ProfileSampleClass is a simple way to profile a function's scope Use the BT_PROFILE macro at the star...
Definition: btQuickprof.h:208
CProfileSample(const char *name)
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling.
Definition: btQuickprof.h:25
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.
Definition: btQuickprof.cpp:91
btClock & operator=(const btClock &other)