From a2c42ab07281e1b7ef56496da12c70f86a59c782 Mon Sep 17 00:00:00 2001 From: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> Date: Tue, 26 Oct 2021 15:15:52 -0700 Subject: [PATCH] [profiler_capture_api] started migration of ProfilerRequests EBus to AZ::Interface Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com> --- .../AzCore/AzCore/Debug/Profiler.cpp | 23 +++++++++++------ .../AzCore/AzCore/Debug/ProfilerBus.h | 25 ++++++++++++------- .../AzCore/IO/Streamer/StreamerComponent.cpp | 5 +++- Gems/PhysX/Code/Source/Scene/PhysXScene.cpp | 5 +++- .../Profiler/Code/Source/ImGuiCpuProfiler.cpp | 13 +++------- .../Code/Source/ProfilerSystemComponent.cpp | 8 ++++++ 6 files changed, 52 insertions(+), 27 deletions(-) diff --git a/Code/Framework/AzCore/AzCore/Debug/Profiler.cpp b/Code/Framework/AzCore/AzCore/Debug/Profiler.cpp index 3b5033a07f..3b6b3b7e7a 100644 --- a/Code/Framework/AzCore/AzCore/Debug/Profiler.cpp +++ b/Code/Framework/AzCore/AzCore/Debug/Profiler.cpp @@ -26,23 +26,32 @@ namespace AZ::Debug 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); + if (auto profilerSystem = ProfilerSystemInterface::Get(); profilerSystem) + { + AZStd::string captureFile = GenerateOutputFile("single"); + AZLOG_INFO("Setting capture file to %s", captureFile.c_str()); + profilerSystem->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); + if (auto profilerSystem = ProfilerSystemInterface::Get(); profilerSystem) + { + AZStd::string captureFile = GenerateOutputFile("multi"); + AZLOG_INFO("Setting capture file to %s", captureFile.c_str()); + profilerSystem->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); + if (auto profilerSystem = ProfilerSystemInterface::Get(); profilerSystem) + { + profilerSystem->EndCapture(); + } } AZ_CONSOLEFREEFUNC(ProfilerEndCapture, AZ::ConsoleFunctorFlags::DontReplicate, "End and dump an in-progress continuous capture"); diff --git a/Code/Framework/AzCore/AzCore/Debug/ProfilerBus.h b/Code/Framework/AzCore/AzCore/Debug/ProfilerBus.h index 03a89b11f2..9194381e23 100644 --- a/Code/Framework/AzCore/AzCore/Debug/ProfilerBus.h +++ b/Code/Framework/AzCore/AzCore/Debug/ProfilerBus.h @@ -43,16 +43,9 @@ namespace AZ * ProfilerRequests provides an interface for making profiling system requests */ class ProfilerRequests - : public AZ::EBusTraits { public: - // EBusTraits overrides - static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; - static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; - - // Allow multiple threads to concurrently make requests - using MutexType = AZStd::mutex; - + AZ_RTTI(ProfilerRequests, "{90AEC117-14C1-4BAE-9704-F916E49EF13F}"); virtual ~ProfilerRequests() = default; //! Getter/setter for the profiler active state @@ -66,7 +59,21 @@ namespace AZ virtual bool StartCapture(AZStd::string outputFilePath) = 0; virtual bool EndCapture() = 0; }; - using ProfilerRequestBus = AZ::EBus; + + class ProfilerRequestsTraits + : public AZ::EBusTraits + { + public: + // EBusTraits overrides + static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; + static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; + + // Allow multiple threads to concurrently make requests + using MutexType = AZStd::mutex; + }; + + using ProfilerSystemInterface = AZ::Interface; + 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 diff --git a/Code/Framework/AzCore/AzCore/IO/Streamer/StreamerComponent.cpp b/Code/Framework/AzCore/AzCore/IO/Streamer/StreamerComponent.cpp index 9728866fb6..9a465021c2 100644 --- a/Code/Framework/AzCore/AzCore/IO/Streamer/StreamerComponent.cpp +++ b/Code/Framework/AzCore/AzCore/IO/Streamer/StreamerComponent.cpp @@ -156,7 +156,10 @@ namespace AZ void StreamerComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time) { bool isEnabled = false; - AZ::Debug::ProfilerRequestBus::BroadcastResult(isEnabled, &AZ::Debug::ProfilerRequests::IsActive); + if (auto profilerSystem = AZ::Debug::ProfilerSystemInterface::Get(); profilerSystem) + { + isEnabled = profilerSystem->IsActive(); + } if (isEnabled) { diff --git a/Gems/PhysX/Code/Source/Scene/PhysXScene.cpp b/Gems/PhysX/Code/Source/Scene/PhysXScene.cpp index 86e3ceb98f..22fc665eec 100644 --- a/Gems/PhysX/Code/Source/Scene/PhysXScene.cpp +++ b/Gems/PhysX/Code/Source/Scene/PhysXScene.cpp @@ -1175,7 +1175,10 @@ namespace PhysX using physx::PxGeometryType; bool isProfilingActive = false; - AZ::Debug::ProfilerRequestBus::BroadcastResult(isProfilingActive, &AZ::Debug::ProfilerRequests::IsActive); + if (auto profilerSystem = AZ::Debug::ProfilerSystemInterface::Get(); profilerSystem) + { + isProfilingActive = profilerSystem->IsActive(); + } if (!isProfilingActive) { diff --git a/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp b/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp index fd19460153..e1a734136b 100644 --- a/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp +++ b/Gems/Profiler/Code/Source/ImGuiCpuProfiler.cpp @@ -154,10 +154,7 @@ namespace Profiler if (m_captureToFile) { - AZ::Debug::ProfilerRequestBus::Broadcast( - &AZ::Debug::ProfilerRequestBus::Events::CaptureFrame, - GenerateOutputFile("single") - ); + AZ::Debug::ProfilerSystemInterface::Get()->CaptureFrame(GenerateOutputFile("single")); } m_captureToFile = false; @@ -198,17 +195,15 @@ namespace Profiler bool isInProgress = CpuProfiler::Get()->IsContinuousCaptureInProgress(); if (ImGui::Button(isInProgress ? "End" : "Begin")) { + auto profilerSystem = AZ::Debug::ProfilerSystemInterface::Get(); if (isInProgress) { - AZ::Debug::ProfilerRequestBus::Broadcast(&AZ::Debug::ProfilerRequestBus::Events::EndCapture); + profilerSystem->EndCapture(); m_paused = true; } else { - AZ::Debug::ProfilerRequestBus::Broadcast( - &AZ::Debug::ProfilerRequestBus::Events::StartCapture, - GenerateOutputFile("multi") - ); + profilerSystem->StartCapture(GenerateOutputFile("multi")); } } diff --git a/Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp b/Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp index 09df0970b8..4deda64964 100644 --- a/Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp +++ b/Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp @@ -128,10 +128,18 @@ namespace Profiler ProfilerSystemComponent::ProfilerSystemComponent() { + if (AZ::Debug::ProfilerSystemInterface::Get() == nullptr) + { + AZ::Debug::ProfilerSystemInterface::Register(this); + } } ProfilerSystemComponent::~ProfilerSystemComponent() { + if (AZ::Debug::ProfilerSystemInterface::Get() == this) + { + AZ::Debug::ProfilerSystemInterface::Unregister(this); + } } void ProfilerSystemComponent::Activate()