Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UE4动态stats
//DynamicStats.h
# pragma once
# include "Stats2.h"
# include "Map.h"
# if STATS
DECLARE_STATS_GROUP(TEXT("Dynamic"), STATGROUP_Dynamic, STATCAT_Advanced);
class FDynamicScopeCycleCounter : public FCycleCounter
{
public:
FDynamicScopeCycleCounter(FString FunctionName)
{
TStatId statID = GetStatIdForFunction("[Dynamic]" + FunctionName);
if (FThreadStats::IsCollectingData(statID))
{
Start(statID);
}
}
~FDynamicScopeCycleCounter()
{
Stop();
}
private:
TStatId GetStatIdForFunction(FString FunctionName)
{
static TMap<FString, TStatId> FunctionStatIdMap;
if (FunctionStatIdMap.Contains(FunctionName))
{
return FunctionStatIdMap[FunctionName];
}
else
{
TStatId statID = FDynamicStats::CreateStatId<FStatGroup_STATGROUP_Dynamic>(FunctionName);
FunctionStatIdMap.Add(FunctionName, statID);
return statID;
}
}
};
# if UE_BUILD_TEST || UE_EDITOR
# define DYNAMIC_SCOPE_CYCLE_COUNTER(name, showname) \
FDynamicScopeCycleCounter name##Counter(showname);
# else
# define DYNAMIC_SCOPE_CYCLE_COUNTER(name, showname)
# endif
# else
# define DYNAMIC_SCOPE_CYCLE_COUNTER(name, showname)
# endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment