UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ParticlePerfStats.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Templates/Atomic.h"
6#include "CoreMinimal.h"
7#include "CoreTypes.h"
8#include "HAL/PlatformTime.h"
9#include "Containers/Array.h"
11
12
13#define WITH_GLOBAL_RUNTIME_FX_BUDGET (!UE_SERVER)
14#ifndef WITH_PARTICLE_PERF_STATS
15 #if (WITH_UNREAL_DEVELOPER_TOOLS || WITH_UNREAL_TARGET_DEVELOPER_TOOLS || (!UE_BUILD_SHIPPING) || WITH_GLOBAL_RUNTIME_FX_BUDGET)
16 #define WITH_PARTICLE_PERF_STATS 1
17 #else
18 #define WITH_PARTICLE_PERF_STATS 0
19 #endif
20#else
21 #if !WITH_PARTICLE_PERF_STATS
22 //If perf stats are explicitly disabled then we must also disable the runtime budget tracking.
23 #undef WITH_GLOBAL_RUNTIME_FX_BUDGET
24 #define WITH_GLOBAL_RUNTIME_FX_BUDGET 0
25 #endif
26#endif
27
28#define WITH_PER_SYSTEM_PARTICLE_PERF_STATS (WITH_PARTICLE_PERF_STATS && !UE_BUILD_SHIPPING)
29#define WITH_PER_COMPONENT_PARTICLE_PERF_STATS (WITH_PARTICLE_PERF_STATS && !UE_BUILD_SHIPPING)
30
31#define WITH_PARTICLE_PERF_CSV_STATS WITH_PER_SYSTEM_PARTICLE_PERF_STATS && CSV_PROFILER_STATS && !UE_BUILD_SHIPPING
33
35class UWorld;
36class UFXSystemAsset;
38
39#if WITH_PARTICLE_PERF_STATS
40
43{
51
53
55 {
56 NumInstances = Other.NumInstances;
57 TickGameThreadCycles = Other.TickGameThreadCycles;
58 TickConcurrentCycles = Other.TickConcurrentCycles.Load();
59 FinalizeCycles = Other.FinalizeCycles;
60 EndOfFrameCycles = Other.EndOfFrameCycles.Load();
61 ActivationCycles = Other.ActivationCycles.Load();
62 WaitCycles = Other.WaitCycles;
63 }
64
66 {
68 TickGameThreadCycles = Other.TickGameThreadCycles;
69 TickConcurrentCycles = Other.TickConcurrentCycles.Load();
70 FinalizeCycles = Other.FinalizeCycles;
71 EndOfFrameCycles = Other.EndOfFrameCycles.Load();
72 ActivationCycles = Other.ActivationCycles.Load();
73 WaitCycles = Other.WaitCycles;
74 return *this;
75 }
76
78 {
79 *this = Other;
80 Other.Reset();
81 }
82
84 {
85 *this = Other;
86 Other.Reset();
87 return *this;
88 }
89
91 {
93 TickGameThreadCycles += Other.TickGameThreadCycles;
94 TickConcurrentCycles += Other.TickConcurrentCycles.Load();
95 FinalizeCycles += Other.FinalizeCycles;
96 EndOfFrameCycles += Other.EndOfFrameCycles.Load();
97 ActivationCycles += Other.ActivationCycles.Load();
98 WaitCycles += Other.WaitCycles;
99 return *this;
100 }
101
102 inline void Reset()
103 {
104 NumInstances = 0;
107 FinalizeCycles = 0;
110 WaitCycles = 0;
111 }
112
115
118};
119
145
169
171{
173
179
180 inline static bool GetCSVStatsEnabled() { return bCSVStatsEnabled.Load(EMemoryOrder::Relaxed); }
181 inline static bool GetStatsEnabled() { return bStatsEnabled.Load(EMemoryOrder::Relaxed); }
182 inline static bool GetGatherWorldStats() { return WorldStatsReaders.Load(EMemoryOrder::Relaxed) > 0; }
183 inline static bool GetGatherSystemStats() { return SystemStatsReaders.Load(EMemoryOrder::Relaxed) > 0; }
184 inline static bool GetGatherComponentStats() { return ComponentStatsReaders.Load(EMemoryOrder::Relaxed) > 0; }
185 inline static bool ShouldGatherStats()
186 {
187 return GetStatsEnabled() &&
189 #if WITH_PER_SYSTEM_PARTICLE_PERF_STATS
191 #endif
192 #if WITH_PER_COMPONENT_PARTICLE_PERF_STATS
194 #endif
195 );
196 }
197
198
199 inline static void SetCSVStatsEnabled(bool bEnabled) { bCSVStatsEnabled.Store(bEnabled); }
200 inline static void SetStatsEnabled(bool bEnabled) { bStatsEnabled.Store(bEnabled); }
201 inline static void AddWorldStatReader() { ++WorldStatsReaders; }
202 inline static void RemoveWorldStatReader() { --WorldStatsReaders; }
203 inline static void AddSystemStatReader() { ++SystemStatsReaders; }
204 inline static void RemoveSystemStatReader() { --SystemStatsReaders; }
207
209 {
211 {
212 return GetWorldPerfStats(World);
213 }
214 return nullptr;
215 }
216
217 static inline FParticlePerfStats* GetStats(const UFXSystemAsset* System)
218 {
219 #if WITH_PER_SYSTEM_PARTICLE_PERF_STATS
220 if (System && GetGatherSystemStats() && GetStatsEnabled())
221 {
222 return GetSystemPerfStats(System);
223 }
224 #endif
225 return nullptr;
226 }
227
229 {
230 #if WITH_PER_COMPONENT_PARTICLE_PERF_STATS
232 {
233 return GetComponentPerfStats(Component);
234 }
235 #endif
236 return nullptr;
237 }
238
243
245
248
251
254
260
266
269 {
270 return GPUStats;
271 }
272
273 //Cached CSV Stat names for this system.
274#if WITH_PARTICLE_PERF_CSV_STATS
287
289
290 void PopulateStatNames(const FName InName);
291 void ResetStatNames();
292#endif
293
294private:
295 static ENGINE_API FParticlePerfStats* GetWorldPerfStats(const UWorld* World);
296 static ENGINE_API FParticlePerfStats* GetSystemPerfStats(const UFXSystemAsset* FXAsset);
297 static ENGINE_API FParticlePerfStats* GetComponentPerfStats(const UFXSystemComponent* FXComponent);
298
299};
300
302{
312
319
325
330
337
343
348
349 inline bool IsValid()
350 {
351 return GetWorldStats() != nullptr || GetSystemStats() != nullptr || GetComponentStats() != nullptr;
352 }
353
356 inline void SetWorldStats(FParticlePerfStats* Stats) { WorldStats = Stats; }
357
358#if WITH_PER_SYSTEM_PARTICLE_PERF_STATS
361 inline void SetSystemStats(FParticlePerfStats* Stats) { SystemStats = Stats; }
362#else
363 inline FParticlePerfStats* GetSystemStats() { return nullptr; }
364 inline void SetSystemStats(FParticlePerfStats* Stats) { }
365#endif
366
367#if WITH_PER_COMPONENT_PARTICLE_PERF_STATS
370 inline void SetComponentStats(FParticlePerfStats* Stats) { ComponentStats = Stats; }
371#else
372 inline FParticlePerfStats* GetComponentStats() { return nullptr; }
373 inline void SetComponentStats(FParticlePerfStats* Stats) { }
374#endif
375};
376
378
379template<typename TWriterFunc>
381{
392
394 {
395 if (StartCycles != INDEX_NONE)
396 {
398 TWriterFunc::Write(Context.GetWorldStats(), Cycles, Count);
399 TWriterFunc::Write(Context.GetSystemStats(), Cycles, Count);
400 TWriterFunc::Write(Context.GetComponentStats(), Cycles, Count);
401 }
402 }
403
407};
408
409#define PARTICLE_PERF_STAT_CYCLES_COMMON(CONTEXT, THREAD, NAME)\
410struct FParticlePerfStatsWriterCycles_##THREAD##_##NAME\
411{\
412 inline static void Write(FParticlePerfStats* Stats, uint64 Cycles, int32 Count)\
413 {\
414 if (Stats){ Stats->Get##THREAD##Stats().NAME##Cycles += Cycles; }\
415 }\
416};\
417FParticlePerfStatScope<FParticlePerfStatsWriterCycles_##THREAD##_##NAME> ANONYMOUS_VARIABLE(ParticlePerfStatScope##THREAD##NAME)(CONTEXT);
418
419#define PARTICLE_PERF_STAT_CYCLES_WITH_COUNT_COMMON(CONTEXT, THREAD, NAME, COUNT)\
420struct FParticlePerfStatsWriterCyclesAndCount_##THREAD##_##NAME\
421{\
422 inline static void Write(FParticlePerfStats* Stats, uint64 Cycles, int32 Count)\
423 {\
424 if(Stats)\
425 {\
426 Stats->Get##THREAD##Stats().NAME##Cycles += Cycles; \
427 Stats->Get##THREAD##Stats().NumInstances += Count; \
428 }\
429 }\
430};\
431FParticlePerfStatScope<FParticlePerfStatsWriterCyclesAndCount_##THREAD##_##NAME> ANONYMOUS_VARIABLE(ParticlePerfStatScope##THREAD##NAME)(CONTEXT, COUNT);
432
433#define PARTICLE_PERF_STAT_CYCLES_GT(CONTEXT, NAME) PARTICLE_PERF_STAT_CYCLES_COMMON(CONTEXT, GameThread, NAME)
434#define PARTICLE_PERF_STAT_CYCLES_RT(CONTEXT, NAME) PARTICLE_PERF_STAT_CYCLES_COMMON(CONTEXT, RenderThread, NAME)
435
436#define PARTICLE_PERF_STAT_CYCLES_WITH_COUNT_GT(CONTEXT, NAME, COUNT) PARTICLE_PERF_STAT_CYCLES_WITH_COUNT_COMMON(CONTEXT, GameThread, NAME, COUNT)
437#define PARTICLE_PERF_STAT_CYCLES_WITH_COUNT_RT(CONTEXT, NAME, COUNT) PARTICLE_PERF_STAT_CYCLES_WITH_COUNT_COMMON(CONTEXT, RenderThread, NAME, COUNT)
438
439#else //WITH_PARTICLE_PERF_STATS
440
441#define PARTICLE_PERF_STAT_CYCLES_GT(CONTEXT, NAME)
442#define PARTICLE_PERF_STAT_CYCLES_RT(CONTEXT, NAME)
443
444#define PARTICLE_PERF_STAT_CYCLES_WITH_COUNT_GT(CONTEXT, NAME, COUNT)
445#define PARTICLE_PERF_STAT_CYCLES_WITH_COUNT_RT(CONTEXT, NAME, COUNT)
446
448{
455};
456
457#endif //WITH_PARTICLE_PERF_STATS
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
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
#define CSV_DECLARE_CATEGORY_MODULE_EXTERN(Module_API, CategoryName)
Definition CsvProfiler.h:80
#define WITH_PER_SYSTEM_PARTICLE_PERF_STATS
Definition ParticlePerfStats.h:28
#define WITH_PER_COMPONENT_PARTICLE_PERF_STATS
Definition ParticlePerfStats.h:29
TFunction< void(FParticlePerfStats *Stats, uint64 Cycles)> FParticlePerfStatsWriterFunc
Definition ParticlePerfStats.h:377
if(Failed) console_printf("Failed.\n")
Definition NameTypes.h:617
Definition Atomic.h:538
Definition AndroidPlatformMisc.h:14
Definition ParticleSystem.h:118
Definition ParticleSystemComponent.h:380
Definition World.h:918
static uint64 Cycles64()
Definition AndroidPlatformTime.h:34
Definition ParticlePerfStats.h:381
FParticlePerfStatsContext Context
Definition ParticlePerfStats.h:404
int32 Count
Definition ParticlePerfStats.h:406
~FParticlePerfStatScope()
Definition ParticlePerfStats.h:393
uint64 StartCycles
Definition ParticlePerfStats.h:405
FParticlePerfStatScope(FParticlePerfStatsContext InContext, int32 InCount=0)
Definition ParticlePerfStats.h:382
Definition ParticlePerfStats.h:302
FParticlePerfStatsContext(FParticlePerfStats *InComponentStats)
Definition ParticlePerfStats.h:326
void SetSystemStats(FParticlePerfStats *Stats)
Definition ParticlePerfStats.h:361
FParticlePerfStats * ComponentStats
Definition ParticlePerfStats.h:368
FParticlePerfStats * GetComponentStats()
Definition ParticlePerfStats.h:369
FParticlePerfStats * SystemStats
Definition ParticlePerfStats.h:359
FParticlePerfStats * WorldStats
Definition ParticlePerfStats.h:354
FParticlePerfStatsContext(const UWorld *InWorld, const UFXSystemAsset *InSystem, const UFXSystemComponent *InComponent)
Definition ParticlePerfStats.h:331
FParticlePerfStatsContext(FParticlePerfStats *InWorldStats, FParticlePerfStats *InSystemStats)
Definition ParticlePerfStats.h:320
FParticlePerfStatsContext(const UFXSystemComponent *InComponent)
Definition ParticlePerfStats.h:344
FParticlePerfStatsContext(const UWorld *InWorld, const UFXSystemAsset *InSystem)
Definition ParticlePerfStats.h:338
FParticlePerfStatsContext(FParticlePerfStats *InWorldStats, FParticlePerfStats *InSystemStats, FParticlePerfStats *InComponentStats)
Definition ParticlePerfStats.h:313
FParticlePerfStats * GetSystemStats()
Definition ParticlePerfStats.h:360
bool IsValid()
Definition ParticlePerfStats.h:349
FParticlePerfStatsContext()
Definition ParticlePerfStats.h:303
void SetWorldStats(FParticlePerfStats *Stats)
Definition ParticlePerfStats.h:356
FParticlePerfStats * GetWorldStats()
Definition ParticlePerfStats.h:355
void SetComponentStats(FParticlePerfStats *Stats)
Definition ParticlePerfStats.h:370
Definition ParticlePerfStats.h:148
uint64 GetPerInstanceAvgMicroseconds() const
Definition ParticlePerfStats.h:153
FParticlePerfStats_GPU()
Definition ParticlePerfStats.h:155
uint64 NumInstances
Definition ParticlePerfStats.h:149
FParticlePerfStats_GPU & operator+=(FParticlePerfStats_GPU &Other)
Definition ParticlePerfStats.h:162
uint64 GetTotalMicroseconds() const
Definition ParticlePerfStats.h:152
void Reset()
Definition ParticlePerfStats.h:156
uint64 TotalMicroseconds
Definition ParticlePerfStats.h:150
Definition ParticlePerfStats.h:43
uint64 GetTotalCycles_GTOnly() const
Definition ParticlePerfStats.h:113
FParticlePerfStats_GT()
Definition ParticlePerfStats.h:52
TAtomic< uint64 > ActivationCycles
Definition ParticlePerfStats.h:49
uint64 NumInstances
Definition ParticlePerfStats.h:44
TAtomic< uint64 > TickConcurrentCycles
Definition ParticlePerfStats.h:46
uint64 WaitCycles
Definition ParticlePerfStats.h:50
FParticlePerfStats_GT & operator+=(FParticlePerfStats_GT &Other)
Definition ParticlePerfStats.h:90
uint64 FinalizeCycles
Definition ParticlePerfStats.h:47
FParticlePerfStats_GT(const FParticlePerfStats_GT &Other)
Definition ParticlePerfStats.h:54
uint64 GetPerInstanceAvgCycles_GTOnly() const
Definition ParticlePerfStats.h:114
uint64 GetTotalCycles() const
Definition ParticlePerfStats.h:116
TAtomic< uint64 > EndOfFrameCycles
Definition ParticlePerfStats.h:48
FParticlePerfStats_GT(FParticlePerfStats_GT &&Other)
Definition ParticlePerfStats.h:77
uint64 TickGameThreadCycles
Definition ParticlePerfStats.h:45
FParticlePerfStats_GT & operator=(const FParticlePerfStats_GT &Other)
Definition ParticlePerfStats.h:65
void Reset()
Definition ParticlePerfStats.h:102
uint64 GetPerInstanceAvgCycles() const
Definition ParticlePerfStats.h:117
FParticlePerfStats_GT & operator=(FParticlePerfStats_GT &&Other)
Definition ParticlePerfStats.h:83
Definition ParticlePerfStats.h:122
uint64 NumInstances
Definition ParticlePerfStats.h:123
uint64 RenderUpdateCycles
Definition ParticlePerfStats.h:124
void Reset()
Definition ParticlePerfStats.h:128
uint64 GetDynamicMeshElementsCycles
Definition ParticlePerfStats.h:125
uint64 GetTotalCycles() const
Definition ParticlePerfStats.h:134
uint64 GetPerInstanceAvgCycles() const
Definition ParticlePerfStats.h:135
FParticlePerfStats_RT & operator+=(FParticlePerfStats_RT &Other)
Definition ParticlePerfStats.h:137
FParticlePerfStats_RT()
Definition ParticlePerfStats.h:127
Definition ParticlePerfStats.h:171
static bool ShouldGatherStats()
Definition ParticlePerfStats.h:185
static bool GetCSVStatsEnabled()
Definition ParticlePerfStats.h:180
static FParticlePerfStats * GetStats(const UFXSystemAsset *System)
Definition ParticlePerfStats.h:217
ENGINE_API void Reset(bool bSyncWithRT)
static bool GetGatherWorldStats()
Definition ParticlePerfStats.h:182
static void RemoveComponentStatReader()
Definition ParticlePerfStats.h:206
FParticlePerfStats_GPU & GetGPUStats()
Definition ParticlePerfStats.h:268
static void RemoveSystemStatReader()
Definition ParticlePerfStats.h:204
static void AddComponentStatReader()
Definition ParticlePerfStats.h:205
static FParticlePerfStats * GetStats(const UFXSystemComponent *Component)
Definition ParticlePerfStats.h:228
FParticlePerfStats_GPU GPUStats
Definition ParticlePerfStats.h:253
static ENGINE_API TAtomic< int32 > ComponentStatsReaders
Definition ParticlePerfStats.h:242
static FParticlePerfStats * GetStats(const UWorld *World)
Definition ParticlePerfStats.h:208
ENGINE_API void Tick()
static ENGINE_API TAtomic< int32 > WorldStatsReaders
Definition ParticlePerfStats.h:240
ENGINE_API void ResetRT()
static bool GetGatherComponentStats()
Definition ParticlePerfStats.h:184
static ENGINE_API TAtomic< bool > bStatsEnabled
Definition ParticlePerfStats.h:239
static ENGINE_API TAtomic< int32 > SystemStatsReaders
Definition ParticlePerfStats.h:241
static void RemoveWorldStatReader()
Definition ParticlePerfStats.h:202
static ENGINE_API TAtomic< bool > bCSVStatsEnabled
Definition ParticlePerfStats.h:244
FParticlePerfStats_RT RenderThreadStats
Definition ParticlePerfStats.h:250
static bool GetGatherSystemStats()
Definition ParticlePerfStats.h:183
ENGINE_API void TickRT()
static void SetCSVStatsEnabled(bool bEnabled)
Definition ParticlePerfStats.h:199
static void AddWorldStatReader()
Definition ParticlePerfStats.h:201
ENGINE_API FParticlePerfStats()
FParticlePerfStats_RT & GetRenderThreadStats()
Definition ParticlePerfStats.h:262
static void SetStatsEnabled(bool bEnabled)
Definition ParticlePerfStats.h:200
FParticlePerfStats_GT & GetGameThreadStats()
Definition ParticlePerfStats.h:256
static bool GetStatsEnabled()
Definition ParticlePerfStats.h:181
static void AddSystemStatReader()
Definition ParticlePerfStats.h:203
ENGINE_API void ResetGT()
FParticlePerfStats_GT GameThreadStats
Definition ParticlePerfStats.h:247
Definition Optional.h:131