UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ImportantLogScope.inl
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Trace/Config.h"
6#include "ImportantLogScope.h"
7#include "SharedBuffer.h"
10#include "Trace/Detail/Field.h"
12#include "AutoRTFM.h"
13
14namespace UE {
15namespace Trace {
16namespace Private {
17
18#if TRACE_PRIVATE_MINIMAL_ENABLED && TRACE_PRIVATE_ALLOW_IMPORTANTS
19
23
24
25
27template <class T>
29{
30 static_assert(!!(uint32(T::EventFlags) & uint32(FEventInfo::Flag_MaybeHasAux)), "Only important trace events with array-type fields need a size parameter to UE_TRACE_LOG()");
31
32 ArrayDataSize += sizeof(FAuxHeader) * T::EventProps_Meta::NumAuxFields;
33 ArrayDataSize += 1; // for AuxDataTerminal
34
35 uint32 Size = T::GetSize();
36 uint32 Uid = T::GetUid() >> EKnownEventUids::_UidShift;
37 FImportantLogScope Ret = EnterImpl(Uid, Size + ArrayDataSize);
38
39 Ret.AuxCursor += Size;
40 Ret.Ptr[Ret.AuxCursor] = uint8(EKnownEventUids::AuxDataTerminal);
41 return Ret;
42}
43
45template <class T>
46UE_AUTORTFM_ALWAYS_OPEN inline FImportantLogScope FImportantLogScope::Enter()
47{
48 static_assert(!(uint32(T::EventFlags) & uint32(FEventInfo::Flag_MaybeHasAux)), "Important trace events with array-type fields must be traced with UE_TRACE_LOG(Logger, Event, Channel, ArrayDataSize)");
49
50 uint32 Size = T::GetSize();
51 uint32 Uid = T::GetUid() >> EKnownEventUids::_UidShift;
52 return EnterImpl(Uid, Size);
53}
54
56UE_AUTORTFM_ALWAYS_OPEN inline FImportantLogScope FImportantLogScope::EnterImpl(uint32 Uid, uint32 Size)
57{
59
60 int32 AllocSize = Size;
61 AllocSize += sizeof(FImportantEventHeader);
62
63 // Claim some space in the buffer
64 int32 NegSizeAndRef = 0 - ((AllocSize << FSharedBuffer::CursorShift) | FSharedBuffer::RefBit);
66
68 {
70 Buffer = Next.Buffer;
71 RegionStart = Next.RegionStart;
72 }
73
74 int32 Bias = (RegionStart >> FSharedBuffer::CursorShift);
75 uint8* Out = (uint8*)Buffer - Bias;
76
77 // Event header
78 uint16 Values16[] = { uint16(Uid), uint16(Size) };
79 memcpy(Out, Values16, sizeof(Values16)); /* FImportantEventHeader::Uid,Size */
80
81 FImportantLogScope Ret;
82 Ret.Ptr = Out + sizeof(FImportantEventHeader);
83 Ret.BufferOffset = int32(PTRINT(Buffer) - PTRINT(Ret.Ptr));
84 Ret.AuxCursor = 0;
85 return Ret;
86}
87
89UE_AUTORTFM_ALWAYS_OPEN inline void FImportantLogScope::operator += (const FImportantLogScope& Other) const
90{
91 auto* Buffer = (FSharedBuffer*)(Ptr + BufferOffset);
92 AtomicAddRelease(&(Buffer->Cursor), int32(FSharedBuffer::RefBit));
93}
94
96template <typename FieldMeta, typename Type>
97struct FImportantLogScope::FFieldSet
98{
100 static void Impl(FImportantLogScope* Scope, const Type& Value)
101 {
102 uint8* Dest = (uint8*)(Scope->Ptr) + FieldMeta::Offset;
103 ::memcpy(Dest, &Value, sizeof(Type));
104 }
105};
106
108template <typename FieldMeta, typename Type>
109struct FImportantLogScope::FFieldSet<FieldMeta, Type[]>
110{
112 static void Impl(FImportantLogScope* Scope, Type const* Data, int32 Num)
113 {
114 uint32 Size = Num * sizeof(Type);
115
116 uint32 Pack = Size << FAuxHeader::SizeShift;
117 Pack |= (FieldMeta::Index & int32(EIndexPack::NumFieldsMask)) << FAuxHeader::FieldShift;
118
119 uint8* Out = Scope->Ptr + Scope->AuxCursor;
120 memcpy(Out, &Pack, sizeof(Pack)); /* FAuxHeader::Pack */
121 Out[0] = uint8(EKnownEventUids::AuxData); /* FAuxHeader::Uid */
122
123 memcpy(Out + sizeof(FAuxHeader), Data, Size);
124
125 Scope->AuxCursor += sizeof(FAuxHeader) + Size;
126 Scope->Ptr[Scope->AuxCursor] = uint8(EKnownEventUids::AuxDataTerminal);
127 }
128};
129
131template <typename FieldMeta>
132struct FImportantLogScope::FFieldSet<FieldMeta, AnsiString>
133{
135 static void Impl(FImportantLogScope* Scope, const ANSICHAR* String, int32 Length=-1)
136 {
137 if (Length < 0)
138 {
139 Length = int32(strlen(String));
140 }
141
142 uint32 Pack = Length << FAuxHeader::SizeShift;
143 Pack |= (FieldMeta::Index & int32(EIndexPack::NumFieldsMask)) << FAuxHeader::FieldShift;
144
145 uint8* Out = Scope->Ptr + Scope->AuxCursor;
146 memcpy(Out, &Pack, sizeof(Pack)); /* FAuxHeader::FieldIndex_Size */
147 Out[0] = uint8(EKnownEventUids::AuxData); /* FAuxHeader::Uid */
148
149 memcpy(Out + sizeof(FAuxHeader), String, Length);
150
151 Scope->AuxCursor += sizeof(FAuxHeader) + Length;
152 Scope->Ptr[Scope->AuxCursor] = uint8(EKnownEventUids::AuxDataTerminal);
153 }
154
156 static void Impl(FImportantLogScope* Scope, const WIDECHAR* String, int32 Length=-1)
157 {
158 if (Length < 0)
159 {
160 Length = 0;
161 for (const WIDECHAR* c = String; *c; ++c, ++Length);
162 }
163
164 uint32 Pack = Length << FAuxHeader::SizeShift;
165 Pack |= (FieldMeta::Index & int32(EIndexPack::NumFieldsMask)) << FAuxHeader::FieldShift;
166
167 uint8* Out = Scope->Ptr + Scope->AuxCursor;
168 memcpy(Out, &Pack, sizeof(Pack)); /* FAuxHeader::FieldIndex_Size */
169 Out[0] = uint8(EKnownEventUids::AuxData); /* FAuxHeader::Uid */
170
171 Out += sizeof(FAuxHeader);
172 for (int32 i = 0; i < Length; ++i)
173 {
174 *Out = int8(*String);
175 ++Out;
176 ++String;
177 }
178
179 Scope->AuxCursor += sizeof(FAuxHeader) + Length;
180 Scope->Ptr[Scope->AuxCursor] = uint8(EKnownEventUids::AuxDataTerminal);
181 }
182};
183
185template <typename FieldMeta>
186struct FImportantLogScope::FFieldSet<FieldMeta, WideString>
187{
189 static void Impl(FImportantLogScope* Scope, const WIDECHAR* String, int32 Length=-1)
190 {
191 if (Length < 0)
192 {
193 Length = 0;
194 for (const WIDECHAR* c = String; *c; ++c, ++Length);
195 }
196
197 uint32 Size = Length * sizeof(WIDECHAR);
198
199 uint32 Pack = Size << FAuxHeader::SizeShift;
200 Pack |= (FieldMeta::Index & int32(EIndexPack::NumFieldsMask)) << FAuxHeader::FieldShift;
201
202 uint8* Out = Scope->Ptr + Scope->AuxCursor;
203 memcpy(Out, &Pack, sizeof(Pack));
204 Out[0] = uint8(EKnownEventUids::AuxData);
205
206 memcpy(Out + sizeof(FAuxHeader), String, Size);
207
208 Scope->AuxCursor += sizeof(FAuxHeader) + Size;
209 Scope->Ptr[Scope->AuxCursor] = uint8(EKnownEventUids::AuxDataTerminal);
210 }
211};
212
214template <typename FieldMeta, typename DefinitionType>
215struct FImportantLogScope::FFieldSet<FieldMeta, TEventRef<DefinitionType>>
216{
218 static void Impl(FImportantLogScope* Scope, const TEventRef<DefinitionType>& Reference)
219 {
221 }
222};
223
224#else // TRACE_PRIVATE_MINIMAL_ENABLED && TRACE_PRIVATE_ALLOW_IMPORTANTS
225
226
227template <typename FieldMeta, typename Type>
229{
230 static void Impl(FImportantLogScope* Scope, const Type& Value)
231 {
232 }
233};
234
235template <typename FieldMeta, typename Type>
237{
238 static void Impl(FImportantLogScope* Scope, Type const* Data, int32 Num)
239 {
240 }
241};
242
243template <typename FieldMeta>
245{
246 static void Impl(FImportantLogScope* Scope, const ANSICHAR* String, int32 Length=-1)
247 {
248 }
249
250 static void Impl(FImportantLogScope* Scope, const WIDECHAR* String, int32 Length=-1)
251 {
252 }
253};
254
255template <typename FieldMeta>
257{
258 static void Impl(FImportantLogScope* Scope, const WIDECHAR* String, int32 Length=-1)
259 {
260 }
261};
262
263template <typename FieldMeta, typename DefinitionType>
265{
266 static void Impl(FImportantLogScope* Scope, const TEventRef<DefinitionType>& Reference)
267 {
268 }
269};
270
271
272#endif // TRACE_PRIVATE_MINIMAL_ENABLED && TRACE_PRIVATE_ALLOW_IMPORTANTS
273
274} // namespace Private
275} // namespace Trace
276} // namespace UE
277
278
#define FORCENOINLINE
Definition AndroidPlatform.h:142
#define UE_AUTORTFM_ALWAYS_OPEN
Definition AutoRTFMDefines.h:114
FPlatformTypes::int8 int8
An 8-bit signed integer.
Definition Platform.h:1121
FPlatformTypes::PTRINT PTRINT
A signed integer the same size as a pointer.
Definition Platform.h:1148
FPlatformTypes::WIDECHAR WIDECHAR
A wide character. Normally a signed type.
Definition Platform.h:1133
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define UNLIKELY(x)
Definition Platform.h:857
FPlatformTypes::ANSICHAR ANSICHAR
An ANSI character. Normally a signed type.
Definition Platform.h:1131
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
@ Num
Definition MetalRHIPrivate.h:234
uint32 Size
Definition VulkanMemory.cpp:4034
memcpy(InputBufferBase, BinkBlocksData, BinkBlocksSize)
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition SharedBuffer.h:341
Definition ImportantLogScope.h:38
void operator+=(const FImportantLogScope &) const
static FImportantLogScope Enter()
Definition ImportantLogScope.h:41
@ Trace
Definition NetTraceConfig.h:23
Type
Definition PawnAction_Move.h:11
Definition ExpressionParserTypes.h:21
Definition OverriddenPropertySet.cpp:45
bool Pack(uint8 *OutBuf, const SIZE_T BufSize, const FUdpPingPacket &Packet)
Definition UDPPing.cpp:1134
Type AtomicAddRelaxed(Type volatile *Target, Type Value)
Definition Atomic.h:131
Type AtomicLoadAcquire(Type volatile *Source)
Definition Atomic.h:67
Type AtomicAddRelease(Type volatile *Target, Type Value)
Definition Atomic.h:147
@ Reference
Definition Protocol6.h:40
@ Bias
Definition Transport.h:27
AnsiString
Definition Trace.h:52
WideString
Definition Trace.h:53
Definition AdvancedWidgetsModule.cpp:13
static void Impl(FImportantLogScope *Scope, const ANSICHAR *String, int32 Length=-1)
Definition ImportantLogScope.inl:246
static void Impl(FImportantLogScope *Scope, const WIDECHAR *String, int32 Length=-1)
Definition ImportantLogScope.inl:250
static void Impl(FImportantLogScope *Scope, const TEventRef< DefinitionType > &Reference)
Definition ImportantLogScope.inl:266
static void Impl(FImportantLogScope *Scope, Type const *Data, int32 Num)
Definition ImportantLogScope.inl:238
static void Impl(FImportantLogScope *Scope, const WIDECHAR *String, int32 Length=-1)
Definition ImportantLogScope.inl:258
Definition ImportantLogScope.inl:229
static void Impl(FImportantLogScope *Scope, const Type &Value)
Definition ImportantLogScope.inl:230
Definition Trace.h:58