[profiler_capture_api] replace profiler capture location cvar with setting registry entry

Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>
This commit is contained in:
AMZN-ScottR
2021-10-26 12:15:30 -07:00
parent 6b1198584b
commit 57a69978b9
4 changed files with 46 additions and 12 deletions
@@ -10,18 +10,16 @@
#include <AzCore/Debug/ProfilerBus.h>
#include <AzCore/Console/IConsole.h>
#include <AzCore/Console/ILogger.h>
#include <AzCore/Settings/SettingsRegistry.h>
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<AZ::CVarFixedString>(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
@@ -10,12 +10,19 @@
#include <AzCore/EBus/EBus.h>
#include <AzCore/Interface/Interface.h>
#include <AzCore/IO/Path/Path_fwd.h>
#include <AzCore/std/string/string.h>
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<ProfilerRequests>;
//! 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
@@ -12,7 +12,6 @@
#include <CpuProfilerImpl.h>
#include <AzCore/Console/IConsole.h>
#include <AzCore/Debug/ProfilerBus.h>
#include <AzCore/IO/FileIO.h>
#include <AzCore/JSON/filereadstream.h>
@@ -25,11 +24,6 @@
#include <AzCore/std/string/conversions.h>
#include <AzCore/std/time.h>
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::CVarFixedString>(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::CVarFixedString>(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());
+15
View File
@@ -0,0 +1,15 @@
{
"O3DE":
{
"AzCore":
{
"Debug":
{
"Profiler":
{
"CaptureLocation" : "@user@/Profiler"
}
}
}
}
}