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 
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]
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;
117  float TotalTime;
118  unsigned long int StartTime;
120 
124  void* m_userPtr;
125 };
126 
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 
159 
160 
161  CProfileIterator( CProfileNode * start );
162  friend class CProfileManager;
163 };
164 
165 
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 
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 
void * GetUserPointer() const
Definition: btQuickprof.h:111
void btSetCustomEnterProfileZoneFunc(btEnterProfileZoneFunc *enterFunc)
void btSetCustomLeaveProfileZoneFunc(btLeaveProfileZoneFunc *leaveFunc)
CProfileNode * Get_Child(void)
Definition: btQuickprof.h:101
void Set_Current_UserPointer(void *ptr)
Definition: btQuickprof.h:147
int Get_Total_Calls(void)
Definition: btQuickprof.h:109
void() btEnterProfileZoneFunc(const char *msg)
Definition: btQuickprof.h:57
int RecursionCounter
Definition: btQuickprof.h:119
CProfileNode * CurrentParent
Definition: btQuickprof.h:157
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:150
unsigned long long int getTimeNanoseconds()
btLeaveProfileZoneFunc * btGetCurrentLeaveProfileZoneFunc()
const char * Get_Current_Name(void)
Definition: btQuickprof.h:142
float Get_Current_Parent_Total_Time(void)
Definition: btQuickprof.h:151
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:144
void reset()
Resets the initial reference time.
An iterator to navigate through the tree.
Definition: btQuickprof.h:128
float TotalTime
Definition: btQuickprof.h:117
CProfileNode * Child
Definition: btQuickprof.h:122
static unsigned long int ResetTime
Definition: btQuickprof.h:196
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()
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:124
CProfileNode * Get_Sibling(void)
Definition: btQuickprof.h:100
struct btClockData * m_data
Definition: btQuickprof.h:52
CProfileNode * Parent
Definition: btQuickprof.h:121
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:112
static void Release_Iterator(CProfileIterator *iterator)
Definition: btQuickprof.h:187
btClock & operator=(const btClock &other)
void * Get_Current_UserPointer(void)
Definition: btQuickprof.h:146
The Manager for the Profile system.
Definition: btQuickprof.h:167
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:91
const char * Name
Definition: btQuickprof.h:115
CProfileNode * Get_Parent(void)
Definition: btQuickprof.h:99
const unsigned int BT_QUICKPROF_MAX_THREAD_COUNT
Definition: btQuickprof.h:75
int Get_Current_Total_Calls(void)
Definition: btQuickprof.h:143
void() btLeaveProfileZoneFunc()
Definition: btQuickprof.h:58
const char * Get_Name(void)
Definition: btQuickprof.h:108
CProfileNode * CurrentChild
Definition: btQuickprof.h:158
unsigned long int StartTime
Definition: btQuickprof.h:118
static int Get_Frame_Count_Since_Reset(void)
Definition: btQuickprof.h:179
float Get_Total_Time(void)
Definition: btQuickprof.h:110
const char * Get_Current_Parent_Name(void)
Definition: btQuickprof.h:149
bool Is_Root(void)
Definition: btQuickprof.h:135
unsigned int btQuickprofGetCurrentThreadIndex2()
static int FrameCounter
Definition: btQuickprof.h:195
CProfileNode * Sibling
Definition: btQuickprof.h:123
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:279