Files
UnrealEngineUWP/Engine/Source/Developer/Profiler/Private/ProfilerFPSAnalyzer.cpp
ionut matasaru 1502e84e56 Disabled Profiler if STATS is not enabled (so Editor can compile also when ENABLE_STATNAMEDEVENTS is on).
#jira UE-140874
#fyi Brandon.Schaefer
#preflight 6201451e6773a3612898bddb
#rb none

[CL 18886574 by ionut matasaru in ue5-main branch]
2022-02-07 11:35:37 -05:00

96 lines
1.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#include "ProfilerFPSAnalyzer.h"
#if STATS
void FFPSAnalyzer::Reset()
{
Samples.Reset();
Histogram.Reset();
Histogram.AddZeroed((MaxVal-MinVal)/Interval+1);
MinFPS = 9999;
MaxFPS = 0;
AveFPS = 0;
FPS90 = 0;
FPS60 = 0;
FPS30 = 0;
FPS25 = 0;
FPS20 = 0;
}
void FFPSAnalyzer::AddSample(float FPSSample)
{
Samples.Add(FPSSample);
float DeltaSeconds = 1.0f / FPSSample;
int32 Index = FPlatformMath::FloorToInt(FPSSample / Interval);
Index = Index >= Histogram.Num() ? Histogram.Num()-1 : Index;
Histogram[Index].Count++;
Histogram[Index].CummulativeTime += DeltaSeconds;
if (FPSSample >= 90)
{
FPS90++;
}
if (FPSSample >= 60)
{
FPS60++;
}
if (FPSSample >= 30)
{
FPS30++;
}
if (FPSSample >= 25)
{
FPS25++;
}
if (FPSSample >= 20)
{
FPS20++;
}
if (FPSSample > MaxFPS)
{
MaxFPS = FPSSample;
}
if (FPSSample < MinFPS)
{
MinFPS = FPSSample;
}
AveFPS = (FPSSample + (float)(Samples.Num()-1) * AveFPS) / (float)Samples.Num();
}
SIZE_T FFPSAnalyzer::GetMemoryUsage() const
{
const SIZE_T MemoryAllocated = Samples.GetAllocatedSize() + Histogram.GetAllocatedSize();
return MemoryAllocated;
}
int32 FFPSAnalyzer::GetTotalCount()
{
return Samples.Num();
}
int32 FFPSAnalyzer::GetCount(float InMinVal, float InMaxVal)
{
int32 Index = FPlatformMath::FloorToInt(InMinVal / Interval);
Index = Index >= Histogram.Num() ? Histogram.Num()-1 : Index;
return Histogram[Index].Count;
}
#endif // STATS