diff --git a/Code/Framework/AzCore/AzCore/Debug/Profiler.cpp b/Code/Framework/AzCore/AzCore/Debug/Profiler.cpp index 4abda46214..3b5033a07f 100644 --- a/Code/Framework/AzCore/AzCore/Debug/Profiler.cpp +++ b/Code/Framework/AzCore/AzCore/Debug/Profiler.cpp @@ -10,18 +10,16 @@ #include #include #include +#include namespace AZ::Debug { - AZ_CVAR(AZ::CVarFixedString, bg_profilerCaptureLocation, "@user@/Profiler", nullptr, ConsoleFunctorFlags::Null, - "Specify where to save profiler capture data"); - AZStd::string GenerateOutputFile(const char* nameHint) { AZStd::string timeString; AZStd::to_string(timeString, AZStd::GetTimeNowSecond()); - AZ::CVarFixedString captureOutput = static_cast(bg_profilerCaptureLocation); + AZ::IO::FixedMaxPathString captureOutput = GetProfilerCaptureLocation(); return AZStd::string::format("%s/capture_%s_%s.json", captureOutput.c_str(), nameHint, timeString.c_str()); } @@ -47,4 +45,20 @@ namespace AZ::Debug AZ::Debug::ProfilerRequestBus::Broadcast(&AZ::Debug::ProfilerRequestBus::Events::EndCapture); } AZ_CONSOLEFREEFUNC(ProfilerEndCapture, AZ::ConsoleFunctorFlags::DontReplicate, "End and dump an in-progress continuous capture"); + + AZ::IO::FixedMaxPathString GetProfilerCaptureLocation() + { + AZ::IO::FixedMaxPathString captureOutput; + if (AZ::SettingsRegistryInterface* settingsRegistry = AZ::SettingsRegistry::Get(); settingsRegistry) + { + settingsRegistry->Get(captureOutput, RegistryKey_ProfilerCaptureLocation); + } + + if (captureOutput.empty()) + { + captureOutput = ProfilerCaptureLocationFallback; + } + + return captureOutput; + } } // namespace AZ::Debug diff --git a/Code/Framework/AzCore/AzCore/Debug/ProfilerBus.h b/Code/Framework/AzCore/AzCore/Debug/ProfilerBus.h index 89c59f01b5..03a89b11f2 100644 --- a/Code/Framework/AzCore/AzCore/Debug/ProfilerBus.h +++ b/Code/Framework/AzCore/AzCore/Debug/ProfilerBus.h @@ -10,12 +10,19 @@ #include #include +#include #include namespace AZ { namespace Debug { + //! settings registry entry for specifying where to output profiler captures + static constexpr const char* RegistryKey_ProfilerCaptureLocation = "/O3DE/AzCore/Debug/Profiler/CaptureLocation"; + + //! fallback value in the event the settings registry isn't ready or doesn't contain the key + static constexpr const char* ProfilerCaptureLocationFallback = "@user@/Profiler"; + /** * ProfilerNotifications provides a profiler event interface that can be used to update listeners on profiler status */ @@ -60,5 +67,9 @@ namespace AZ virtual bool EndCapture() = 0; }; using ProfilerRequestBus = AZ::EBus; + + //! helper function for getting the profiler capture location from the settings registry that + //! includes fallback handing in the event the registry value can't be determined + AZ::IO::FixedMaxPathString GetProfilerCaptureLocation(); } // namespace Debug } // namespace AZ diff --git a/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp b/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp index 88b200c733..fd19460153 100644 --- a/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp +++ b/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp @@ -12,7 +12,6 @@ #include -#include #include #include #include @@ -25,11 +24,6 @@ #include #include -namespace AZ::Debug -{ - AZ_CVAR_EXTERNED(AZ::CVarFixedString, bg_profilerCaptureLocation); -} - namespace Profiler { namespace CpuProfilerImGuiHelper @@ -226,7 +220,7 @@ namespace Profiler // Only update the cached file list when opened so that we aren't making IO calls on every frame. m_cachedCapturePaths.clear(); - AZ::CVarFixedString captureOutput = static_cast(AZ::Debug::bg_profilerCaptureLocation); + AZ::IO::FixedMaxPathString captureOutput = AZ::Debug::GetProfilerCaptureLocation(); auto* base = AZ::IO::FileIOBase::GetInstance(); base->FindFiles(captureOutput.c_str(), "*.json", @@ -416,7 +410,7 @@ namespace Profiler AZStd::string timeString; AZStd::to_string(timeString, AZStd::GetTimeNowSecond()); - AZ::CVarFixedString captureOutput = static_cast(AZ::Debug::bg_profilerCaptureLocation); + AZ::IO::FixedMaxPathString captureOutput = AZ::Debug::GetProfilerCaptureLocation(); const AZ::IO::FixedMaxPathString frameDataFilePath = AZ::IO::FixedMaxPathString::format("%s/cpu_%s_%s.json", captureOutput.c_str(), nameHint, timeString.c_str()); diff --git a/Registry/profiler.setreg b/Registry/profiler.setreg new file mode 100644 index 0000000000..a295b007e1 --- /dev/null +++ b/Registry/profiler.setreg @@ -0,0 +1,15 @@ +{ + "O3DE": + { + "AzCore": + { + "Debug": + { + "Profiler": + { + "CaptureLocation" : "@user@/Profiler" + } + } + } + } +} \ No newline at end of file