Skip to content

Instantly share code, notes, and snippets.

@vgvgvvv
Last active November 23, 2021 03:20
Show Gist options
  • Save vgvgvvv/dbdbfb3574768cc80969c1cb827868c0 to your computer and use it in GitHub Desktop.
Save vgvgvvv/dbdbfb3574768cc80969c1cb827868c0 to your computer and use it in GitHub Desktop.
UE4动态stats
//DynamicStats.h
# pragma once
# if STATS
DECLARE_STATS_GROUP(TEXT("Dynamic"), STATGROUP_Dynamic, STATCAT_Advanced);
class FDynamicScopeCycleStatIdContainer : public TThreadSingleton<FDynamicScopeCycleStatIdContainer>
{
public:
TStatId GetStatId(FString FunctionName)
{
if (FunctionStatIdMap.Contains(FunctionName))
{
return FunctionStatIdMap[FunctionName];
}
else
{
TStatId statID = FDynamicStats::CreateStatId<FStatGroup_STATGROUP_Dynamic>(FunctionName);
FunctionStatIdMap.Add(FunctionName, statID);
return statID;
}
}
private:
TMap<FString, TStatId> FunctionStatIdMap;
};
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)
{
return FDynamicScopeCycleStatIdContainer::Get().GetStatId(FunctionName);
}
};
# 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