[atom_cpu_profiler_gem_promotion] additional APIs for external control of the CPU profiler and visualization

Signed-off-by: AMZN-ScottR <24445312+AMZN-ScottR@users.noreply.github.com>
This commit is contained in:
AMZN-ScottR
2021-10-15 18:44:10 -07:00
parent 63e68f224b
commit 6480bc8b86
7 changed files with 58 additions and 7 deletions
@@ -19,6 +19,9 @@ namespace Profiler
AZ_RTTI(ProfilerRequests, "{3757c4e5-1941-457c-85ae-16305e17a4c6}");
virtual ~ProfilerRequests() = default;
//! Enable/Disable the CpuProfiler
virtual void SetProfilerEnabled(bool enabled) = 0;
//! Dump a single frame of Cpu profiling data
virtual bool CaptureCpuProfilingStatistics(const AZStd::string& outputFilePath) = 0;
@@ -0,0 +1,35 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
namespace Profiler
{
class ProfilerImGuiRequests
{
public:
AZ_RTTI(ProfilerImGuiRequests, "{E0443400-D108-4D3F-8FF5-4F076FCF6D13}");
virtual ~ProfilerImGuiRequests() = default;
// special request to render the CPU profiler window in a non-standard way
// e.g not through ImGuiUpdateListenerBus::OnImGuiUpdate
virtual void ShowCpuProfilerWindow(bool& keepDrawing) = 0;
};
class ProfilerImGuiBusTraits
: public AZ::EBusTraits
{
public:
// EBusTraits overrides
static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
};
using ProfilerImGuiRequestBus = AZ::EBus<ProfilerImGuiRequests, ProfilerImGuiBusTraits>;
} // namespace Profiler
@@ -61,13 +61,10 @@ namespace Profiler
{
}
void ProfilerImGuiSystemComponent::Init()
{
}
void ProfilerImGuiSystemComponent::Activate()
{
#if defined(IMGUI_ENABLED)
ProfilerImGuiRequestBus::Handler::BusConnect();
ImGui::ImGuiUpdateListenerBus::Handler::BusConnect();
#endif // defined(IMGUI_ENABLED)
}
@@ -75,16 +72,22 @@ namespace Profiler
void ProfilerImGuiSystemComponent::Deactivate()
{
#if defined(IMGUI_ENABLED)
ProfilerImGuiRequestBus::Handler::BusDisconnect();
ImGui::ImGuiUpdateListenerBus::Handler::BusDisconnect();
#endif // defined(IMGUI_ENABLED)
}
#if defined(IMGUI_ENABLED)
void ProfilerImGuiSystemComponent::ShowCpuProfilerWindow(bool& keepDrawing)
{
m_imguiCpuProfiler.Draw(keepDrawing);
}
void ProfilerImGuiSystemComponent::OnImGuiUpdate()
{
if (m_showCpuProfiler)
{
m_imguiCpuProfiler.Draw(m_showCpuProfiler);
ShowCpuProfilerWindow(m_showCpuProfiler);
}
}
@@ -8,7 +8,7 @@
#pragma once
#include <Profiler/ProfilerBus.h>
#include <Profiler/ProfilerImGuiBus.h>
#include <ImGuiCpuProfiler.h>
@@ -24,6 +24,7 @@ namespace Profiler
class ProfilerImGuiSystemComponent
: public AZ::Component
#if defined(IMGUI_ENABLED)
, public ProfilerImGuiRequestBus::Handler
, public ImGui::ImGuiUpdateListenerBus::Handler
#endif // defined(IMGUI_ENABLED)
{
@@ -42,11 +43,13 @@ namespace Profiler
protected:
// AZ::Component interface implementation
void Init() override;
void Activate() override;
void Deactivate() override;
#if defined(IMGUI_ENABLED)
// ProfilerImGuiRequestBus interface implementation
void ShowCpuProfilerWindow(bool& keepDrawing) override;
// ImGuiUpdateListenerBus overrides
void OnImGuiUpdate() override;
void OnImGuiMainMenuUpdate() override;
@@ -200,6 +200,11 @@ namespace Profiler
}
}
void ProfilerSystemComponent::SetProfilerEnabled(bool enabled)
{
m_cpuProfiler.SetProfilerEnabled(enabled);
}
bool ProfilerSystemComponent::CaptureCpuProfilingStatistics(const AZStd::string& outputFilePath)
{
bool expected = false;
@@ -39,6 +39,7 @@ namespace Profiler
void Deactivate() override;
// ProfilerRequestBus interface implementation
void SetProfilerEnabled(bool enabled) override;
bool CaptureCpuProfilingStatistics(const AZStd::string& outputFilePath) override;
bool BeginContinuousCpuProfilingCapture() override;
bool EndContinuousCpuProfilingCapture(const AZStd::string& outputFilePath) override;
+1
View File
@@ -8,6 +8,7 @@
set(FILES
Include/Profiler/ProfilerBus.h
Include/Profiler/ProfilerImGuiBus.h
Source/CpuProfiler.h
Source/CpuProfilerImpl.cpp
Source/CpuProfilerImpl.h