UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MiscTrace.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "CoreTypes.h"
8#include "Misc/Build.h"
11#include "Trace/Config.h"
12
13#if !defined(MISCTRACE_ENABLED)
14#if UE_TRACE_ENABLED && !UE_BUILD_SHIPPING
15#define MISCTRACE_ENABLED 1
16#else
17#define MISCTRACE_ENABLED 0
18#endif
19#endif
20
21#ifndef FRAME_TRACE_ENABLED
22#define FRAME_TRACE_ENABLED MISCTRACE_ENABLED
23#endif
24
26
34
36{
37 static void Encode7bit(uint64 Value, uint8*& BufferPtr)
38 {
39 // Writes 1 to 10 bytes for uint64 and 1 to 5 bytes for uint32.
40 do
41 {
42 uint8 HasMoreBytes = (uint8)((Value > uint64(0x7F)) << 7);
43 *(BufferPtr++) = (uint8)(Value & 0x7F) | HasMoreBytes;
44 Value >>= 7;
45 } while (Value > 0);
46 }
47
48 static void EncodeZigZag(int64 Value, uint8*& BufferPtr)
49 {
50 Encode7bit((Value << 1) ^ (Value >> 63), BufferPtr);
51 }
52};
53
54class FName;
55
57{
58 CORE_API static void OutputBookmarkSpec(const void* BookmarkPoint, const ANSICHAR* File, int32 Line, const TCHAR* Format);
59
60 template <typename... Types>
70
71 template <typename... Types>
81
82 CORE_API static void OutputBeginRegion(const TCHAR* RegionName, const TCHAR* Category = nullptr);
83 [[nodiscard]] CORE_API static uint64 OutputBeginRegionWithId(const TCHAR* RegionName, const TCHAR* Category = nullptr);
84 CORE_API static void OutputEndRegion(const TCHAR* RegionName);
85 CORE_API static void OutputEndRegionWithId(uint64 RegionId);
86
89
90 CORE_API static void OutputScreenshot(const TCHAR* Name, uint64 Cycle, uint32 Width, uint32 Height, TArray64<uint8> Data);
91 CORE_API static bool ShouldTraceScreenshot();
92 CORE_API static bool ShouldTraceBookmark();
93 CORE_API static bool ShouldTraceRegion();
94
95 template <typename... Types>
96 UE_DEPRECATED(5.6, "Use OutputBookmark that has CallstackId parameter")
101
102 template <typename... Types>
103 UE_DEPRECATED(5.6, "Use OutputBookmarkCycles that has CallstackId parameter")
108
109private:
110 CORE_API static void OutputBookmarkInternal(const void* BookmarkPoint, uint32 CallstackId, uint16 EncodedFormatArgsSize, uint8* EncodedFormatArgs);
111 CORE_API static void OutputBookmarkInternalCycles(uint64 Cycles, const void* BookmarkPoint, uint32 CallstackId, uint16 EncodedFormatArgsSize, uint8* EncodedFormatArgs);
112};
113
114#if MISCTRACE_ENABLED
115
116#define TRACE_BOOKMARK(Format, ...) \
117if (UE_TRACE_CHANNELEXPR_IS_ENABLED(BookmarkChannel)) \
118{ \
119 static bool PREPROCESSOR_JOIN(__BookmarkPoint, __LINE__); \
120 if (!PREPROCESSOR_JOIN(__BookmarkPoint, __LINE__)) \
121 { \
122 static_assert(std::is_const_v<std::remove_reference_t<decltype(Format)>>, "Formatting string must be a const TCHAR array."); \
123 static_assert(TIsArrayOrRefOfTypeByPredicate<decltype(Format), TIsCharEncodingCompatibleWithTCHAR>::Value, "Formatting string must be a TCHAR array."); \
124 UE_VALIDATE_FORMAT_STRING(Format, ##__VA_ARGS__); \
125 FMiscTrace::OutputBookmarkSpec(&PREPROCESSOR_JOIN(__BookmarkPoint, __LINE__), __FILE__, __LINE__, Format); \
126 PREPROCESSOR_JOIN(__BookmarkPoint, __LINE__) = true; \
127 } \
128 FMiscTrace::OutputBookmark(CallstackTrace_GetCurrentId(), &PREPROCESSOR_JOIN(__BookmarkPoint, __LINE__), ##__VA_ARGS__); \
129}
130
131#define TRACE_BOOKMARK_CYCLES(Cycles, Format, ...) \
132if (UE_TRACE_CHANNELEXPR_IS_ENABLED(BookmarkChannel)) \
133{ \
134 static bool PREPROCESSOR_JOIN(__BookmarkPoint, __LINE__); \
135 if (!PREPROCESSOR_JOIN(__BookmarkPoint, __LINE__)) \
136 { \
137 static_assert(std::is_const_v<std::remove_reference_t<decltype(Format)>>, "Formatting string must be a const TCHAR array."); \
138 static_assert(TIsArrayOrRefOfTypeByPredicate<decltype(Format), TIsCharEncodingCompatibleWithTCHAR>::Value, "Formatting string must be a TCHAR array."); \
139 UE_VALIDATE_FORMAT_STRING(Format, ##__VA_ARGS__); \
140 FMiscTrace::OutputBookmarkSpec(&PREPROCESSOR_JOIN(__BookmarkPoint, __LINE__), __FILE__, __LINE__, Format); \
141 PREPROCESSOR_JOIN(__BookmarkPoint, __LINE__) = true; \
142 } \
143 FMiscTrace::OutputBookmarkCycles(CallstackTrace_GetCurrentId(), Cycles, &PREPROCESSOR_JOIN(__BookmarkPoint, __LINE__), ##__VA_ARGS__); \
144}
145
157#define TRACE_BEGIN_REGION(RegionName, ...) \
158FMiscTrace::OutputBeginRegion(RegionName __VA_OPT__(,) __VA_ARGS__);
159
171#define TRACE_BEGIN_REGION_WITH_ID(RegionName, ...) \
172FMiscTrace::OutputBeginRegionWithId(RegionName __VA_OPT__(,) __VA_ARGS__);
173
174#define TRACE_END_REGION(RegionName) \
175 FMiscTrace::OutputEndRegion(RegionName);
176
177#define TRACE_END_REGION_WITH_ID(RegionId) \
178 FMiscTrace::OutputEndRegionWithId(RegionId);
179
180#define TRACE_SCREENSHOT(Name, Cycle, Width, Height, Data) \
181 FMiscTrace::OutputScreenshot(Name, Cycle, Width, Height, Data);
182
183#define SHOULD_TRACE_SCREENSHOT() \
184 FMiscTrace::ShouldTraceScreenshot()
185
186#define SHOULD_TRACE_BOOKMARK() \
187 FMiscTrace::ShouldTraceBookmark()
188
189#define SHOULD_TRACE_REGION() \
190 FMiscTrace::ShouldTraceRegion()
191
192#else
193
194#define TRACE_BOOKMARK(...)
195#define TRACE_BOOKMARK_CYCLES(...)
196#define TRACE_BEGIN_REGION(...)
197#define TRACE_BEGIN_REGION_WITH_ID(...) 0;
198#define TRACE_END_REGION(...)
199#define TRACE_END_REGION_WITH_ID(...)
200#define TRACE_SCREENSHOT(...)
201#define SHOULD_TRACE_SCREENSHOT(...) false
202#define SHOULD_TRACE_BOOKMARK(...) false
203#define SHOULD_TRACE_REGION(...) false
204
205#endif // MISCTRACE_ENABLED
206
207#if FRAME_TRACE_ENABLED
208
209#define TRACE_BEGIN_FRAME(FrameType) \
210FMiscTrace::OutputBeginFrame(FrameType);
211
212#define TRACE_END_FRAME(FrameType) \
213FMiscTrace::OutputEndFrame(FrameType);
214
215#else
216
217#define TRACE_BEGIN_FRAME(...)
218#define TRACE_END_FRAME(...)
219
220#endif // FRAME_TRACE_ENABLED
uint32 CallstackTrace_GetCurrentId()
Definition CallstackTrace.h:113
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::ANSICHAR ANSICHAR
An ANSI character. Normally a signed type.
Definition Platform.h:1131
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
ETraceFrameType
Definition MiscTrace.h:28
@ TraceFrameType_Game
Definition MiscTrace.h:29
@ TraceFrameType_Count
Definition MiscTrace.h:32
@ TraceFrameType_Rendering
Definition MiscTrace.h:30
#define UE_TRACE_CHANNEL_EXTERN(ChannelName,...)
Definition Trace.h:448
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 NameTypes.h:617
static uint16 EncodeArguments(uint8(&Buffer)[BufferSize], Types... FormatArgs)
Definition FormatArgsTrace.h:49
Definition MiscTrace.h:57
static void OutputBookmark(uint32 CallstackId, const void *BookmarkPoint, Types... FormatArgs)
Definition MiscTrace.h:61
static CORE_API uint64 OutputBeginRegionWithId(const TCHAR *RegionName, const TCHAR *Category=nullptr)
Definition MiscTrace.cpp:98
static CORE_API bool ShouldTraceScreenshot()
Definition MiscTrace.cpp:198
static CORE_API void OutputScreenshot(const TCHAR *Name, uint64 Cycle, uint32 Width, uint32 Height, TArray64< uint8 > Data)
Definition MiscTrace.cpp:162
static CORE_API void OutputBeginFrame(ETraceFrameType FrameType)
Definition MiscTrace.cpp:136
static CORE_API void OutputEndRegion(const TCHAR *RegionName)
Definition MiscTrace.cpp:108
static CORE_API void OutputEndRegionWithId(uint64 RegionId)
Definition MiscTrace.cpp:115
static CORE_API void OutputBeginRegion(const TCHAR *RegionName, const TCHAR *Category=nullptr)
Definition MiscTrace.cpp:90
static CORE_API bool ShouldTraceRegion()
Definition MiscTrace.cpp:208
static CORE_API void OutputBookmarkSpec(const void *BookmarkPoint, const ANSICHAR *File, int32 Line, const TCHAR *Format)
Definition MiscTrace.cpp:77
static CORE_API void OutputEndFrame(ETraceFrameType FrameType)
Definition MiscTrace.cpp:149
static CORE_API bool ShouldTraceBookmark()
Definition MiscTrace.cpp:203
static void OutputBookmarkCycles(uint32 CallstackId, uint64 Cycles, const void *BookmarkPoint, Types... FormatArgs)
Definition MiscTrace.h:72
Definition MiscTrace.h:36
static void Encode7bit(uint64 Value, uint8 *&BufferPtr)
Definition MiscTrace.h:37
static void EncodeZigZag(int64 Value, uint8 *&BufferPtr)
Definition MiscTrace.h:48