1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
#ifndef _PROFILERSTATS_H_
#define _PROFILERSTATS_H_
#include "Configuration/UnityConfigure.h"
enum ValueFormat
{
kFormatTime, // milliseconds
kFormatCount, // number (optionally with k/M)
kFormatBytes, // number b/kB/m
kFormatPercentage // Percentage in % * 10 as an int, so that we can represent 10.1%
};
enum ProfilerArea
{
kProfilerAreaCPU,
kProfilerAreaGPU,
kProfilerAreaRendering,
kProfilerAreaMemory,
kProfilerAreaAudio,
kProfilerAreaPhysics,
kProfilerAreaPhysics2D,
kProfilerAreaDebug,
kProfilerAreaCount = kProfilerAreaDebug
};
#if ENABLE_PROFILER
#include "TimeHelper.h"
#include "Runtime/Utilities/dynamic_array.h"
struct MemoryStats
{
// used bytes: Total, unity(-profiler), mono, DX/OGL, Profiler, FMOD??, Executable??
// reserved bytes: Total, unity, mono, DX/OGL, Profiler, FMOD??, Executable??
size_t bytesUsedTotal;
size_t bytesUsedUnity;
size_t bytesUsedMono;
size_t bytesUsedGFX;
size_t bytesUsedFMOD;
size_t bytesUsedProfiler;
size_t bytesReservedTotal;
size_t bytesReservedUnity;
size_t bytesReservedMono;
size_t bytesReservedGFX;
size_t bytesReservedFMOD;
size_t bytesReservedProfiler;
size_t bytesVirtual;
size_t bytesCommitedLimit;
size_t bytesCommitedTotal;
int bytesUsedDelta;
int textureCount;
int textureBytes;
int meshCount;
int meshBytes;
int materialCount;
int materialBytes;
int animationClipCount;
int animationClipBytes;
int audioCount;
int audioBytes;
int assetCount;
int sceneObjectCount;
int gameObjectCount;
int totalObjectsCount;
int profilerMemUsed;
int profilerNumAllocations;
// NB! Everything above here will be cleared with a memset() in the constructor! ^^^^^^^^^^^^
dynamic_array<int> classCount;
ProfilerString memoryOverview;
MemoryStats () : classCount(kMemProfiler) { memset(this, 0, ptrdiff_t(&classCount) - ptrdiff_t(this)); classCount.clear(); memoryOverview.clear(); }
#if ENABLE_PLAYERCONNECTION
void Serialize( dynamic_array<int>& bitstream );
void Deserialize( int** bitstream, bool swapdata );
#endif
ProfilerString ToString () const;
};
struct DrawStats
{
int drawCalls;
int triangles;
int vertices;
int batchedDrawCalls;
int batchedTriangles;
int batchedVertices;
int shadowCasters;
int usedTextureCount;
int usedTextureBytes;
int renderTextureCount;
int renderTextureBytes;
int renderTextureStateChanges;
int screenWidth;
int screenHeight;
int screenFSAA;
int screenBytes;
int vboTotal;
int vboTotalBytes;
int vboUploads;
int vboUploadBytes;
int ibUploads;
int ibUploadBytes;
int visibleSkinnedMeshes;
int totalAvailableVRamMBytes;
// int textureStateChanges;
// int lightStateChanges;
// int pixelShaderStateChanges;
// int vertexShaderStateChanges;
DrawStats () { memset(this, 0, sizeof(*this)); }
ProfilerString GetScreenResString () const;
ProfilerString ToString () const;
};
struct PhysicsStats
{
int activeRigidbodies;
int sleepingRigidbodies;
int numberOfShapePairs;
int numberOfStaticColliders;
int numberOfDynamicColliders;
PhysicsStats () { memset(this, 0, sizeof(*this)); }
};
struct Physics2DStats
{
int m_TotalBodyCount;
int m_ActiveBodyCount;
int m_SleepingBodyCount;
int m_DynamicBodyCount;
int m_KinematicBodyCount;
int m_DiscreteBodyCount;
int m_ContinuousBodyCount;
int m_JointCount;
int m_ContactCount;
int m_ActiveColliderShapesCount;
int m_SleepingColliderShapesCount;
int m_StepTime;
int m_CollideTime;
int m_SolveTime;
int m_SolveInitialization;
int m_SolveVelocity;
int m_SolvePosition;
int m_SolveBroadphase;
int m_SolveTimeOfImpact;
Physics2DStats () { memset(this, 0, sizeof(*this)); }
};
struct DebugStats
{
DebugStats () { memset(this, 0, sizeof(*this)); }
int m_ProfilerMemoryUsage;
int m_ProfilerMemoryUsageOthers;
int m_AllocatedProfileSamples;
ProfilerString ToString () const;
#if ENABLE_PLAYERCONNECTION
void Serialize( dynamic_array<int>& bitstream );
void Deserialize( int** bitstream );
#endif
};
struct AudioStats
{
AudioStats () { memset(this, 0, sizeof(*this)); }
int playingSources;
int pausedSources;
int audioCPUusage;
int audioMemUsage;
int audioMaxMemUsage;
int audioVoices;
int audioClipCount;
int audioSourceCount;
unsigned int audioMemDetailsUsage;
struct Details
{
unsigned int other; /* [out] Memory not accounted for by other types */
unsigned int string; /* [out] String data */
unsigned int system; /* [out] System object and various internals */
unsigned int plugins; /* [out] Plugin objects and internals */
unsigned int output; /* [out] Output module object and internals */
unsigned int channel; /* [out] Channel related memory */
unsigned int channelgroup; /* [out] ChannelGroup objects and internals */
unsigned int codec; /* [out] Codecs allocated for streaming */
unsigned int file; /* [out] File buffers and structures */
unsigned int sound; /* [out] Sound objects and internals */
unsigned int secondaryram; /* [out] Sound data stored in secondary RAM */
unsigned int soundgroup; /* [out] SoundGroup objects and internals */
unsigned int streambuffer; /* [out] Stream buffer memory */
unsigned int dspconnection; /* [out] DSPConnection objects and internals */
unsigned int dsp; /* [out] DSP implementation objects */
unsigned int dspcodec; /* [out] Realtime file format decoding DSP objects */
unsigned int profile; /* [out] Profiler memory footprint. */
unsigned int recordbuffer; /* [out] Buffer used to store recorded data from microphone */
unsigned int reverb; /* [out] Reverb implementation objects */
unsigned int reverbchannelprops; /* [out] Reverb channel properties structs */
unsigned int geometry; /* [out] Geometry objects and internals */
unsigned int syncpoint; /* [out] Sync point memory. */
unsigned int eventsystem; /* [out] EventSystem and various internals */
unsigned int musicsystem; /* [out] MusicSystem and various internals */
unsigned int fev; /* [out] Definition of objects contained in all loaded projects e.g. events, groups, categories */
unsigned int memoryfsb; /* [out] Data loaded with preloadFSB */
unsigned int eventproject; /* [out] EventProject objects and internals */
unsigned int eventgroupi; /* [out] EventGroup objects and internals */
unsigned int soundbankclass; /* [out] Objects used to manage wave banks */
unsigned int soundbanklist; /* [out] Data used to manage lists of wave bank usage */
unsigned int streaminstance; /* [out] Stream objects and internals */
unsigned int sounddefclass; /* [out] Sound definition objects */
unsigned int sounddefdefclass; /* [out] Sound definition static data objects */
unsigned int sounddefpool; /* [out] Sound definition pool data */
unsigned int reverbdef; /* [out] Reverb definition objects */
unsigned int eventreverb; /* [out] Reverb objects */
unsigned int userproperty; /* [out] User property objects */
unsigned int eventinstance; /* [out] Event instance base objects */
unsigned int eventinstance_complex; /* [out] Complex event instance objects */
unsigned int eventinstance_simple; /* [out] Simple event instance objects */
unsigned int eventinstance_layer; /* [out] Event layer instance objects */
unsigned int eventinstance_sound; /* [out] Event sound instance objects */
unsigned int eventenvelope; /* [out] Event envelope objects */
unsigned int eventenvelopedef; /* [out] Event envelope definition objects */
unsigned int eventparameter; /* [out] Event parameter objects */
unsigned int eventcategory; /* [out] Event category objects */
unsigned int eventenvelopepoint; /* [out] Event envelope point objects */
unsigned int eventinstancepool; /* [out] Event instance pool memory */
};
Details audioMemDetails;
};
// Stores samples for profiler charts
struct ChartSample
{
ChartSample () { memset(this, 0, sizeof(*this)); }
int rendering;
int scripts;
int physics;
int gc;
int vsync;
int others;
int gpuOpaque;
int gpuTransparent;
int gpuShadows;
int gpuPostProcess;
int gpuDeferredPrePass;
int gpuDeferredLighting;
int gpuOther;
int hasGPUProfiler;
};
struct AllProfilerStats
{
MemoryStats memoryStats;
DrawStats drawStats;
PhysicsStats physicsStats;
Physics2DStats physics2DStats;
DebugStats debugStats;
AudioStats audioStats;
ChartSample chartSample;
ChartSample chartSampleSelected;
#if ENABLE_PLAYERCONNECTION
void Serialize( dynamic_array<int>& bitstream );
void Deserialize( int** bitstream, bool swapdata );
#endif
};
struct StatisticsProperty
{
std::string name;
int offset;
ValueFormat format;
ProfilerArea area;
bool showGraph;
};
void InitializeStatisticsProperties (dynamic_array<StatisticsProperty>& statisticProperties);
inline int GetStatisticsValue (int offset, AllProfilerStats& stats)
{
AssertIf( offset < 0 || offset >= sizeof(AllProfilerStats) );
UInt8* dataPtr = reinterpret_cast<UInt8*>(&stats) + offset;
return *reinterpret_cast<int*> (dataPtr);
}
#endif
#endif
|