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