UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LowLevelMemTrackerPrivate.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6
7#if ENABLE_LOW_LEVEL_MEM_TRACKER
8#include "Containers/Array.h"
9#include "Containers/Map.h"
10#include "Containers/Set.h"
12#include "LowLevelMemoryUtils.h"
13
14// Private defines configuring LLM; see also public defines in LowLevelMemTracker.h
15// LLM_ALLOW_NAMES_TAGS: Set to 1 to allow arbitrary FNames to be used as tags, at the cost of more LLM memory usage per allocation. Set to 0 to store only the top-level ELLMTag for each allocation.
16// LLM_SCOPES always use FNames for the definition of their tag
17// Storing these tags on each allocation however requires 4 bytes per allocation
18// To reduce the memory overhead of LLM, this can be reduced to 1 byte per allocation at the cost of showing only the top-level 256 Tags; tags are replaced with their containing toplevel tag during allocation.
19// This setting is ignored if features requiring more information per allocation (LLM_ALLOW_STATS, LLM_ALLOW_ASSETS_TAGS) are enabled
20#ifndef LLM_ALLOW_NAMES_TAGS
21 #define LLM_ALLOW_NAMES_TAGS 1
22#endif
23
24// Enable storing the full tag for each alloc if (1) arbitrary names tags are allowed or (2) Stats are allowed (stats use names tags) or (3) Asset tags are allowed (assets use names tags)
25#define LLM_ENABLED_FULL_TAGS (LLM_ALLOW_NAMES_TAGS || LLM_ALLOW_STATS || LLM_ALLOW_ASSETS_TAGS)
26
27// Whether to enable running with reduced threads. This is currently enabled because the engine crashes with -norenderthread
28#define LLM_ENABLED_REDUCE_THREADS 0
29
30// this controls if the commandline is used to enable tracking, or to disable it. If LLM_COMMANDLINE_ENABLES_FUNCTIONALITY is true,
31// then tracking will only happen through Engine::Init(), at which point it will be disabled unless the commandline tells
32// it to keep going (with -llm). If LLM_COMMANDLINE_ENABLES_FUNCTIONALITY is false, then tracking will be on unless the commandline
33// disables it (with -nollm)
34#ifndef LLM_COMMANDLINE_ENABLES_FUNCTIONALITY
35 #define LLM_COMMANDLINE_ENABLES_FUNCTIONALITY 1
36#endif
37
38// when set to 1, forces LLM to be enabled without having to parse the command line.
39#ifndef LLM_AUTO_ENABLE
40 #define LLM_AUTO_ENABLE 0
41#endif
42
43// There is a little memory and cpu overhead in tracking peak memory but it is generally more useful than current memory.
44// Disable if you need a little more memory or speed
45#define LLM_ENABLED_TRACK_PEAK_MEMORY 1
46
47namespace UE
48{
49namespace LLMPrivate
50{
51 struct FTagDataNameKey
52 {
53 FName Name;
54 ELLMTagSet TagSet;
55
57 Name(InName),
58 TagSet(InTagSet)
59 {
60 }
61
62 friend uint32 GetTypeHash(const FTagDataNameKey& Key)
63 {
64 constexpr uint32 HashPrime = 101;
65 return GetTypeHash(Key.Name) + HashPrime * static_cast<uint32>(Key.TagSet);
66 }
67
68 friend bool operator==(const FTagDataNameKey& A, const FTagDataNameKey& B)
69 {
70 return A.Name == B.Name && A.TagSet == B.TagSet;
71 }
72
73 friend bool operator!=(const FTagDataNameKey& A, const FTagDataNameKey& B)
74 {
75 return (A.Name != B.Name || A.TagSet != B.TagSet);
76 }
77
78 FTagDataNameKey() = delete;
79 };
80
84 class FTagData
85 {
86 public:
87
92 ~FTagData();
93
94 bool IsParentConstructed() const;
95 bool IsFinishConstructed() const;
96 FName GetName() const;
97 FName GetDisplayName() const;
98 void GetDisplayPath(FStringBuilderBase& Result, int32 MaxLen=-1) const;
99 void AppendDisplayPath(FStringBuilderBase& Result, int32 MaxLen=-1) const;
100 const FTagData* GetParent() const;
101 FName GetParentName() const;
103 FName GetStatName() const;
105 ELLMTag GetEnumTag() const;
106 ELLMTagSet GetTagSet() const;
107 bool HasEnumTag() const;
108 const FTagData* GetContainingEnumTagData() const;
111 int32 GetIndex() const;
112 bool IsReportable() const;
113 bool IsStatsReportable() const;
114
115 void SetParent(const FTagData* InParent);
116 void SetIndex(int32 InIndex);
120
121 // These functions are normally invalid - these properties should be immutable - but are called for EnumTags during bootstrapping
123 void SetName(FName InName);
124 void SetDisplayName(FName InDisplayName);
125 void SetStatName(FName InStatName);
127 void SetParentName(FName InParentName);
128
129 private:
130 bool IsUsedAsDisplayParent() const;
131
132 FName Name;
134 union
135 {
136 const FTagData* Parent;
137 FName ParentName;
138 };
139 FName StatName;
141 int32 Index;
144 ELLMTagSet TagSet;
146 bool bParentIsName;
147 bool bHasEnumTag;
148 bool bIsReportable;
149 };
150
151 // TagData container types that use FLLMAllocator
152 class FTagDataNameMap : public TMap<FTagDataNameKey, FTagData*, FDefaultSetLLMAllocator>
153 {
155 };
156 class FConstTagDataArray : public TArray<const FTagData*, FDefaultLLMAllocator>
157 {
159 };
160 class FTagDataArray : public TArray<FTagData*, FDefaultLLMAllocator>
161 {
163 };
164}
165}
166
167// Interface for Algo::TopologicalSort for FTagDataArray
168inline UE::LLMPrivate::FTagData** GetData(UE::LLMPrivate::FTagDataArray& Array)
169{
170 return Array.GetData();
171}
172inline UE::LLMPrivate::FTagDataArray::SizeType GetNum(UE::LLMPrivate::FTagDataArray& Array)
173{
174 return Array.Num();
175}
176
177namespace UE
178{
179namespace LLMPrivate
180{
183 {
184 int64 Size = 0;
185#if LLM_ENABLED_TRACK_PEAK_MEMORY
186 int64 PeakSize = 0;
187#endif
190 bool bExternalValid = false;
191 bool bExternalAddToTotal = false;
192
193 int64 GetSize(UE::LLM::ESizeParams SizeParams) const
194 {
195 int64 CurrentSize = Size;
196
197#if LLM_ENABLED_TRACK_PEAK_MEMORY
198 if (EnumHasAnyFlags(SizeParams, UE::LLM::ESizeParams::ReportPeak))
199 {
200 CurrentSize = PeakSize;
201 }
202#endif
203 // Note, this will also subtract the snapshotted size from PeakSize if that flag is enabled
204 if (EnumHasAnyFlags(SizeParams, UE::LLM::ESizeParams::RelativeToSnapshot))
205 {
206 CurrentSize = FMath::Clamp<int64>(CurrentSize - SizeInSnapshot, 0, INT64_MAX); //-V569
207 }
208
209 return CurrentSize;
210 };
211
212 void CaptureSnapshot()
213 {
215 }
216
217 void ClearSnapshot()
218 {
219 SizeInSnapshot = 0;
220 }
221 };
223
228 struct FThreadTagSizeData
229 {
230 const FTagData* TagData = nullptr;
231 int64 Size = 0;
232 };
233 //
235}
236}
237
239
240#endif // #if ENABLE_LOW_LEVEL_MEM_TRACKER
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
constexpr bool EnumHasAnyFlags(Enum Flags, Enum Contains)
Definition EnumClassFlags.h:35
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:76
auto GetNum(const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Length())
Definition StringConv.h:808
auto GetData(const TStringConversion< Converter, DefaultConversionSize > &Conversion) -> decltype(Conversion.Get())
Definition StringConv.h:802
uint32 Size
Definition VulkanMemory.cpp:4034
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition NameTypes.h:617
Definition Array.h:670
UE_NODEBUG UE_FORCEINLINE_HINT ElementType * GetData() UE_LIFETIMEBOUND
Definition Array.h:1027
Definition UnrealString.h.inl:34
Definition SortedMap.h:20
IMAGECORE_API const TCHAR * GetName(Type Format)
Definition ImageCore.cpp:1378
uint32 GetTypeHash(const FKey &Key)
Definition BlackboardKey.h:35
bool operator==(const FCachedAssetKey &A, const FCachedAssetKey &B)
Definition AssetDataMap.h:501
Definition AdvancedWidgetsModule.cpp:13
@ DisplayName
[ClassMetadata] [PropertyMetadata] [FunctionMetadata] The name to display for this class,...
Definition ObjectMacros.h:1240
U16 Index
Definition radfft.cpp:71