From d24f9d1e1e5346b0ec088271b1408a3b8bb1c9df Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 22 May 2025 05:18:56 +0200 Subject: [PATCH] Add warning when using memory profiler without enabled on startup --- Source/Editor/Windows/Profiler/Memory.cs | 15 +++++++++++++++ Source/Engine/Profiler/ProfilerMemory.cpp | 4 ++++ Source/Engine/Profiler/ProfilerMemory.h | 2 +- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Windows/Profiler/Memory.cs b/Source/Editor/Windows/Profiler/Memory.cs index f33bec4cc..806bed18f 100644 --- a/Source/Editor/Windows/Profiler/Memory.cs +++ b/Source/Editor/Windows/Profiler/Memory.cs @@ -29,6 +29,7 @@ namespace FlaxEditor.Windows.Profiler private List _tableRowsCache; private string[] _groupNames; private int[] _groupOrder; + private Label _warningText; public Memory() : base("Memory") @@ -65,6 +66,18 @@ namespace FlaxEditor.Windows.Profiler }; _managedAllocationsChart.SelectedSampleChanged += OnSelectedSampleChanged; + // Warning text + if (!ProfilerMemory.Enabled) + { + _warningText = new Label + { + Text = "Detailed memory profiling is disabled. Run with command line: -mem", + TextColor = Color.Red, + Visible = false, + Parent = layout, + }; + } + // Table var style = Style.Current; var headerColor = style.LightBackground; @@ -204,6 +217,8 @@ namespace FlaxEditor.Windows.Profiler { if (_frames.Count == 0) return; + if (_warningText != null) + _warningText.Visible = true; var frame = _frames.Get(selectedFrame); var totalUage = frame.Usage.Values0[(int)ProfilerMemory.Groups.TotalTracked]; var totalPeek = frame.Peek.Values0[(int)ProfilerMemory.Groups.TotalTracked]; diff --git a/Source/Engine/Profiler/ProfilerMemory.cpp b/Source/Engine/Profiler/ProfilerMemory.cpp index e617d712c..adb244f26 100644 --- a/Source/Engine/Profiler/ProfilerMemory.cpp +++ b/Source/Engine/Profiler/ProfilerMemory.cpp @@ -186,6 +186,10 @@ namespace output.AppendLine(); } #endif + + // Warn that data might be missing due to inactive profiler + if (!ProfilerMemory::Enabled) + output.AppendLine(TEXT("Detailed memory profiling is disabled. Run with command line: -mem")); } FORCE_INLINE void AddGroupMemory(ProfilerMemory::Groups group, int64 add) diff --git a/Source/Engine/Profiler/ProfilerMemory.h b/Source/Engine/Profiler/ProfilerMemory.h index 65ed5d9ab..206814560 100644 --- a/Source/Engine/Profiler/ProfilerMemory.h +++ b/Source/Engine/Profiler/ProfilerMemory.h @@ -215,7 +215,7 @@ public: /// /// The profiling tools usage flag. Can be used to disable profiler. Run engine with '-mem' command line to activate it from start. /// - static bool Enabled; + API_FIELD(ReadOnly) static bool Enabled; static void OnMemoryAlloc(void* ptr, uint64 size); static void OnMemoryFree(void* ptr);