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 //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 private:
57 };
58 
59 #endif //USE_BT_CLOCK
60 
61 
62 
63 
65 class CProfileNode {
66 
67 public:
68  CProfileNode( const char * name, CProfileNode * parent );
69  ~CProfileNode( void );
70 
71  CProfileNode * Get_Sub_Node( const char * name );
72 
73  CProfileNode * Get_Parent( void ) { return Parent; }
74  CProfileNode * Get_Sibling( void ) { return Sibling; }
75  CProfileNode * Get_Child( void ) { return Child; }
76 
77  void CleanupMemory();
78  void Reset( void );
79  void Call( void );
80  bool Return( void );
81 
82  const char * Get_Name( void ) { return Name; }
83  int Get_Total_Calls( void ) { return TotalCalls; }
84  float Get_Total_Time( void ) { return TotalTime; }
85  void* GetUserPointer() const {return m_userPtr;}
86  void SetUserPointer(void* ptr) { m_userPtr = ptr;}
87 protected:
88 
89  const char * Name;
91  float TotalTime;
92  unsigned long int StartTime;
94 
98  void* m_userPtr;
99 };
100 
103 {
104 public:
105  // Access all the children of the current parent
106  void First(void);
107  void Next(void);
108  bool Is_Done(void);
109  bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); }
110 
111  void Enter_Child( int index ); // Make the given child the new parent
112  void Enter_Largest_Child( void ); // Make the largest child the new parent
113  void Enter_Parent( void ); // Make the current parent's parent the new parent
114 
115  // Access the current child
116  const char * Get_Current_Name( void ) { return CurrentChild->Get_Name(); }
119 
122  // Access the current parent
123  const char * Get_Current_Parent_Name( void ) { return CurrentParent->Get_Name(); }
126 
127 
128 
129 protected:
130 
133 
134 
135  CProfileIterator( CProfileNode * start );
136  friend class CProfileManager;
137 };
138 
139 
142 public:
143  static void Start_Profile( const char * name );
144  static void Stop_Profile( void );
145 
146  static void CleanupMemory(void)
147  {
149  }
150 
151  static void Reset( void );
152  static void Increment_Frame_Counter( void );
153  static int Get_Frame_Count_Since_Reset( void ) { return FrameCounter; }
154  static float Get_Time_Since_Reset( void );
155 
156  static CProfileIterator * Get_Iterator( void )
157  {
158 
159  return new CProfileIterator( &Root );
160  }
161  static void Release_Iterator( CProfileIterator * iterator ) { delete ( iterator); }
162 
163  static void dumpRecursive(CProfileIterator* profileIterator, int spacing);
164 
165  static void dumpAll();
166 
167 private:
170  static int FrameCounter;
171  static unsigned long int ResetTime;
172 };
173 
174 
178 public:
179  CProfileSample( const char * name )
180  {
182  }
183 
185  {
187  }
188 };
189 
190 
191 #define BT_PROFILE( name ) CProfileSample __profile( name )
192 
193 #else
194 
195 #define BT_PROFILE( name )
196 
197 #endif //#ifndef BT_NO_PROFILE
198 
199 
200 
201 #endif //BT_QUICK_PROF_H
202 
203 
CProfileNode * Get_Sub_Node(const char *name)
static CProfileNode * CurrentNode
Definition: btQuickprof.h:169
CProfileSample(const char *name)
Definition: btQuickprof.h:179
CProfileNode * Get_Child(void)
Definition: btQuickprof.h:75
void Set_Current_UserPointer(void *ptr)
Definition: btQuickprof.h:121
CProfileIterator(CProfileNode *start)
void CleanupMemory()
static void Start_Profile(const char *name)
int Get_Total_Calls(void)
Definition: btQuickprof.h:83
int RecursionCounter
Definition: btQuickprof.h:93
CProfileNode * CurrentParent
Definition: btQuickprof.h:131
static void dumpAll()
void First(void)
int Get_Current_Parent_Total_Calls(void)
Definition: btQuickprof.h:124
const char * Get_Current_Name(void)
Definition: btQuickprof.h:116
bool Return(void)
float Get_Current_Parent_Total_Time(void)
Definition: btQuickprof.h:125
unsigned long int getTimeMicroseconds()
Returns the time in us since the last call to reset or since the Clock was created.
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling...
Definition: btQuickprof.h:35
void Reset(void)
float Get_Current_Total_Time(void)
Definition: btQuickprof.h:118
void Enter_Child(int index)
void reset()
Resets the initial reference time.
An iterator to navigate through the tree.
Definition: btQuickprof.h:102
float TotalTime
Definition: btQuickprof.h:91
static void Stop_Profile(void)
CProfileNode * Child
Definition: btQuickprof.h:96
unsigned long int getTimeMilliseconds()
Returns the time in ms since the last call to reset or since the btClock was created.
static void dumpRecursive(CProfileIterator *profileIterator, int spacing)
static unsigned long int ResetTime
Definition: btQuickprof.h:171
static void CleanupMemory(void)
Definition: btQuickprof.h:146
ProfileSampleClass is a simple way to profile a function's scope Use the BT_PROFILE macro at the star...
Definition: btQuickprof.h:177
btClock()
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling...
Definition: btQuickprof.cpp:76
void * m_userPtr
Definition: btQuickprof.h:98
CProfileNode * Get_Sibling(void)
Definition: btQuickprof.h:74
struct btClockData * m_data
Definition: btQuickprof.h:56
bool Is_Done(void)
CProfileNode * Parent
Definition: btQuickprof.h:95
void SetUserPointer(void *ptr)
Definition: btQuickprof.h:86
static void Release_Iterator(CProfileIterator *iterator)
Definition: btQuickprof.h:161
static void Reset(void)
btClock & operator=(const btClock &other)
Definition: btQuickprof.cpp:96
void * Get_Current_UserPointer(void)
Definition: btQuickprof.h:120
The Manager for the Profile system.
Definition: btQuickprof.h:141
static float Get_Time_Since_Reset(void)
A node in the Profile Hierarchy Tree.
Definition: btQuickprof.h:65
const char * Name
Definition: btQuickprof.h:89
static void Increment_Frame_Counter(void)
void Call(void)
CProfileNode * Get_Parent(void)
Definition: btQuickprof.h:73
~CProfileNode(void)
int Get_Current_Total_Calls(void)
Definition: btQuickprof.h:117
const char * Get_Name(void)
Definition: btQuickprof.h:82
CProfileNode * CurrentChild
Definition: btQuickprof.h:132
unsigned long int StartTime
Definition: btQuickprof.h:92
~CProfileSample(void)
Definition: btQuickprof.h:184
CProfileNode(const char *name, CProfileNode *parent)
static CProfileNode Root
Definition: btQuickprof.h:168
static CProfileIterator * Get_Iterator(void)
Definition: btQuickprof.h:156
void Enter_Parent(void)
static int Get_Frame_Count_Since_Reset(void)
Definition: btQuickprof.h:153
float Get_Total_Time(void)
Definition: btQuickprof.h:84
const char * Get_Current_Parent_Name(void)
Definition: btQuickprof.h:123
void * GetUserPointer() const
Definition: btQuickprof.h:85
bool Is_Root(void)
Definition: btQuickprof.h:109
void Enter_Largest_Child(void)
static int FrameCounter
Definition: btQuickprof.h:170
CProfileNode * Sibling
Definition: btQuickprof.h:97