UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMSamplingProfiler.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if WITH_VERSE_VM || defined(__INTELLISENSE__)
6
7#include "Async/EventCount.h"
8#include "Containers/Set.h"
9#include "HAL/Runnable.h"
10#include "HAL/RunnableThread.h"
11#include "Templates/UniquePtr.h"
12#include "VerseVM/VVMContext.h"
13#include "VerseVM/VVMFrame.h"
15#include "VerseVM/VVMTask.h"
16
17#include "Trace/Config.h"
19#include "Trace/Trace.h"
20
21namespace Verse
22{
23// Enabled via cmd-line arg `-trace=verse` passed to the program being sampled
25
26struct FSampledFrame
27{
30 bool bIsNativeCall{false};
32 uint32 BytecodeOffset;
33 uint64 Cycles;
35 {
36 MarkStack.MarkNonNull(Task.Get());
37 MarkStack.MarkNonNull(Frame.Get());
38 for (uint32 Index = 0; Index < NativeFrameCallstack.Num(); ++Index)
39 {
41 }
42 }
43};
44
45struct FVerseSample
46{
47 uint32 Hits = 0u;
48 TArray<VUniqueString*> Callstack;
49 TArray<TPair</*StartCycle*/ uint64, /*ApproxCycles*/ uint64>> Cycles;
50 TMap<TPair</*bytecodeoffset*/ uint32, /*line*/ uint32>, uint32> BytecodeHits;
51 bool operator==(const FVerseSample& Other) const
52 {
53 return Callstack == Other.Callstack;
54 }
55};
56
57inline uint32 GetTypeHash(const FVerseSample& Sample)
58{
59 return GetTypeHash(Sample.Callstack);
60}
61
62// - TODO: No longer assume a single mutator. Maybe this is OK in a UEFN context, but it quickly becomes
63// not OK if we end up running the VM with multiple mutators
64// - TODO: Redact non-user visible callstacks
65struct FSamplingProfiler final : FRunnable
66{
68 void Pause() { bPauseRequested.store(true, std::memory_order_seq_cst); }
69
70 FSamplingProfiler() { Start(); };
72
73 // FRunnable Interface
74 COREUOBJECT_API uint32 Run() override;
75 void Stop() override { bStopRequested.store(true, std::memory_order_seq_cst); }
76 COREUOBJECT_API void Exit() override;
77 // ~FRunnable Interface
78
80
81 // Non GC calls to process samples need to lock the GC mutex first
83
85
86 // This only work in debug builds atm... reason why is not clear.
88
89 FRunningContext* MutatorContext{nullptr}; // We need this to PairHandshake
90
93
95
96 // We cache these so we can re-use the processed callstacks from them
97 // when sampling. They are removed in FNativeFrame's dtor
99
101
102 bool bIsRunning = false;
103 std::atomic<bool> bStopRequested = false;
104 std::atomic<bool> bPauseRequested = false;
106
107 // Used to trace the strings already emitted to insights this session
108 // TODO: Reset these upon a new insights connection
111
113 TPair</*StartCycle*/ uint64, /*ApproxCycles*/ uint64>* PreviousSampleTimeEntry{nullptr};
114};
115
119
120} // namespace Verse
121
122#endif
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
@ Stop
Definition PrecomputedVolumetricLightmapStreaming.cpp:26
#define UE_TRACE_MINIMAL_CHANNEL_EXTERN(ChannelName,...)
Definition Trace.h:475
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Runnable.h:20
Definition Array.h:670
Definition UnrealString.h.inl:34
Definition UniquePtr.h:107
Definition Mutex.h:18
void Sample(float *Dst, float X, float Y, float Z)
Definition FieldSystemNoiseAlgo.cpp:59
int WaitEvent(void *p_os_event_mem, int timeout)
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
bool operator==(const FCachedAssetKey &A, const FCachedAssetKey &B)
Definition AssetDataMap.h:501
@ Start
Definition GeoEnum.h:100
void Run(FMassRuntimePipeline &RuntimePipeline, FProcessingContext &ProcessingContext)
Definition MassExecutor.cpp:25
Definition Archive.h:36
uint32 GetTypeHash(TPtrVariant< Ts... > Ptr)
Definition VVMPtrVariant.h:83
U16 Index
Definition radfft.cpp:71
Definition Tuple.h:652