UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ABTesting.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
7#pragma once
8
9#include "Containers/Array.h"
10#include "Containers/BitArray.h"
12#include "CoreTypes.h"
13#include "Math/RandomStream.h"
14#include "Misc/Build.h"
15
16#if !UE_BUILD_SHIPPING
17#define ENABLE_ABTEST 1
18#else
19#define ENABLE_ABTEST 0
20#endif
21
23
24template<typename Allocator > class TBitArray;
25
26#if ENABLE_ABTEST
28{
29public:
30
32
33 //returns a command to execute, if any.
35
36 bool IsActive()
37 {
38 return bABTestActive;
39 }
40
42 {
43 TotalScopeTimeInFrame += ScopeTime;
44 }
45
47 {
48 return CurrentTest == 0;
49 }
50
51 static CORE_API FABTest& Get();
52
53 static CORE_API void ABTestCmdFunc(const TArray<FString>& Args);
54
55 static bool StaticIsActive()
56 {
57 return Get().bABTestActive;
58 }
59
60private:
61
62 CORE_API void StartFrameLog();
63 CORE_API void FrameLogTick(double Delta);
64
65 CORE_API void Start(FString* InABTestCmds, bool bScopeTest);
66 CORE_API void Stop();
67
68 CORE_API const TCHAR* SwitchTest(int32 Index);
69
70
71
72 FRandomStream Stream;
73 bool bABTestActive;
74 bool bABScopeTestActive; //whether we are doing abtesting on the scope macro rather than a CVAR.
75 bool bFrameLog;
76 FString ABTestCmds[2];
77 int32 ABTestNumSamples;
78 int32 RemainingCoolDown;
79 int32 CurrentTest;
80 int32 RemainingTrial;
81 int32 RemainingPrint;
82
83 int32 HistoryNum;
84 int32 ReportNum;
85 int32 CoolDown;
86 int32 MinFramesPerTrial;
87 int32 NumResamples;
88
89 struct FSample
90 {
91 uint32 Micros;
92 int32 TestIndex;
93 TBitArray<> InResamples;
94 };
95
96 TArray<FSample> Samples;
97 TArray<uint32> ResampleAccumulators;
98 TArray<uint32> ResampleCount;
99 uint32 Totals[2];
100 uint32 Counts[2];
101
102 double TotalTime;
103 uint32 TotalFrames;
104 uint32 Spikes;
105
106 double TotalScopeTimeInFrame;
107 uint64 LastGCFrame;
108
109};
110
112{
113public:
114 explicit FScopedABTimer()
115 : FDurationTimer(TimerData)
116 , TimerData(0)
117 {
118 Start();
119 }
120
127private:
128 double TimerData;
129};
130
131#define SCOPED_ABTEST() FScopedABTimer ABSCOPETIMER;
132#define SCOPED_ABTEST_DOFIRSTTEST() FABTest::Get().GetDoFirstScopeTest()
133#else
134
135class FABTest
136{
137public:
138 static bool StaticIsActive()
139 {
140 return false;
141 }
142};
143
144#define SCOPED_ABTEST(TimerName)
145#define SCOPED_ABTEST_DOFIRSTTEST() true
146#endif
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition ABTesting.h:28
bool IsActive()
Definition ABTesting.h:36
bool GetDoFirstScopeTest() const
Definition ABTesting.h:46
static CORE_API void ABTestCmdFunc(const TArray< FString > &Args)
static CORE_API FABTest & Get()
void ReportScopeTime(double ScopeTime)
Definition ABTesting.h:41
static bool StaticIsActive()
Definition ABTesting.h:55
CORE_API const TCHAR * TickAndGetCommand()
CORE_API FABTest()
Definition ScopedTimers.h:32
double & Accumulator
Definition ScopedTimers.h:58
double Stop()
Definition ScopedTimers.h:45
double Start()
Definition ScopedTimers.h:39
Definition ABTesting.h:112
~FScopedABTimer()
Definition ABTesting.h:122
FScopedABTimer()
Definition ABTesting.h:114
Definition Array.h:670
Definition BitArray.h:350
U16 Index
Definition radfft.cpp:71
Definition RandomStream.h:20