TexGen
ShinyManager.h
Go to the documentation of this file.
1/*
2The zlib/libpng License
3
4Copyright (c) 2007 Aidin Abedi (www.*)
5
6This software is provided 'as-is', without any express or implied warranty. In no event will
7the authors be held liable for any damages arising from the use of this software.
8
9Permission is granted to anyone to use this software for any purpose, including commercial
10applications, and to alter it and redistribute it freely, subject to the following
11restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not claim that
14 you wrote the original software. If you use this software in a product,
15 an acknowledgment in the product documentation would be appreciated but is
16 not required.
17
18 2. Altered source versions must be plainly marked as such, and must not be
19 misrepresented as being the original software.
20
21 3. This notice may not be removed or altered from any source distribution.
22*/
23
24#ifndef SHINY_MANAGER_H
25#define SHINY_MANAGER_H
26
27#include "ShinyZone.h"
28#include "ShinyNode.h"
29#include "ShinyNodePool.h"
30#include "ShinyTools.h"
31#include "ShinyOutput.h"
32
33#include <iostream>
34
35
36#if SHINY_PROFILER == TRUE
37namespace Shiny {
38
39
40//-----------------------------------------------------------------------------
41
43 //NOTE: data-members are intentionally public because the
44 // class needs to fulfil the definition of an aggregate
45
47 TABLE_SIZE_INIT = 256
48 };
49
51
53
54 uint32_t _tableMask; // = _tableSize - 1
55
57
58#if SHINY_PROFILER_LOOKUPRATE == TRUE
59 uint64_t _lookupCount;
61#endif
62
63 uint32_t _tableSize;
64
65 uint32_t nodeCount;
66 uint32_t zoneCount;
67
69
72
75
78
80
82
83 //
84
86 register tick_t curTick;
87 GetTicks(&curTick);
88
89 _curNode->appendTicks(curTick - _lastTick);
90 _lastTick = curTick;
91 }
92
94
95 void _createNodeTable(uint32_t a_count);
96 void _resizeNodeTable(uint32_t a_count);
97
98 void _createNodePool(uint32_t a_count);
99 void _resizeNodePool(uint32_t a_count);
100
102 void _insertNode(ProfileNode* a_pNode);
103
104 void _init(void) {
105 _initialized = true;
106
109 }
110
111 void _uninit(void) {
112 _initialized = false;
113
114 rootNode.clear();
117 }
118
119#if SHINY_PROFILER_LOOKUPRATE == TRUE
122 SHINY_INLINE float lookupSuccessRate(void) const { return ((float) _lookupSuccessCount) / ((float) _lookupCount); }
123
124#else
125 SHINY_INLINE void _incLookup(void) {}
126 SHINY_INLINE void _incLookupSuccess(void) {}
127 SHINY_INLINE float lookupSuccessRate(void) const { return -1; }
128#endif
129
130 void _resetZones(void);
131 void _destroyNodes(void);
132
133 SHINY_INLINE float tableUsage(void) const { return ((float) nodeCount) / ((float) _tableSize); }
134
135 uint32_t staticMemInBytes(void) {
136 // ASSUME: zones and cache are used as intended; throught the macros
137
138 return sizeof(instance) + sizeof(_dummyNodeTable[0]) + sizeof(ProfileNode::_dummy)
139 + (zoneCount - 1) * (sizeof(ProfileZone) + sizeof(ProfileNodeCache));
140 }
141
142 uint32_t allocMemInBytes(void) {
143 return _tableSize * sizeof(ProfileNode*)
145 }
146
148 if (_curNode != (*a_cache)->parent)
149 *a_cache = _lookupNode(a_cache, a_zone);
150
151 _beginNode(*a_cache);
152 }
153
155 a_node->beginEntry();
156
158 _curNode = a_node;
159 }
160
164 }
165
166 //
167
168 void preLoad(void);
169
170 void updateClean(void);
171 void update(float a_damping = 0.9f);
172
173 void clear(void);
174 void destroy(void);
175
176 bool output(const char *a_filename);
177 bool output(std::ostream &a_ostream = std::cout);
178
181
182 //
183
184 static void enumerateNodes(void (*a_func)(const ProfileNode*),
185 const ProfileNode* a_node = &instance.rootNode)
186 {
187 a_func(a_node);
188
189 if (a_node->firstChild) enumerateNodes(a_func, a_node->firstChild);
190 if (a_node->nextSibling) enumerateNodes(a_func, a_node->nextSibling);
191 }
192
193 template <class T>
194 static void enumerateNodes(T* a_this, void (T::*a_func)(const ProfileNode*),
195 const ProfileNode* a_node = &instance.rootNode)
196 {
197 (a_this->*a_func)(a_node);
198
199 if (a_node->firstChild) enumerateNodes(a_this, a_func, a_node->firstChild);
200 if (a_node->nextSibling) enumerateNodes(a_this, a_func, a_node->nextSibling);
201 }
202
203 static void enumerateZones(void (*a_func)(const ProfileZone*),
204 const ProfileZone* a_zone = &instance.rootZone)
205 {
206 a_func(a_zone);
207
208 if (a_zone->next) enumerateZones(a_func, a_zone->next);
209 }
210
211 template <class T>
212 static void enumerateZones(T* a_this, void (T::*a_func)(const ProfileZone*),
213 const ProfileZone* a_zone = &instance.rootZone)
214 {
215 (a_this->*a_func)(a_zone);
216
217 if (a_zone->next) enumerateZones(a_this, a_func, a_zone->next);
218 }
219 };
220
221
222//-----------------------------------------------------------------------------
223
225 public:
226
229 }
230 };
231
232} // namespace Shiny
233
234#endif // if SHINY_PROFILER == TRUE
235
236#endif // ifndef SHINY_*_H
#define SHINY_INLINE
Definition: ShinyPrereqs.h:55
SHINY_INLINE ~ProfileAutoEndNode()
Definition: ShinyManager.h:227
uint64_t tick_t
Definition: ShinyPrereqs.h:77
std::string OutputNodesAsString(const ProfileNode *a_root, uint32_t a_count)
void GetTicks(tick_t *p)
std::string OutputZonesAsString(const ProfileZone *a_root, uint32_t a_count)
static void enumerateZones(T *a_this, void(T::*a_func)(const ProfileZone *), const ProfileZone *a_zone=&instance.rootZone)
Definition: ShinyManager.h:212
void _destroyNodes(void)
uint32_t staticMemInBytes(void)
Definition: ShinyManager.h:135
SHINY_INLINE void _beginNode(ProfileNode *a_node)
Definition: ShinyManager.h:154
SHINY_INLINE float lookupSuccessRate(void) const
Definition: ShinyManager.h:122
static ProfileNode * _dummyNodeTable[]
Definition: ShinyManager.h:79
ProfileNode rootNode
Definition: ShinyManager.h:73
SHINY_INLINE void _beginNode(ProfileNodeCache *a_cache, ProfileZone *a_zone)
Definition: ShinyManager.h:147
SHINY_INLINE void _incLookup(void)
Definition: ShinyManager.h:120
uint32_t allocMemInBytes(void)
Definition: ShinyManager.h:142
void _insertNode(ProfileNode *a_pNode)
static void enumerateZones(void(*a_func)(const ProfileZone *), const ProfileZone *a_zone=&instance.rootZone)
Definition: ShinyManager.h:203
ProfileNodePool * _firstNodePool
Definition: ShinyManager.h:71
void _resizeNodePool(uint32_t a_count)
void _createNodeTable(uint32_t a_count)
uint64_t _lookupSuccessCount
Definition: ShinyManager.h:60
bool output(const char *a_filename)
ProfileNode * _lookupNode(ProfileNodeCache *a_cache, ProfileZone *a_zone)
SHINY_INLINE std::string outputZonesAsString(void)
Definition: ShinyManager.h:180
SHINY_INLINE void _appendTicksToCurNode(void)
Definition: ShinyManager.h:85
void update(float a_damping=0.9f)
ProfileNode * _curNode
Definition: ShinyManager.h:52
static void enumerateNodes(void(*a_func)(const ProfileNode *), const ProfileNode *a_node=&instance.rootNode)
Definition: ShinyManager.h:184
ProfileZone rootZone
Definition: ShinyManager.h:74
ProfileNode * _createNode(ProfileNodeCache *a_cache, ProfileZone *a_pZone)
SHINY_INLINE float tableUsage(void) const
Definition: ShinyManager.h:133
void _createNodePool(uint32_t a_count)
SHINY_INLINE void _endCurNode(void)
Definition: ShinyManager.h:161
static void enumerateNodes(T *a_this, void(T::*a_func)(const ProfileNode *), const ProfileNode *a_node=&instance.rootNode)
Definition: ShinyManager.h:194
ProfileZone * _lastZone
Definition: ShinyManager.h:68
ProfileNodeTable * _nodeTable
Definition: ShinyManager.h:56
void _resizeNodeTable(uint32_t a_count)
SHINY_INLINE std::string outputNodesAsString(void)
Definition: ShinyManager.h:179
SHINY_INLINE void _incLookupSuccess(void)
Definition: ShinyManager.h:121
bool output(std::ostream &a_ostream=std::cout)
static ProfileManager instance
Definition: ShinyManager.h:81
ProfileNodePool * _lastNodePool
Definition: ShinyManager.h:70
SHINY_INLINE void appendTicks(tick_t a_elapsedTicks)
Definition: ShinyNode.h:89
SHINY_INLINE void beginEntry(void)
Definition: ShinyNode.h:90
static ProfileNode _dummy
Definition: ShinyNode.h:58
ProfileNode * parent
Definition: ShinyNode.h:45
ProfileZone * zone
Definition: ShinyNode.h:44
uint32_t memoryUsageChain(void)