UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
NetworkMetricsDatabase.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "NetworkMetricsDatabase.generated.h"
7
8#define UE_API ENGINE_API
9
11
12template<typename BaseStructT>
14
15namespace UE::Net
16{
17
18template<class MetricType>
24
36
37} // namespace UE::Net
38
39UCLASS(MinimalAPI)
41{
43
44public:
45 /* Add a floating point metric. */
46 UE_API void CreateFloat(const FName MetricName, float DefaultValue);
47 /* Add an integer metric. */
48 UE_API void CreateInt(const FName MetricName, int64 DefaultValue);
49 /* Set the value of an existing floating point metric. */
50 UE_API bool SetFloat(const FName MetricName, float Value);
51 /* Set the value of a floating point metric if it's smaller than the existing value. */
52 UE_API bool SetMinFloat(const FName MetricName, float Value);
53 /* Set the value of a floating point metric if it's bigger than the existing value. */
54 UE_API bool SetMaxFloat(const FName MetricName, float Value);
56 UE_API float GetFloat(const FName MetricName);
57 /* Set the value of an existing integer metric. */
58 UE_API bool SetInt(const FName MetricName, int64 Value);
59 /* Set the value of an integer metric if it's smaller than the existing value. */
60 UE_API bool SetMinInt(const FName MetricName, int64 Value);
61 /* Set the value of an integer metric if it's bigger than the existing value. */
62 UE_API bool SetMaxInt(const FName MetricName, int64 Value);
63 /* Increment the value of an existing integer metric. */
64 UE_API bool IncrementInt(const FName MetricName, int64 Value);
66 UE_API int64 GetInt(const FName MetricName);
67 /* Returns true if a metric has been created in the database. */
68 UE_API bool Contains(const FName MetricName) const;
69
70 /* Call all registered listeners.*/
71 UE_API void ProcessListeners();
72 /* Remove all registered metrics and listeners. */
73 UE_API void Reset();
74 /* Remove all registered listeners. */
75 UE_API void ResetListeners();
76
77 /* Register a listener to be called for a given metric. */
79
80 /* Register a mutator with a listener. */
82
83private:
84 /* Return true if the report interval time for a listener has elapsed, and update its last reported time if it has. */
85 bool HasReportIntervalPassed(double CurrentTimeSeconds, UNetworkMetricsBaseListener* Listener);
86
87 enum class EMetricType { Integer, Float };
88
89 void AddMetricToSnapshot(UE::Net::FNetworkMetricSnapshot& Snapshot, const FName MetricName, const EMetricType MetricType);
90
91 TMap<FName, EMetricType> MetricTypes;
92
95
97
98 /* The time, in seconds, metrics were reported to a listener. */
99 TMap<TWeakObjectPtr<UNetworkMetricsBaseListener>, double> LastReportListener;
100
101 // Map of listeners to metrics registered with them. A listener may have an entry with an empty set if it has no metrics but some mutators registered. */
103};
104
154UCLASS(MinimalAPI, abstract, Config=Engine)
156{
158
159public:
162
163 /* Set the interval, in seconds, between calling Report(). */
164 void SetInterval(double Seconds)
165 {
166 if (ensureMsgf(Seconds >= 0, TEXT("SetInterval() called with a negative time interval.")))
167 {
168 IntervalSeconds = Seconds;
169 }
170 }
171
172 /* Get the interval, in seconds, between calling Report(). */
173 double GetInterval() const
174 {
175 return IntervalSeconds;
176 }
177
179 {
180 return Mutators;
181 }
182
187
189
190private:
191 UPROPERTY(Config)
192 double IntervalSeconds;
193
195 UPROPERTY()
197};
198
212UCLASS(MinimalAPI)
214{
216
217public:
218 virtual ~UNetworkMetricsLog() = default;
219
220 UE_API virtual void Report(const UE::Net::FNetworkMetricSnapshot& Snapshot);
221};
222
253UCLASS(MinimalAPI)
255{
257
258public:
260 virtual ~UNetworkMetricsCSV() = default;
261
262 /* Set the CSV category. */
263 UE_API void SetCategory(const FString& CategoryName);
264
265 UE_API virtual void Report(const UE::Net::FNetworkMetricSnapshot& Snapshot);
266
267private:
268 int32 CategoryIndex;
269};
270
272UCLASS(MinimalAPI)
274{
276
277public:
279 {
280 SetCategory("Replication");
281 }
282
284};
285
294UCLASS(MinimalAPI)
296{
298
299public:
300 virtual ~UNetworkMetricsPerfCounters() = default;
301
302 UE_API virtual void Report(const UE::Net::FNetworkMetricSnapshot& Snapshot);
303};
304
317UCLASS(MinimalAPI)
319{
321
322public:
324 virtual ~UNetworkMetricsStats() = default;
325
328 {
329 StatName = Name;
330 }
331
332 UE_API virtual void Report(const UE::Net::FNetworkMetricSnapshot& Snapshot);
333
334private:
335 FName StatName;
336};
337
338#undef UE_API
#define ensureMsgf( InExpression, InFormat,...)
Definition AssertionMacros.h:465
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_API
Definition NetworkMetricsDatabase.h:8
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UCLASS(...)
Definition ObjectMacros.h:776
Definition Engine.Build.cs:7
Definition NameTypes.h:617
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition NetworkMetricsDatabase.h:156
double GetInterval() const
Definition NetworkMetricsDatabase.h:173
virtual void Report(const UE::Net::FNetworkMetricSnapshot &Snapshot)
Definition NetworkMetricsDatabase.h:188
void SetInterval(double Seconds)
Definition NetworkMetricsDatabase.h:164
const TArray< TInstancedStruct< FNetworkMetricsMutator > > & GetMutators() const
Definition NetworkMetricsDatabase.h:178
virtual ~UNetworkMetricsBaseListener()
TArray< TInstancedStruct< FNetworkMetricsMutator > > & GetMutators()
Definition NetworkMetricsDatabase.h:183
Definition NetworkMetricsDatabase.h:274
UNetworkMetricsCSV_Replication()
Definition NetworkMetricsDatabase.h:278
virtual ~UNetworkMetricsCSV_Replication()=default
Definition NetworkMetricsDatabase.h:255
virtual ~UNetworkMetricsCSV()=default
Definition NetworkMetricsDatabase.h:41
Definition NetworkMetricsDatabase.h:214
virtual ~UNetworkMetricsLog()=default
Definition NetworkMetricsDatabase.h:296
virtual ~UNetworkMetricsPerfCounters()=default
Definition NetworkMetricsDatabase.h:319
void SetStatName(const FName Name)
Definition NetworkMetricsDatabase.h:327
virtual ~UNetworkMetricsStats()=default
Definition Object.h:95
Definition NetworkVersion.cpp:28
Definition NetworkMetricsMutators.h:28
Definition InstancedStruct.h:307
Definition Tuple.h:652
Definition WeakObjectPtrTemplates.h:25
Definition NetworkMetricsDatabase.h:26
void Reset()
Definition NetworkMetricsDatabase.h:30
TArray< FNetworkMetric< int64 > > MetricInts
Definition NetworkMetricsDatabase.h:27
TArray< FNetworkMetric< float > > MetricFloats
Definition NetworkMetricsDatabase.h:28
Definition NetworkMetricsDatabase.h:20
MetricType Value
Definition NetworkMetricsDatabase.h:22
FName Name
Definition NetworkMetricsDatabase.h:21