diff --git a/Gems/Profiler/CMakeLists.txt b/Gems/Profiler/CMakeLists.txt new file mode 100644 index 0000000000..2bb380fae3 --- /dev/null +++ b/Gems/Profiler/CMakeLists.txt @@ -0,0 +1,9 @@ +# +# 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 +# +# + +add_subdirectory(Code) diff --git a/Gems/Profiler/Code/CMakeLists.txt b/Gems/Profiler/Code/CMakeLists.txt new file mode 100644 index 0000000000..899cdee3e7 --- /dev/null +++ b/Gems/Profiler/Code/CMakeLists.txt @@ -0,0 +1,46 @@ +# +# 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 +# +# + +# Add the Profiler.Static target +ly_add_target( + NAME Profiler.Static STATIC + NAMESPACE Gem + FILES_CMAKE + profiler_files.cmake + INCLUDE_DIRECTORIES + PUBLIC + Include + PRIVATE + Source + BUILD_DEPENDENCIES + PUBLIC + AZ::AzCore + AZ::AzFramework +) + +# Here add Profiler target, it depends on the Profiler.Static +ly_add_target( + NAME Profiler ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE} + NAMESPACE Gem + FILES_CMAKE + profiler_shared_files.cmake + INCLUDE_DIRECTORIES + PUBLIC + Include + PRIVATE + Source + BUILD_DEPENDENCIES + PRIVATE + Gem::Profiler.Static +) + +# By default, we will specify that the above target Profiler would be used by +# Client and Server type targets when this gem is enabled. If you don't want it +# active in Clients or Servers by default, delete one of both of the following lines: +ly_create_alias(NAME Profiler.Clients NAMESPACE Gem TARGETS Gem::Profiler) +ly_create_alias(NAME Profiler.Servers NAMESPACE Gem TARGETS Gem::Profiler) diff --git a/Gems/Profiler/Code/Include/Profiler/ProfilerBus.h b/Gems/Profiler/Code/Include/Profiler/ProfilerBus.h new file mode 100644 index 0000000000..28e1513324 --- /dev/null +++ b/Gems/Profiler/Code/Include/Profiler/ProfilerBus.h @@ -0,0 +1,37 @@ +/* + * 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 +#include + +namespace Profiler +{ + class ProfilerRequests + { + public: + AZ_RTTI(ProfilerRequests, "{3757c4e5-1941-457c-85ae-16305e17a4c6}"); + virtual ~ProfilerRequests() = default; + // Put your public methods here + }; + + class ProfilerBusTraits + : public AZ::EBusTraits + { + public: + ////////////////////////////////////////////////////////////////////////// + // EBusTraits overrides + static constexpr AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single; + static constexpr AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single; + ////////////////////////////////////////////////////////////////////////// + }; + + using ProfilerRequestBus = AZ::EBus; + using ProfilerInterface = AZ::Interface; + +} // namespace Profiler diff --git a/Gems/Profiler/Code/Source/ProfilerModule.cpp b/Gems/Profiler/Code/Source/ProfilerModule.cpp new file mode 100644 index 0000000000..732265cdb4 --- /dev/null +++ b/Gems/Profiler/Code/Source/ProfilerModule.cpp @@ -0,0 +1,23 @@ +/* + * 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 + * + */ + +#include +#include + +namespace Profiler +{ + class ProfilerModule + : public ProfilerModuleInterface + { + public: + AZ_RTTI(ProfilerModule, "{1908f95f-30b9-4e27-8ae7-1e9fe487ef87}", ProfilerModuleInterface); + AZ_CLASS_ALLOCATOR(ProfilerModule, AZ::SystemAllocator, 0); + }; +}// namespace Profiler + +AZ_DECLARE_MODULE_CLASS(Gem_Profiler, Profiler::ProfilerModule) diff --git a/Gems/Profiler/Code/Source/ProfilerModuleInterface.h b/Gems/Profiler/Code/Source/ProfilerModuleInterface.h new file mode 100644 index 0000000000..6cf6fd30ab --- /dev/null +++ b/Gems/Profiler/Code/Source/ProfilerModuleInterface.h @@ -0,0 +1,43 @@ +/* + * 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 + * + */ + +#include +#include +#include + +namespace Profiler +{ + class ProfilerModuleInterface + : public AZ::Module + { + public: + AZ_RTTI(ProfilerModuleInterface, "{c966e43a-420d-41c9-bd0d-4cb0bca0d3e1}", AZ::Module); + AZ_CLASS_ALLOCATOR(ProfilerModuleInterface, AZ::SystemAllocator, 0); + + ProfilerModuleInterface() + { + // Push results of [MyComponent]::CreateDescriptor() into m_descriptors here. + // Add ALL components descriptors associated with this gem to m_descriptors. + // This will associate the AzTypeInfo information for the components with the the SerializeContext, BehaviorContext and EditContext. + // This happens through the [MyComponent]::Reflect() function. + m_descriptors.insert(m_descriptors.end(), { + ProfilerSystemComponent::CreateDescriptor(), + }); + } + + /** + * Add required SystemComponents to the SystemEntity. + */ + AZ::ComponentTypeList GetRequiredSystemComponents() const override + { + return AZ::ComponentTypeList{ + azrtti_typeid(), + }; + } + }; +}// namespace Profiler diff --git a/Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp b/Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp new file mode 100644 index 0000000000..d6f9adce17 --- /dev/null +++ b/Gems/Profiler/Code/Source/ProfilerSystemComponent.cpp @@ -0,0 +1,90 @@ +/* + * 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 + * + */ + +#include + +#include +#include +#include + +namespace Profiler +{ + void ProfilerSystemComponent::Reflect(AZ::ReflectContext* context) + { + if (AZ::SerializeContext* serialize = azrtti_cast(context)) + { + serialize->Class() + ->Version(0) + ; + + if (AZ::EditContext* ec = serialize->GetEditContext()) + { + ec->Class("Profiler", "[Description of functionality provided by this System Component]") + ->ClassElement(AZ::Edit::ClassElements::EditorData, "") + ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("System")) + ->Attribute(AZ::Edit::Attributes::AutoExpand, true) + ; + } + } + } + + void ProfilerSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) + { + provided.push_back(AZ_CRC_CE("ProfilerService")); + } + + void ProfilerSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) + { + incompatible.push_back(AZ_CRC_CE("ProfilerService")); + } + + void ProfilerSystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required) + { + } + + void ProfilerSystemComponent::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent) + { + } + + ProfilerSystemComponent::ProfilerSystemComponent() + { + if (ProfilerInterface::Get() == nullptr) + { + ProfilerInterface::Register(this); + } + } + + ProfilerSystemComponent::~ProfilerSystemComponent() + { + if (ProfilerInterface::Get() == this) + { + ProfilerInterface::Unregister(this); + } + } + + void ProfilerSystemComponent::Init() + { + } + + void ProfilerSystemComponent::Activate() + { + ProfilerRequestBus::Handler::BusConnect(); + AZ::TickBus::Handler::BusConnect(); + } + + void ProfilerSystemComponent::Deactivate() + { + AZ::TickBus::Handler::BusDisconnect(); + ProfilerRequestBus::Handler::BusDisconnect(); + } + + void ProfilerSystemComponent::OnTick([[maybe_unused]] float deltaTime, [[maybe_unused]] AZ::ScriptTimePoint time) + { + } + +} // namespace Profiler diff --git a/Gems/Profiler/Code/Source/ProfilerSystemComponent.h b/Gems/Profiler/Code/Source/ProfilerSystemComponent.h new file mode 100644 index 0000000000..9b53f7d3a1 --- /dev/null +++ b/Gems/Profiler/Code/Source/ProfilerSystemComponent.h @@ -0,0 +1,54 @@ +/* + * 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 +#include +#include + +namespace Profiler +{ + class ProfilerSystemComponent + : public AZ::Component + , protected ProfilerRequestBus::Handler + , public AZ::TickBus::Handler + { + public: + AZ_COMPONENT(ProfilerSystemComponent, "{3f52c1d7-d920-4781-8ed7-88077ec4f305}"); + + static void Reflect(AZ::ReflectContext* context); + + static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided); + static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible); + static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); + static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent); + + ProfilerSystemComponent(); + ~ProfilerSystemComponent(); + + protected: + //////////////////////////////////////////////////////////////////////// + // ProfilerRequestBus interface implementation + + //////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////// + // AZ::Component interface implementation + void Init() override; + void Activate() override; + void Deactivate() override; + //////////////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////////////// + // AZTickBus interface implementation + void OnTick(float deltaTime, AZ::ScriptTimePoint time) override; + //////////////////////////////////////////////////////////////////////// + }; + +} // namespace Profiler diff --git a/Gems/Profiler/Code/profiler_files.cmake b/Gems/Profiler/Code/profiler_files.cmake new file mode 100644 index 0000000000..4f774fd024 --- /dev/null +++ b/Gems/Profiler/Code/profiler_files.cmake @@ -0,0 +1,14 @@ +# +# 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 +# +# + +set(FILES + Include/Profiler/ProfilerBus.h + Source/ProfilerModuleInterface.h + Source/ProfilerSystemComponent.cpp + Source/ProfilerSystemComponent.h +) diff --git a/Gems/Profiler/Code/profiler_shared_files.cmake b/Gems/Profiler/Code/profiler_shared_files.cmake new file mode 100644 index 0000000000..b8ee476e23 --- /dev/null +++ b/Gems/Profiler/Code/profiler_shared_files.cmake @@ -0,0 +1,11 @@ +# +# 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 +# +# + +set(FILES + Source/ProfilerModule.cpp +) diff --git a/Gems/Profiler/gem.json b/Gems/Profiler/gem.json new file mode 100644 index 0000000000..460a5bde99 --- /dev/null +++ b/Gems/Profiler/gem.json @@ -0,0 +1,16 @@ +{ + "gem_name": "Profiler", + "display_name": "Profiler", + "license": "Apache-2.0 Or MIT", + "origin": "Open 3D Engine - o3de.org", + "type": "Code", + "summary": "A collection of utilities for capturing performance data", + "canonical_tags": [ + "Gem" + ], + "user_tags": [ + "Profiler" + ], + "icon_path": "preview.png", + "requirements": "" +} diff --git a/Gems/Profiler/preview.png b/Gems/Profiler/preview.png new file mode 100644 index 0000000000..0f393ac886 --- /dev/null +++ b/Gems/Profiler/preview.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ac9dd09bde78f389e3725ac49d61eff109857e004840bc0bc3881739df9618d +size 2217