OROCHI
 
Loading...
Searching...
No Matches
GxProfiler.h
Go to the documentation of this file.
1//===========================================================================
10//===========================================================================
11#pragma once
12
13#if GX_DEVELOP
14
15GX_CORE_NAMESPACE_BEGIN()
16
17class GxRenderContext;
18class GxRenderQuery;
19
20//===========================================================================
22//===========================================================================
23class GxProfiler : public GxClassBase, public SingletonBase<GxProfiler>
24{
25 //-------------------------------------------------------------
27 //-------------------------------------------------------------
29public:
30 // RTTI定義
31 GX_RTTI_ABSTRACT_CLASS( GxProfiler, GxClassBase )
32 // GxClassBase継承クラス用禁止宣言
33 GX_PROHIBIT_CLASS_BASE( GxProfiler )
34
35 static const GxColor ColorMainUpdate;
36 static const GxColor ColorBaseTool;
37 static const GxColor ColorBaseUnit;
38 static const GxColor ColorBaseStage;
39 static const GxColor ColorBaseResource;
40 static const GxColor ColorBaseRender;
41 static const GxColor ColorBasePhysics;
42
43 class GxScopeProfiler;
44 class GxProfileBase;
45 class GxThreadProfile;
46 class GxGpuProfile;
47 class GxThreadProfileIterator;
48
50 struct GxLogData
51 {
52 //-----------------------------------------------------------
54 //-----------------------------------------------------------
56
58 void clear(void)
59 {
60 _averageTime = 0;
61 _totalTime = 0;
62 _minTime = U32_MAX;
63 _maxTime = 0;
64 _temporaryTime = 0;
65 _temporaryTotalTime = 0;
66 _percentTotal = 0;
67 _percentParent = 0;
68 _timeCount = 0;
69 _temporaryTimeCount = 0;
70 }
71
73 //-----------------------------------------------------------
75 //-----------------------------------------------------------
77
78 u32 _averageTime;
79 u32 _totalTime;
80 u32 _minTime;
81 u32 _maxTime;
82 u32 _temporaryTime;
83 u32 _temporaryTotalTime;
84 u16 _percentTotal;
85 u16 _percentParent;
86 u16 _timeCount;
87 u16 _temporaryTimeCount;
88
90 };
91
92
96 struct GxLog
97 {
98 //-----------------------------------------------------------
100 //-----------------------------------------------------------
102
104 GxLog(void)
105 : _pNext( nullptr )
106 , _pParent( nullptr )
107 , _pChild( nullptr )
108 , _name( nullptr )
109 , _color( GxColor::WHITE )
110 , _isOpen( false )
111 , _pBufferData( nullptr )
112 {}
113
115 //-----------------------------------------------------------
117 //-----------------------------------------------------------
119
120 GxLog* _pNext;
121 GxLog* _pParent;
122 GxLog* _pChild;
123 GX_CSTR _name;
124
125 // ツール用
126 GxColor _color;
127 b32 _isOpen;
128 GxLogData* _pBufferData;
129
131 };
132
134 //-------------------------------------------------------------
136 //-------------------------------------------------------------
138
140 GxProfiler( void );
141
143 ~GxProfiler( void ) override;
144
146 b32 initialize( const u32 logMax );
147
149 b32 initializeThreadProfiling( const u32 index );
151 void terminateThreadProfiling( const u32 index );
152
154 //-------------------------------------------------------------
156 //-------------------------------------------------------------
158
160 GxThreadProfileIterator getThreadProfileIterator( void );
163 constexpr GxGpuProfile* getGpuProfile( void ) const { return _pGpuProfile; }
166 constexpr u32 getProfilingLogMax( void ) const { return _profilingLogMax; }
168 void setIsActive(b32 isActive);
171 constexpr void setProfileFrame( s32 frame ) { _profileFrame = frame; }
172 static b32 isActive( void ) { return _isActive; }
173
176 const GxLogData* getProfileData( GX_CSTR name );
177
178#if defined(_NX64)
180 static void setNativeProfilerFunction(void* pInitializeFunction, void* pRecordFunction, void* pEnterCodeBlockName, void* pExitCodeBlockName);
181#endif // _NX64
182
184 //-------------------------------------------------------------
186 //-------------------------------------------------------------
188
190 virtual void update( void );
191
193 void clearAllData( void );
195 void setIsOpenAllTree( b32 isOpen );
196
198 void beginThreadProfiling( GX_CSTR name, const GxColor& color = GxColor::LIGHT_CYAN, const b32 adjustFromName = false );
199
201 void endThreadProfiling( GX_CSTR name );
202
204 void setThreadProfilerUpdateLock( b32 lock );
205
207 //-------------------------------------------------------------
209 //-------------------------------------------------------------
211private:
212 static b32 _isActive;
213 b32 _requestIsActive;
214 s32 _profileFrame;
215 s32 _frameCounter;
216 GxTimer _timer;
217 GxCriticalSection _criticalSection;
218
219 u32 _profilingLogMax;
220 GxThreadProfile** _ppThreadProfile;
221 GxGpuProfile* _pGpuProfile;
222
224};
225
226// アクセスインターフェース
227GX_FORCE_INLINE GxProfiler* getGxProfiler(void){ return GxProfiler::getSingletonPointer(); }
228
229//===========================================================================
231//===========================================================================
232class GxProfiler::GxProfileBase : public GxClassBase
233{
234 //-------------------------------------------------------------
236 //-------------------------------------------------------------
238public:
239 // RTTI定義
240 GX_RTTI_ABSTRACT_CLASS( GxProfiler::GxProfileBase, GxClassBase )
241
242 // new, delete定義
243 GX_OPERATOR_NEW_DELETE(GxAllocatorList::ALLOCATOR_TYPE::DEVELOP)
244
245
246 static constexpr u32 BUFFER_COUNT = 16;
247
249 //-------------------------------------------------------------
251 //-------------------------------------------------------------
253
255 GxProfileBase( void );
256
258 ~GxProfileBase( void ) override;
259
261 //-------------------------------------------------------------
263 //-------------------------------------------------------------
265
267 virtual void update( u32 timeTotalAll );
268
270 constexpr GxLog* getTopLog( void ) const { return _pLog ? _pLog[0]._pChild : nullptr ; }
271
273 void attachLog( void );
274
276 constexpr u32 getBackBufferIndex(void) const { return _backBufferIndex; }
277
279 constexpr u32 getBufferIndex( void ) const { return _bufferIndex; }
280
282 void clearAllData( void );
284 void setIsOpenAllTree( b32 isOpen );
285
287 constexpr u32 getLogMax( void ) const { return _logMax; }
288
290 void clearLogData(GxLog* pLog);
291
293 void setUpdateLock( b32 lock ) { _isUpdateLocked = lock; }
294
295protected:
297 b32 allocateLogTree( u32 logMax );
298
300 GxLog* createLog( GX_CSTR name, GxLog* pParent );
301
303 void updateLog( GxLog* pLog, const u32 bufferIndex, const u32 timeTotalAll );
304
306 //-------------------------------------------------------------
308 //-------------------------------------------------------------
310
311 u32 _logMax;
312 u32 _logCount;
313 u32 _bufferIndex;
314 u32 _backBufferIndex;
315 GxLogData* _pLogData;
316 GxLog* _pLog;
317 GxLog** _ppCurrentLog;
318 b32 _isUpdateLocked;
319 u32 _lockedTimeTotal;
320
322};
323
324//===========================================================================
326//===========================================================================
327class GxProfiler::GxThreadProfile : public GxProfileBase
328{
329 //-------------------------------------------------------------
331 //-------------------------------------------------------------
333public:
334 // RTTI定義
335 GX_RTTI_CLASS( GxProfiler::GxThreadProfile, GxProfileBase )
336
337 // new, delete定義
338 GX_OPERATOR_NEW_DELETE(GxAllocatorList::ALLOCATOR_TYPE::DEVELOP)
339
340
341 //-------------------------------------------------------------
343 //-------------------------------------------------------------
345
347 GxThreadProfile( void );
348
350 ~GxThreadProfile( void ) override {}
351
353 b32 initialize( void );
354
356 //-------------------------------------------------------------
358 //-------------------------------------------------------------
360
362 void beginProfiling( GX_CSTR name, const GxTimer& timer, const GxColor& color, const b32 adjustFromName, GxCriticalSection& criticalSection);
363
365 void endProfiling( GX_CSTR name, const u32 endTime, GxCriticalSection& criticalSection);
366
368 GxLog* getCurrentLog( GxCriticalSection& criticalSection );
369
371 //-------------------------------------------------------------
373 //-------------------------------------------------------------
375
378 constexpr GxThreadProfile* getNext( void ) const { return _pNext; }
381 constexpr GxThreadProfile* getPrevious( void ) const { return _pPrevious; }
384 constexpr void setNext( GxThreadProfile* pNext ) { _pNext = pNext; }
387 constexpr void setPrevious( GxThreadProfile* pPrevious ) { _pPrevious = pPrevious; }
388
390 //-------------------------------------------------------------
392 //-------------------------------------------------------------
394protected:
395 GxThreadProfile* _pNext;
396 GxThreadProfile* _pPrevious;
397
399};
400
401//===========================================================================
403// note:未完成
404//===========================================================================
405class GxProfiler::GxGpuProfile : public GxProfiler::GxProfileBase
406{
407 //-------------------------------------------------------------
409 //-------------------------------------------------------------
411public:
412 // RTTI定義
413 GX_RTTI_CLASS( GxProfiler::GxGpuProfile, GxProfiler::GxProfileBase )
414
415protected:
417 struct GxLogDataGpu
418 {
419 GxRenderQuery* _pBeginQuery;
420 GxRenderQuery* _pEndQuery;
421 b32 _queryIssued;
422 };
423
425 //-------------------------------------------------------------
427 //-------------------------------------------------------------
429public:
431 GxGpuProfile( void );
432
434 ~GxGpuProfile( void ) override;
435
437 b32 initialize( void );
438
440 void terminate(void);
441
443 //-------------------------------------------------------------
445 //-------------------------------------------------------------
447
449 void beginProfiling( GX_CSTR name, const GxColor& color, const b32 adjustFromName );
450
452 void endProfiling( GX_CSTR name );
453
455 GxLog* getCurrentLog( void );
456
458 void update( u32 timeTotalAll ) override;
459
461 //-------------------------------------------------------------
463 //-------------------------------------------------------------
465private:
466 GX_CHAR* _pLogName;
467 GxLogDataGpu* _pLogDataGpu;
468
470};
471
472//===========================================================================
475//===========================================================================
476class GxProfiler::GxScopeProfiler
477{
478 //-------------------------------------------------------------
480 //-------------------------------------------------------------
482public:
484 GxScopeProfiler( GX_CSTR name, const GxColor& color = GxColor::DARK_GRAY, const b32 adjustFromName = false );
485
487 ~GxScopeProfiler( void );
488
490 //-------------------------------------------------------------
492 //-------------------------------------------------------------
494private:
495 GX_CSTR _name;
496
498};
499
500//===========================================================================
502//===========================================================================
503class GxProfiler::GxThreadProfileIterator
504{
505 //-------------------------------------------------------------
507 //-------------------------------------------------------------
509public:
511 GxThreadProfileIterator( GxThreadProfile* pProfile );
512
514 //-------------------------------------------------------------
516 //-------------------------------------------------------------
518
520 constexpr GxThreadProfile* begin( void ) const { return _pTop; }
522 constexpr GxThreadProfile* current( void ) const { return _pCurrent; }
524 constexpr GxThreadProfile* next( void ) { _pCurrent = _pCurrent->getNext(); return _pCurrent; }
526 constexpr GxThreadProfile* end( void ) const { return _pTop ? _pTop->getPrevious() : nullptr; }
527
529 //-------------------------------------------------------------
531 //-------------------------------------------------------------
533private:
534 GxThreadProfile* _pTop;
535 GxThreadProfile* _pCurrent;
536
538};
539
540//===========================================================================
542//===========================================================================
543// note:createColorFromClassNameが良い感じになったら整理
544//-------------------------------------------------------------
546//-------------------------------------------------------------
548
550#define GX_PROFILE_BEGIN(name) getGxProfiler()->beginThreadProfiling( name )
551
553#define GX_PROFILE_BEGIN_COLOR( name, color ) getGxProfiler()->beginThreadProfiling( name, color )
554
556#define GX_PROFILE_BEGIN_COLOR_ADJUST( name, colorBase ) getGxProfiler()->beginThreadProfiling( name, colorBase, true )
557
559#define GX_PROFILE_END( name ) getGxProfiler()->endThreadProfiling( name )
560
562//-------------------------------------------------------------
564//-------------------------------------------------------------
566
568#define GX_PROFILE( name ) GxProfiler::GxScopeProfiler __scopeProfiler( name )
569
571#define GX_PROFILE_COLOR( name, color ) GxProfiler::GxScopeProfiler __scopeProfiler( name, color )
572
574#define GX_PROFILE_COLOR_ADJUST( name, colorBase ) GxProfiler::GxScopeProfiler __scopeProfiler( name, colorBase, true )
575
577//-------------------------------------------------------------
579//-------------------------------------------------------------
581
582#define GX_TIME_FUNCTION( function, time ) { \
583 GxTimer __timer; \
584 function; \
585 time = __timer.getDiff(); \
586}
587
588#define GX_TIME_FUNCTION_ITERATION( function, time, iteration ) { \
589 GxTimer __timer; \
590 for(u32 __i=0; __i<iteration; ++__i) { function; }\
591 time = __timer.getDiff(); \
592}
593
595
596GX_CORE_NAMESPACE_END()
597
598#else // GX_DEVELOP
599
600#define GX_PROFILE_BEGIN(name)
601#define GX_PROFILE_BEGIN_COLOR(name, COLOR )
602#define GX_PROFILE_BEGIN_COLOR_ADJUST(name, COLOR )
603#define GX_PROFILE_END(name)
604#define GX_PROFILE(name)
605#define GX_PROFILE_COLOR(name, color)
606#define GX_PROFILE_COLOR_ADJUST(name, color)
607
608#endif // !GX_DEVELOP
#define GX_PROHIBIT_CLASS_BASE(__CLASS__)
GxClassBase継承の禁止宣言
Definition GxBase.h:240
オブジェクト基底クラス
Definition GxBase.h:88
クリティカルセクションクラス
Definition GxThread.h:20
描画コマンドの並列発行を管理します。
Definition GxRenderContext.h:28
GPUクエリを管理する
Definition GxRenderQuery.h:19
タイマークラス
Definition GxTimer.h:110
シングルトン基礎クラス
Definition GxSingleton.h:19
Definition GxColor.h:21
static const GxColor DARK_GRAY
暗いグレー
Definition GxColor.h:45
static const GxColor LIGHT_CYAN
明るいシアン
Definition GxColor.h:52
32bitブーリアン
Definition GxDefine.h:173