天天看點

虛幻4 SCOPE_CYCLE_COUNTER

QUICK_SCOPE_CYCLE_COUNTER(STAT_FForwardShadingSceneRenderer_Render);
           

展開:

第一步:

#define QUICK_SCOPE_CYCLE_COUNTER(Stat) \
	SCOPE_CYCLE_COUNTER_GUARD \
	DECLARE_SCOPE_CYCLE_COUNTER(TEXT(#Stat),Stat,STATGROUP_Quick)


	SCOPE_CYCLE_COUNTER_GUARD \
	DECLARE_SCOPE_CYCLE_COUNTER(TEXT(#Stat),Stat,STATGROUP_Quick)


	{const char* ReadTheText = "SCOPE_CYCLE_COUNTER can't be used in the global scope.";}
	DECLARE_SCOPE_CYCLE_COUNTER("STAT_FForwardShadingSceneRenderer_Render",STAT_FForwardShadingSceneRenderer_Render,STATGROUP_Quick)


#define DECLARE_SCOPE_CYCLE_COUNTER(CounterName,Stat,GroupId) \
	SCOPE_CYCLE_COUNTER_GUARD \
	DECLARE_STAT(CounterName,Stat,GroupId,EStatDataType::ST_int64, true, true, FPlatformMemory::MCR_Invalid); \
	static DEFINE_STAT(Stat) \
	FScopeCycleCounter CycleCount_##Stat(GET_STATID(Stat));




第二步:
{const char* ReadTheText = "SCOPE_CYCLE_COUNTER can't be used in the global scope.";}
{const char* ReadTheText = "SCOPE_CYCLE_COUNTER can't be used in the global scope.";}
DECLARE_STAT("STAT_FForwardShadingSceneRenderer_Render",STAT_FForwardShadingSceneRenderer_Render,STATGROUP_Quick,EStatDataType::ST_int64, true, true, FPlatformMemory::MCR_Invalid); \
static DEFINE_STAT(STAT_FForwardShadingSceneRenderer_Render) \
FScopeCycleCounter CycleCount_STAT_FForwardShadingSceneRenderer_Render(GET_STATID(STAT_FForwardShadingSceneRenderer_Render));



第三步:

#define DECLARE_STAT(Description, StatName, GroupName, StatType, bShouldClearEveryFrame, bCycleStat, MemoryRegion) \
struct FStat_##StatName\
{ \
	typedef FStatGroup_##GroupName TGroup; \
	static FORCEINLINE const char* GetStatName() \
	{ \
		return #StatName; \
	} \
	static FORCEINLINE const TCHAR* GetDescription() \
	{ \
		return Description; \
	} \
	static FORCEINLINE EStatDataType::Type GetStatType() \
	{ \
		return StatType; \
	} \
	static FORCEINLINE bool IsClearEveryFrame() \
	{ \
		return bShouldClearEveryFrame; \
	} \
	static FORCEINLINE bool IsCycleStat() \
	{ \
		return bCycleStat; \
	} \
	static FORCEINLINE FPlatformMemory::EMemoryCounterRegion GetMemoryRegion() \
	{ \
		return MemoryRegion; \
	} \
};


第四步:
{const char* ReadTheText = "SCOPE_CYCLE_COUNTER can't be used in the global scope.";}
{const char* ReadTheText = "SCOPE_CYCLE_COUNTER can't be used in the global scope.";}
struct FStat_STAT_FForwardShadingSceneRenderer_Render\
{ \
	typedef FStatGroup_STATGROUP_Quick TGroup; \
	static FORCEINLINE const char* GetStatName() \
	{ \
		return "STAT_FForwardShadingSceneRenderer_Render"; \
	} \
	static FORCEINLINE const TCHAR* GetDescription() \
	{ \
		return "STAT_FForwardShadingSceneRenderer_Render"; \
	} \
	static FORCEINLINE EStatDataType::Type GetStatType() \
	{ \
		return EStatDataType::ST_int64; \
	} \
	static FORCEINLINE bool IsClearEveryFrame() \
	{ \
		return true; \
	} \
	static FORCEINLINE bool IsCycleStat() \
	{ \
		return true; \
	} \
	static FORCEINLINE FPlatformMemory::EMemoryCounterRegion GetMemoryRegion() \
	{ \
		return FPlatformMemory::MCR_Invalid; \
	} \
};
static DEFINE_STAT(STAT_FForwardShadingSceneRenderer_Render) \
FScopeCycleCounter CycleCount_STAT_FForwardShadingSceneRenderer_Render(GET_STATID(STAT_FForwardShadingSceneRenderer_Render));




#define DEFINE_STAT(Stat) \
	struct FThreadSafeStaticStat<FStat_##Stat> StatPtr_##Stat;



第五步:

{const char* ReadTheText = "SCOPE_CYCLE_COUNTER can't be used in the global scope.";}
{const char* ReadTheText = "SCOPE_CYCLE_COUNTER can't be used in the global scope.";}
struct FStat_STAT_FForwardShadingSceneRenderer_Render\
{ \
	typedef FStatGroup_STATGROUP_Quick TGroup; \
	static FORCEINLINE const char* GetStatName() \
	{ \
		return "STAT_FForwardShadingSceneRenderer_Render"; \
	} \
	static FORCEINLINE const TCHAR* GetDescription() \
	{ \
		return "STAT_FForwardShadingSceneRenderer_Render"; \
	} \
	static FORCEINLINE EStatDataType::Type GetStatType() \
	{ \
		return EStatDataType::ST_int64; \
	} \
	static FORCEINLINE bool IsClearEveryFrame() \
	{ \
		return true; \
	} \
	static FORCEINLINE bool IsCycleStat() \
	{ \
		return true; \
	} \
	static FORCEINLINE FPlatformMemory::EMemoryCounterRegion GetMemoryRegion() \
	{ \
		return FPlatformMemory::MCR_Invalid; \
	} \
};
static struct FThreadSafeStaticStat<FStat_STAT_FForwardShadingSceneRenderer_Render> StatPtr_STAT_FForwardShadingSceneRenderer_Render;
FScopeCycleCounter CycleCount_STAT_FForwardShadingSceneRenderer_Render(GET_STATID(STAT_FForwardShadingSceneRenderer_Render));

#define GET_STATID(Stat) (StatPtr_##Stat.GetStatId())


GET_STATID(STAT_FForwardShadingSceneRenderer_Render) = StatPtr_STAT_FForwardShadingSceneRenderer_Render.GetStatId()


           

最終結果:

{const char* ReadTheText = "SCOPE_CYCLE_COUNTER can't be used in the global scope.";}
{const char* ReadTheText = "SCOPE_CYCLE_COUNTER can't be used in the global scope.";}
struct FStat_STAT_FForwardShadingSceneRenderer_Render\
{ \
	typedef FStatGroup_STATGROUP_Quick TGroup; \
	static FORCEINLINE const char* GetStatName() \
	{ \
		return "STAT_FForwardShadingSceneRenderer_Render"; \
	} \
	static FORCEINLINE const TCHAR* GetDescription() \
	{ \
		return "STAT_FForwardShadingSceneRenderer_Render"; \
	} \
	static FORCEINLINE EStatDataType::Type GetStatType() \
	{ \
		return EStatDataType::ST_int64; \
	} \
	static FORCEINLINE bool IsClearEveryFrame() \
	{ \
		return true; \
	} \
	static FORCEINLINE bool IsCycleStat() \
	{ \
		return true; \
	} \
	static FORCEINLINE FPlatformMemory::EMemoryCounterRegion GetMemoryRegion() \
	{ \
		return FPlatformMemory::MCR_Invalid; \
	} \
};
static struct FThreadSafeStaticStat<FStat_STAT_FForwardShadingSceneRenderer_Render> StatPtr_STAT_FForwardShadingSceneRenderer_Render;
FScopeCycleCounter CycleCount_STAT_FForwardShadingSceneRenderer_Render(StatPtr_STAT_FForwardShadingSceneRenderer_Render.GetStatId());
           

展開:

SCOPE_CYCLE_COUNTER(STAT_TranslucencyDrawTime);
           

結果:

{const char* ReadTheText = "SCOPE_CYCLE_COUNTER can't be used in the global scope.";}
FScopeCycleCounter CycleCount_STAT_TranslucencyDrawTime(StatPtr_STAT_TranslucencyDrawTime.GetStatId());
           

FScopeCycleCounter

這個類被建立時候,就開始計時了。

/**
 * This is a utility class for counting the number of cycles during the
 * lifetime of the object. It updates the per thread values for this
 * stat.
 */
class FScopeCycleCounter : public FCycleCounter
{
public:
	/**
	 * Pushes the specified stat onto the hierarchy for this thread. Starts
	 * the timing of the cycles used
	 */
	FORCEINLINE_STATS FScopeCycleCounter( TStatId StatId, bool bAlways = false )
	{
		Start( StatId, bAlways );
	}

	/**
	 * Updates the stat with the time spent
	 */
	FORCEINLINE_STATS ~FScopeCycleCounter()
	{
		Stop();
	}

};
           

繼續閱讀