Skyscraper 2.0
profiler.h
Go to the documentation of this file.
1#ifndef _SBS_PROFILER_H
2#define _SBS_PROFILER_H
3
4namespace SBS {
5
6#define ENABLE_PROFILING
7
8/***************************************************************************************************
9**
10** Real-Time Hierarchical Profiling for Game Programming Gems 3
11**
12** by Greg Hjelstrom & Byon Garrabrant
13**
14***************************************************************************************************/
15
18
19public:
20 ProfileNode( const char * name, ProfileNode * parent );
21 ~ProfileNode( void );
22
23 ProfileNode * Get_Sub_Node( const char * name );
24
25 ProfileNode * Get_Parent( void ) { return Parent; }
26 ProfileNode * Get_Sibling( void ) { return Sibling; }
27 ProfileNode * Get_Child( void ) { return Child; }
28
29 void CleanupMemory();
30 void Reset( void );
31 void Call( void );
32 bool Return( void );
33
34 const char * Get_Name( void ) { return Name; }
35 int Get_Total_Calls( void ) { return TotalCalls; }
36 float Get_Total_Time( void ) { return TotalTime; }
37
38protected:
39
40 const char * Name;
42 float TotalTime;
43 unsigned long int StartTime;
45
49};
50
53{
54public:
55 // Access all the children of the current parent
56 void First(void);
57 void Next(void);
58 bool Is_Done(void);
59 bool Is_Root(void) { return (CurrentParent->Get_Parent() == 0); }
60
61 void Enter_Child( int index ); // Make the given child the new parent
62 void Enter_Largest_Child( void ); // Make the largest child the new parent
63 void Enter_Parent( void ); // Make the current parent's parent the new parent
64
65 // Access the current child
66 const char * Get_Current_Name( void ) { return CurrentChild->Get_Name(); }
67 int Get_Current_Total_Calls( void ) { return CurrentChild->Get_Total_Calls(); }
68 float Get_Current_Total_Time( void ) { return CurrentChild->Get_Total_Time(); }
69
70 // Access the current parent
71 const char * Get_Current_Parent_Name( void ) { return CurrentParent->Get_Name(); }
72 int Get_Current_Parent_Total_Calls( void ) { return CurrentParent->Get_Total_Calls(); }
73 float Get_Current_Parent_Total_Time( void ) { return CurrentParent->Get_Total_Time(); }
74
75protected:
76
79
81 friend class ProfileManager;
82};
83
84
87public:
88 static void Start_Profile( const char * name );
89 static void Stop_Profile( void );
90
91 static void CleanupMemory(void)
92 {
93 Root.CleanupMemory();
94 }
95
96 static void Reset( void );
97 static void Increment_Frame_Counter( void );
98 static int Get_Frame_Count_Since_Reset( void ) { return FrameCounter; }
99 static float Get_Time_Since_Reset( void );
100
102 {
103
104 return new ProfileIterator( &Root );
105 }
106 static void Release_Iterator( ProfileIterator * iterator ) { delete ( iterator); }
107
108 static void dumpRecursive(std::string &output, ProfileIterator* profileIterator, int spacing);
109
110 static void dumpAll(std::string &output);
111
112private:
115 static int FrameCounter;
116 static unsigned long int ResetTime;
117};
118
119
123public:
124 ProfileSample( const char * name, bool advanced = true );
125 ~ProfileSample( void );
126private:
128};
129
130#ifdef ENABLE_PROFILING
131#define SBS_PROFILE(name) ProfileSample __profile(name, true)
132#define SBS_PROFILE_MAIN(name) ProfileSample __profile(name, false)
133#else
134#define SBS_PROFILE(name)
135#endif
136
137}
138
139#endif
140
An iterator to navigate through the tree.
Definition profiler.h:53
int Get_Current_Parent_Total_Calls(void)
Definition profiler.h:72
int Get_Current_Total_Calls(void)
Definition profiler.h:67
const char * Get_Current_Parent_Name(void)
Definition profiler.h:71
const char * Get_Current_Name(void)
Definition profiler.h:66
ProfileNode * CurrentParent
Definition profiler.h:77
bool Is_Root(void)
Definition profiler.h:59
void Enter_Largest_Child(void)
float Get_Current_Parent_Total_Time(void)
Definition profiler.h:73
ProfileNode * CurrentChild
Definition profiler.h:78
float Get_Current_Total_Time(void)
Definition profiler.h:68
The Manager for the Profile system.
Definition profiler.h:86
static ProfileNode Root
Definition profiler.h:113
static void Release_Iterator(ProfileIterator *iterator)
Definition profiler.h:106
static int Get_Frame_Count_Since_Reset(void)
Definition profiler.h:98
static unsigned long int ResetTime
Definition profiler.h:116
static int FrameCounter
Definition profiler.h:115
static ProfileNode * CurrentNode
Definition profiler.h:114
static ProfileIterator * Get_Iterator(void)
Definition profiler.h:101
static void CleanupMemory(void)
Definition profiler.h:91
A node in the Profile Hierarchy Tree.
Definition profiler.h:17
ProfileNode * Get_Child(void)
Definition profiler.h:27
ProfileNode * Child
Definition profiler.h:47
ProfileNode * Sibling
Definition profiler.h:48
ProfileNode * Get_Sibling(void)
Definition profiler.h:26
unsigned long int StartTime
Definition profiler.h:43
ProfileNode * Get_Parent(void)
Definition profiler.h:25
int Get_Total_Calls(void)
Definition profiler.h:35
float Get_Total_Time(void)
Definition profiler.h:36
ProfileNode * Parent
Definition profiler.h:46
const char * Name
Definition profiler.h:40
const char * Get_Name(void)
Definition profiler.h:34
#define SBSIMPEXP
Definition globals.h:53