[profiler_capture_api] added cvar/console access for profiler capture

Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>
This commit is contained in:
AMZN-ScottR
2021-10-25 11:48:00 -07:00
parent 6ddfb6500f
commit 471436b0fc
2 changed files with 52 additions and 4 deletions
@@ -7,4 +7,44 @@
*/
#include <AzCore/Debug/Profiler.h>
#include <AzCore/Debug/ProfilerBus.h>
#include <AzCore/Console/IConsole.h>
#include <AzCore/Console/ILogger.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);
return AZStd::string::format("%s/capture_%s_%s.json", captureOutput.c_str(), nameHint, timeString.c_str());
}
void ProfilerCaptureFrame([[maybe_unused]] const AZ::ConsoleCommandContainer& arguments)
{
AZStd::string captureFile = GenerateOutputFile("single");
AZLOG_INFO("Setting capture file to %s", captureFile.c_str());
AZ::Debug::ProfilerRequestBus::Broadcast(&AZ::Debug::ProfilerRequestBus::Events::CaptureFrame, captureFile);
}
AZ_CONSOLEFREEFUNC(ProfilerCaptureFrame, AZ::ConsoleFunctorFlags::DontReplicate, "Capture a single frame of profiling data");
void ProfilerStartCapture([[maybe_unused]] const AZ::ConsoleCommandContainer& arguments)
{
AZStd::string captureFile = GenerateOutputFile("multi");
AZLOG_INFO("Setting capture file to %s", captureFile.c_str());
ProfilerRequestBus::Broadcast(&ProfilerRequestBus::Events::StartCapture, captureFile);
}
AZ_CONSOLEFREEFUNC(ProfilerStartCapture, AZ::ConsoleFunctorFlags::DontReplicate, "Start a multi-frame capture of profiling data");
void ProfilerEndCapture([[maybe_unused]] const AZ::ConsoleCommandContainer& arguments)
{
AZ::Debug::ProfilerRequestBus::Broadcast(&AZ::Debug::ProfilerRequestBus::Events::EndCapture);
}
AZ_CONSOLEFREEFUNC(ProfilerEndCapture, AZ::ConsoleFunctorFlags::DontReplicate, "End and dump an in-progress continuous capture");
} // namespace AZ::Debug
+12 -4
View File
@@ -12,6 +12,7 @@
#include <CpuProfilerImpl.h>
#include <AzCore/Console/IConsole.h>
#include <AzCore/Debug/ProfilerBus.h>
#include <AzCore/IO/FileIO.h>
#include <AzCore/JSON/filereadstream.h>
@@ -24,10 +25,13 @@
#include <AzCore/std/string/conversions.h>
#include <AzCore/std/time.h>
namespace AZ::Debug
{
AZ_CVAR_EXTERNED(AZ::CVarFixedString, bg_profilerCaptureLocation);
}
namespace Profiler
{
static constexpr const char* defaultSaveLocation = "@user@/Profiler";
namespace CpuProfilerImGuiHelper
{
float TicksToMs(double ticks)
@@ -222,8 +226,10 @@ 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);
auto* base = AZ::IO::FileIOBase::GetInstance();
base->FindFiles(defaultSaveLocation, "*.json",
base->FindFiles(captureOutput.c_str(), "*.json",
[&paths = m_cachedCapturePaths](const char* path) -> bool
{
auto foundPath = AZ::IO::Path(path);
@@ -410,7 +416,9 @@ namespace Profiler
AZStd::string timeString;
AZStd::to_string(timeString, AZStd::GetTimeNowSecond());
const AZStd::string frameDataFilePath = AZStd::string::format("%s/cpu_%s_%s.json", defaultSaveLocation, nameHint, timeString.c_str());
AZ::CVarFixedString captureOutput = static_cast<AZ::CVarFixedString>(AZ::Debug::bg_profilerCaptureLocation);
const AZStd::string frameDataFilePath = AZStd::string::format("%s/cpu_%s_%s.json", captureOutput.c_str(), nameHint, timeString.c_str());
char resolvedPath[AZ::IO::MaxPathLength];
AZ::IO::FileIOBase::GetInstance()->ResolvePath(frameDataFilePath.c_str(), resolvedPath, AZ::IO::MaxPathLength);