Add conditional profiling in Editor (run only when using Profiler window)

This commit is contained in:
2023-09-25 18:34:07 +02:00
parent 216a5e9f92
commit da47088250
6 changed files with 30 additions and 6 deletions
@@ -93,7 +93,7 @@ namespace FlaxEditor.Windows.Profiler
_liveRecordingButton = toolstrip.AddButton(editor.Icons.Play64);
_liveRecordingButton.LinkTooltip("Live profiling events recording");
_liveRecordingButton.AutoCheck = true;
_liveRecordingButton.Clicked += () => _liveRecordingButton.Icon = LiveRecording ? editor.Icons.Stop64 : editor.Icons.Play64;
_liveRecordingButton.Clicked += OnLiveRecordingChanged;
_clearButton = toolstrip.AddButton(editor.Icons.Rotate32, Clear);
_clearButton.LinkTooltip("Clear data");
toolstrip.AddSeparator();
@@ -118,6 +118,12 @@ namespace FlaxEditor.Windows.Profiler
_tabs.SelectedTabChanged += OnSelectedTabChanged;
}
private void OnLiveRecordingChanged()
{
_liveRecordingButton.Icon = LiveRecording ? Editor.Icons.Stop64 : Editor.Icons.Play64;
ProfilingTools.Enabled = LiveRecording;
}
/// <summary>
/// Adds the mode.
/// </summary>
-3
View File
@@ -102,9 +102,6 @@ int32 Engine::Main(const Char* cmdLine)
Platform::SetHighDpiAwarenessEnabled(!CommandLine::Options.LowDPI.IsTrue());
Time::StartupTime = DateTime::Now();
#if COMPILE_WITH_PROFILER
ProfilerCPU::Enabled = true;
#endif
Globals::StartupFolder = Globals::BinariesFolder = Platform::GetMainDirectory();
#if USE_EDITOR
Globals::StartupFolder /= TEXT("../../../..");
+1 -1
View File
@@ -205,7 +205,7 @@ int32 ProfilerCPU::BeginEvent(const char* name)
void ProfilerCPU::EndEvent(int32 index)
{
if (Enabled && Thread::Current)
if (index != -1 && Thread::Current)
Thread::Current->EndEvent(index);
}
+1 -1
View File
@@ -14,7 +14,7 @@ RenderStatsData RenderStatsData::Counter;
int32 ProfilerGPU::_depth = 0;
Array<GPUTimerQuery*> ProfilerGPU::_timerQueriesPool;
Array<GPUTimerQuery*> ProfilerGPU::_timerQueriesFree;
bool ProfilerGPU::Enabled = true;
bool ProfilerGPU::Enabled = false;
int32 ProfilerGPU::CurrentBuffer = 0;
ProfilerGPU::EventBuffer ProfilerGPU::Buffers[PROFILER_GPU_EVENTS_FRAMES];
+11
View File
@@ -175,4 +175,15 @@ void ProfilingToolsService::Dispose()
ProfilingTools::EventsGPU.SetCapacity(0);
}
bool ProfilingTools::GetEnabled()
{
return ProfilerCPU::Enabled && ProfilerGPU::Enabled;
}
void ProfilingTools::SetEnabled(bool enabled)
{
ProfilerCPU::Enabled = enabled;
ProfilerGPU::Enabled = enabled;
}
#endif
+10
View File
@@ -106,6 +106,16 @@ public:
};
public:
/// <summary>
/// Controls the engine profiler (CPU, GPU, etc.) usage.
/// </summary>
API_PROPERTY() static bool GetEnabled();
/// <summary>
/// Controls the engine profiler (CPU, GPU, etc.) usage.
/// </summary>
API_PROPERTY() static void SetEnabled(bool enabled);
/// <summary>
/// The current collected main stats by the profiler from the local session. Updated every frame.
/// </summary>