UDocumentation
UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
OpenHashThrottler.h
Go to the documentation of this file.
1
// Copyright Epic Games, Inc. All Rights Reserved.
2
3
#pragma once
4
5
#if (defined(__AUTORTFM) && __AUTORTFM)
6
7
#include "
HashMap.h
"
8
9
namespace
AutoRTFM
10
{
11
12
// Forward declaration
13
class
FWriteLog
;
14
27
class
FOpenHashThrottler
28
{
29
public
:
30
using
FSeconds =
double
;
31
33
class
FHashScope
34
{
35
public
:
36
// Constructor - Begins timing a validation hash.
37
// * Throttler is the AutoRTFM FOpenHashThrottler.
38
// * OpenReturnAddress is the return address for the call to AutoRTFM::Open(). Used to identify the open.
39
// * WriteLog is the write log that is being hashed. Used only for statistics logging.
40
FHashScope
(
FOpenHashThrottler
& Throttler,
const
void
*
OpenReturnAddress
,
const
FWriteLog
&
WriteLog
);
41
~FHashScope
();
42
private
:
43
FOpenHashThrottler
& Throttler;
44
const
FWriteLog
&
WriteLog
;
45
const
void
*
const
OpenReturnAddress
;
46
FSeconds StartTime;
47
};
48
49
// Constructor
50
// * LogInterval is time between each statistics log
51
// * AdjustThrottleInterval is time between adjustments to hash probabilities.
52
// * TargetFractionHashing is target fraction of time spent hashing / total time.
53
FOpenHashThrottler
(FSeconds
LogInterval
, FSeconds
AdjustThrottleInterval
, FSeconds
TargetFractionHashing
);
54
55
// Returns the probability (0: never hash, 1: always hash) the given open return address should be hashed.
56
// * OpenReturnAddress is the return address for the call to AutoRTFM::Open(). Used to identify the open.
57
double
HashProbabilityFor
(
const
void
*
OpenReturnAddress
);
58
59
// Returns true if the open with the given return address should perform memory validation.
60
// * OpenReturnAddress is the return address for the call to AutoRTFM::Open(). Used to identify the open.
61
bool
ShouldHashFor
(
const
void
*
OpenReturnAddress
);
62
63
// Updates the profiler with timings for an open hash.
64
// * HashStart is the wall-clock time before hashing begun
65
// * HashStart is the wall-clock time after hashing ended
66
// * OpenReturnAddress is the return address for the call to AutoRTFM::Open(). Used to identify the open.
67
// * WriteLog is the write log that is being hashed. Used only for statistics logging.
68
void
OnHash
(FSeconds
HashStart
, FSeconds
HashEnd
,
const
void
*
OpenReturnAddress
,
const
FWriteLog
&
WriteLog
);
69
70
// Periodically adjusts the probabilities for hashing opens, and prints statistics.
71
// * DeltaTime the time since the last call to Update(), or 0 to calculate using an internal clock.
72
void
Update
(FSeconds DeltaTime = 0);
73
74
private
:
75
void
UpdateThrottlingData
();
76
void
UpdateLogStats
();
77
78
struct
FOpenAddressInfo
79
{
80
// Total time spent hashing this open since last reset.
81
FSeconds
TimeSpentHashing
= 0;
82
// Throttled probability to hash this open.
83
double
Probability = 0;
84
// True if the open address was queried or hashed since last throttling update.
85
bool
bActive =
true
;
86
};
87
88
// Data used for throttling hashing
89
struct
FThrottlingData
90
{
91
// Timestamp since this was last updated.
92
FSeconds TimeSinceLastUpdate = 0;
93
// Total time spent hashing for all opens since last reset.
94
FSeconds
TotalTimeSpentHashing
= 0;
95
// A map of open return address to open info.
96
THashMap<const void*, FOpenAddressInfo>
Opens
;
97
// The default hash probability if the open return address is not found
98
// in Opens.
99
double
DefaultHashProbability
= 1;
100
};
101
102
// Statistics for logging
103
struct
FLogStats
104
{
105
// Timestamp since this was last reset.
106
FSeconds
TimeSinceLastReset
= 0;
107
// Total time spent hashing since last reset.
108
FSeconds
TimeSpentHashing
= 0;
109
// Number of hash calls since last reset.
110
size_t
NumHashCalls
= 0;
111
// Number of bytes hashed since last reset.
112
size_t
NumBytesHashed
= 0;
113
// Number of write records hashed since last reset.
114
size_t
NumWriteRecords
= 0;
115
// Number of times ShouldHashFor() return true.
116
size_t
NumShouldHashForTrue
= 0;
117
// Number of times ShouldHashFor() return false.
118
size_t
NumShouldHashForFalse
= 0;
119
};
120
121
const
FSeconds
LogInterval
;
122
const
FSeconds
AdjustThrottleInterval
;
123
const
FSeconds
TargetFractionHashing
;
124
125
FThrottlingData
ThrottlingData
;
126
FLogStats
LogStats;
127
FSeconds LastUpdateTimestamp = 0;
128
};
129
130
}
// namespace AutoRTFM
131
132
#endif
// (defined(__AUTORTFM) && __AUTORTFM)
StaticCastSharedRef
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition
SharedPointer.h:127
HashMap.h
EAccelerationStructureBuildMode::Update
@ Update
AutoRTFM
Definition
API.cpp:57
Engine
Source
Runtime
AutoRTFM
Private
OpenHashThrottler.h
Generated by
1.9.8