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#ifndef BT_QUICK_PROF_H
14#define BT_QUICK_PROF_H
15
16#include "btScalar.h"
17#define USE_BT_CLOCK 1
18
19#ifdef USE_BT_CLOCK
20
22 class btClock
23{
24public:
25 btClock();
26
27 btClock(const btClock& other);
28 btClock& operator=(const btClock& other);
29
30 ~btClock();
31
33 void reset();
34
37 unsigned long long int getTimeMilliseconds();
38
41 unsigned long long int getTimeMicroseconds();
42
43 unsigned long long int getTimeNanoseconds();
44
47 btScalar getTimeSeconds();
48
49private:
50 struct btClockData* m_data;
51};
52
53#endif //USE_BT_CLOCK
54
55 typedef void(btEnterProfileZoneFunc)(const char* msg);
56 typedef void(btLeaveProfileZoneFunc)();
57
58 btEnterProfileZoneFunc* btGetCurrentEnterProfileZoneFunc();
59 btLeaveProfileZoneFunc* btGetCurrentLeaveProfileZoneFunc();
60
61void btSetCustomEnterProfileZoneFunc(btEnterProfileZoneFunc* enterFunc);
62void btSetCustomLeaveProfileZoneFunc(btLeaveProfileZoneFunc* leaveFunc);
63
64#ifndef BT_ENABLE_PROFILE
65#define BT_NO_PROFILE 1
66#endif //BT_NO_PROFILE
67
68 const unsigned int BT_QUICKPROF_MAX_THREAD_COUNT = 64;
69
70//btQuickprofGetCurrentThreadIndex will return -1 if thread index cannot be determined,
71//otherwise returns thread index in range [0..maxThreads]
72unsigned int btQuickprofGetCurrentThreadIndex2();
73
74#ifndef BT_NO_PROFILE
75
76
77#include <stdio.h> //@todo remove this, backwards compatibility
78
79#include "btAlignedAllocator.h"
80#include <new>
81
83class CProfileNode
84{
85public:
86 CProfileNode(const char* name, CProfileNode* parent);
87 ~CProfileNode(void);
88
89 CProfileNode* Get_Sub_Node(const char* name);
90
91 CProfileNode* Get_Parent(void) { return Parent; }
92 CProfileNode* Get_Sibling(void) { return Sibling; }
93 CProfileNode* Get_Child(void) { return Child; }
94
95 void CleanupMemory();
96 void Reset(void);
97 void Call(void);
98 bool Return(void);
99
100 const char* Get_Name(void) { return Name; }
101 int Get_Total_Calls(void) { return TotalCalls; }
102 float Get_Total_Time(void) { return TotalTime; }
103 void* GetUserPointer() const { return m_userPtr; }
104 void SetUserPointer(void* ptr) { m_userPtr = ptr; }
105
106protected:
107 const char* Name;
108 int TotalCalls;
109 float TotalTime;
110 unsigned long int StartTime;
111 int RecursionCounter;
112
113 CProfileNode* Parent;
114 CProfileNode* Child;
115 CProfileNode* Sibling;
116 void* m_userPtr;
117};
118
120class CProfileIterator
121{
122public:
123 // Access all the children of the current parent
124 void First(void);
125 void Next(void);
126 bool Is_Done(void);
127 bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); }
128
129 void Enter_Child(int index); // Make the given child the new parent
130 void Enter_Largest_Child(void); // Make the largest child the new parent
131 void Enter_Parent(void); // Make the current parent's parent the new parent
132
133 // Access the current child
134 const char* Get_Current_Name(void) { return CurrentChild->Get_Name(); }
135 int Get_Current_Total_Calls(void) { return CurrentChild->Get_Total_Calls(); }
136 float Get_Current_Total_Time(void) { return CurrentChild->Get_Total_Time(); }
137
138 void* Get_Current_UserPointer(void) { return CurrentChild->GetUserPointer(); }
139 void Set_Current_UserPointer(void* ptr) { CurrentChild->SetUserPointer(ptr); }
140 // Access the current parent
141 const char* Get_Current_Parent_Name(void) { return CurrentParent->Get_Name(); }
142 int Get_Current_Parent_Total_Calls(void) { return CurrentParent->Get_Total_Calls(); }
143 float Get_Current_Parent_Total_Time(void) { return CurrentParent->Get_Total_Time(); }
144
145protected:
146 CProfileNode* CurrentParent;
147 CProfileNode* CurrentChild;
148
149 CProfileIterator(CProfileNode* start);
150 friend class CProfileManager;
151};
152
154class CProfileManager
155{
156public:
157 static void Start_Profile(const char* name);
158 static void Stop_Profile(void);
159
160 static void CleanupMemory(void);
161 // {
162 // Root.CleanupMemory();
163 // }
164
165 static void Reset(void);
166 static void Increment_Frame_Counter(void);
167 static int Get_Frame_Count_Since_Reset(void) { return FrameCounter; }
168 static float Get_Time_Since_Reset(void);
169
170 static CProfileIterator* Get_Iterator(void);
171 // {
172 //
173 // return new CProfileIterator( &Root );
174 // }
175 static void Release_Iterator(CProfileIterator* iterator) { delete (iterator); }
176
177 static void dumpRecursive(CProfileIterator* profileIterator, int spacing);
178
179 static void dumpAll();
180
181private:
182 static int FrameCounter;
183 static unsigned long int ResetTime;
184};
185
186#endif //#ifndef BT_NO_PROFILE
187
190 class CProfileSample
191{
192public:
193 CProfileSample(const char* name);
194
195 ~CProfileSample(void);
196};
197
198#define BT_PROFILE(name) CProfileSample __profile(name)
199
200#endif //BT_QUICK_PROF_H
btAlignedAllocator.h
btGetCurrentEnterProfileZoneFunc
btEnterProfileZoneFunc * btGetCurrentEnterProfileZoneFunc()
Definition: btQuickprof.cpp:779
btLeaveProfileZoneFunc
void() btLeaveProfileZoneFunc()
Definition: btQuickprof.h:56
btSetCustomEnterProfileZoneFunc
void btSetCustomEnterProfileZoneFunc(btEnterProfileZoneFunc *enterFunc)
Definition: btQuickprof.cpp:788
btSetCustomLeaveProfileZoneFunc
void btSetCustomLeaveProfileZoneFunc(btLeaveProfileZoneFunc *leaveFunc)
Definition: btQuickprof.cpp:792
BT_QUICKPROF_MAX_THREAD_COUNT
const unsigned int BT_QUICKPROF_MAX_THREAD_COUNT
Definition: btQuickprof.h:68
btQuickprofGetCurrentThreadIndex2
unsigned int btQuickprofGetCurrentThreadIndex2()
Definition: btQuickprof.cpp:741
btEnterProfileZoneFunc
void() btEnterProfileZoneFunc(const char *msg)
Definition: btQuickprof.h:55
btGetCurrentLeaveProfileZoneFunc
btLeaveProfileZoneFunc * btGetCurrentLeaveProfileZoneFunc()
Definition: btQuickprof.cpp:783
btScalar.h
btScalar
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:314
CProfileSample
ProfileSampleClass is a simple way to profile a function's scope Use the BT_PROFILE macro at the star...
Definition: btQuickprof.h:191
CProfileSample::~CProfileSample
~CProfileSample(void)
Definition: btQuickprof.cpp:802
btClock
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling.
Definition: btQuickprof.h:23
btClock::getTimeSeconds
btScalar getTimeSeconds()
Returns the time in s since the last call to reset or since the Clock was created.
Definition: btQuickprof.cpp:267
btClock::getTimeNanoseconds
unsigned long long int getTimeNanoseconds()
Definition: btQuickprof.cpp:205
btClock::reset
void reset()
Resets the initial reference time.
Definition: btQuickprof.cpp:112
btClock::m_data
struct btClockData * m_data
Definition: btQuickprof.h:50
btClock::~btClock
~btClock()
Definition: btQuickprof.cpp:94
btClock::getTimeMilliseconds
unsigned long long int getTimeMilliseconds()
Returns the time in ms since the last call to reset or since the btClock was created.
Definition: btQuickprof.cpp:136
btClock::getTimeMicroseconds
unsigned long long int getTimeMicroseconds()
Returns the time in us since the last call to reset or since the Clock was created.
Definition: btQuickprof.cpp:171
btClock::btClock
btClock()
The btClock is a portable basic clock that measures accurate time in seconds, use for profiling.
Definition: btQuickprof.cpp:85
btClock::operator=
btClock & operator=(const btClock &other)
Definition: btQuickprof.cpp:105
btClockData
Definition: btQuickprof.cpp:67