-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add superluminal, Tracy and Optick profilers integration as Gems #834
Open
guillaume-haerinck
wants to merge
5
commits into
o3de:development
Choose a base branch
from
guillaume-haerinck:superluminal_profiler
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,390
−0
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
712f671
Add superluminal profiler integration
guillaume-haerinck 7173ae8
Add support for tracy profiler
guillaume-haerinck a83ff67
add basic optick support and clang-format everything
guillaume-haerinck e370d46
Move optick into 3rd party folder
guillaume-haerinck 6581368
Move optick into 3rd party folder
guillaume-haerinck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
Gems/ExternalProfilers/SuperluminalProfiler/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
# | ||
# | ||
|
||
o3de_gem_setup("SuperluminalProfiler") | ||
|
||
add_subdirectory(Code) |
60 changes: 60 additions & 0 deletions
60
Gems/ExternalProfilers/SuperluminalProfiler/Code/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# | ||
# 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(SUPERLUMINAL_API_PATH "C:/Program Files/Superluminal/Performance/API" CACHE PATH "Path to the Superluminal 3rd party profiler API folder.") | ||
list(APPEND CMAKE_MODULE_PATH ${SUPERLUMINAL_API_PATH}) | ||
|
||
find_package(SuperluminalAPI REQUIRED) | ||
|
||
ly_add_target( | ||
NAME ${gem_name}.Static STATIC | ||
NAMESPACE Gem | ||
FILES_CMAKE | ||
superluminalprofiler_files.cmake | ||
INCLUDE_DIRECTORIES | ||
PUBLIC | ||
Include | ||
PRIVATE | ||
Source | ||
${SuperluminalAPI_INCLUDE_DIRS} | ||
BUILD_DEPENDENCIES | ||
PUBLIC | ||
AZ::AzCore | ||
AZ::AzFramework | ||
PRIVATE | ||
${SuperluminalAPI_LIBS_RELEASE} | ||
) | ||
|
||
ly_add_target( | ||
NAME ${gem_name} ${PAL_TRAIT_MONOLITHIC_DRIVEN_MODULE_TYPE} | ||
NAMESPACE Gem | ||
FILES_CMAKE | ||
superluminalprofiler_shared_files.cmake | ||
INCLUDE_DIRECTORIES | ||
PUBLIC | ||
Include | ||
PRIVATE | ||
Source | ||
BUILD_DEPENDENCIES | ||
PRIVATE | ||
Gem::${gem_name}.Static | ||
) | ||
|
||
ly_add_source_properties( | ||
SOURCES | ||
Source/ProfilerModule.cpp | ||
PROPERTY COMPILE_DEFINITIONS | ||
VALUES | ||
O3DE_GEM_NAME=${gem_name} | ||
O3DE_GEM_VERSION=${gem_version}) | ||
|
||
ly_create_alias(NAME ${gem_name}.Servers NAMESPACE Gem TARGETS Gem::${gem_name}) | ||
ly_create_alias(NAME ${gem_name}.Builders NAMESPACE Gem TARGETS Gem::${gem_name}) | ||
ly_create_alias(NAME ${gem_name}.Clients NAMESPACE Gem TARGETS Gem::${gem_name}) | ||
ly_create_alias(NAME ${gem_name}.Unified NAMESPACE Gem TARGETS Gem::${gem_name}) | ||
ly_create_alias(NAME ${gem_name}.Tools NAMESPACE Gem TARGETS Gem::${gem_name}) |
64 changes: 64 additions & 0 deletions
64
Gems/ExternalProfilers/SuperluminalProfiler/Code/Source/CpuProfiler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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 <CpuProfiler.h> | ||
|
||
#include <AzCore/Interface/Interface.h> | ||
#include <AzCore/Serialization/SerializeContext.h> | ||
#include <Superluminal/PerformanceAPI.h> | ||
|
||
namespace SuperluminalProfiler | ||
{ | ||
void CpuProfiler::Init() | ||
{ | ||
AZ::Interface<AZ::Debug::Profiler>::Register(this); | ||
m_initialized = true; | ||
AZ::SystemTickBus::Handler::BusConnect(); | ||
} | ||
|
||
void CpuProfiler::Shutdown() | ||
{ | ||
if (!m_initialized) | ||
{ | ||
return; | ||
} | ||
|
||
// When this call is made, no more thread profiling calls can be performed anymore | ||
AZ::Interface<AZ::Debug::Profiler>::Unregister(this); | ||
|
||
// Wait for the remaining threads that might still be processing its profiling calls | ||
AZStd::unique_lock<AZStd::shared_mutex> shutdownLock(m_shutdownMutex); | ||
AZ::SystemTickBus::Handler::BusDisconnect(); | ||
} | ||
|
||
void CpuProfiler::BeginRegion(const AZ::Debug::Budget* budget, const char* eventName, ...) | ||
{ | ||
// Try to lock here, the shutdownMutex will only be contested when the CpuProfiler is shutting down. | ||
if (m_shutdownMutex.try_lock_shared()) | ||
{ | ||
PerformanceAPI_BeginEvent(eventName, budget->Name(), budget->Crc()); | ||
m_shutdownMutex.unlock_shared(); | ||
} | ||
} | ||
|
||
void CpuProfiler::EndRegion([[maybe_unused]] const AZ::Debug::Budget* budget) | ||
{ | ||
// Try to lock here, the shutdownMutex will only be contested when the CpuProfiler is shutting down. | ||
if (m_shutdownMutex.try_lock_shared()) | ||
{ | ||
PerformanceAPI_EndEvent(); | ||
m_shutdownMutex.unlock_shared(); | ||
} | ||
} | ||
|
||
void CpuProfiler::OnSystemTick() | ||
{ | ||
PerformanceAPI::InstrumentationScope("SystemTick", nullptr, PERFORMANCEAPI_MAKE_COLOR(0, 255, 0)); | ||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
Gems/ExternalProfilers/SuperluminalProfiler/Code/Source/CpuProfiler.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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/Component/TickBus.h> | ||
#include <AzCore/Debug/Profiler.h> | ||
#include <AzCore/Memory/SystemAllocator.h> | ||
#include <AzCore/Name/Name.h> | ||
#include <AzCore/RTTI/RTTI.h> | ||
#include <AzCore/std/parallel/mutex.h> | ||
#include <AzCore/std/parallel/shared_mutex.h> | ||
|
||
namespace SuperluminalProfiler | ||
{ | ||
class CpuProfiler final | ||
: public AZ::Debug::Profiler | ||
, public AZ::SystemTickBus::Handler | ||
{ | ||
public: | ||
AZ_RTTI(CpuProfiler, "{A05E7DC4-AB00-41BC-A739-8E58908CB84F}", AZ::Debug::Profiler); | ||
AZ_CLASS_ALLOCATOR(CpuProfiler, AZ::SystemAllocator); | ||
|
||
CpuProfiler() = default; | ||
~CpuProfiler() = default; | ||
|
||
//! Registers/un-registers the AZ::Debug::Profiler instance to the interface | ||
void Init(); | ||
void Shutdown(); | ||
|
||
//! AZ::Debug::Profiler overrides... | ||
void BeginRegion(const AZ::Debug::Budget* budget, const char* eventName, ...) final override; | ||
void EndRegion(const AZ::Debug::Budget* budget) final override; | ||
|
||
//! Check to see if a programmatic capture is currently in progress, implies | ||
//! that the profiler is active if returns True. | ||
bool IsContinuousCaptureInProgress() const; | ||
|
||
//! AZ::SystemTickBus::Handler overrides | ||
//! When fired, the profiler collects all profiling data from registered threads and updates | ||
//! m_timeRegionMap so that the next frame has up-to-date profiling data. | ||
void OnSystemTick() final override; | ||
|
||
private: | ||
// This lock will only be contested when the CpuProfiler's Shutdown() method has been called | ||
AZStd::shared_mutex m_shutdownMutex; | ||
|
||
bool m_initialized = false; | ||
}; | ||
} |
50 changes: 50 additions & 0 deletions
50
Gems/ExternalProfilers/SuperluminalProfiler/Code/Source/ProfilerModule.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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 <ProfilerSystemComponent.h> | ||
|
||
#include <AzCore/Memory/SystemAllocator.h> | ||
#include <AzCore/Module/Module.h> | ||
|
||
namespace SuperluminalProfiler | ||
{ | ||
class ProfilerModule | ||
: public AZ::Module | ||
{ | ||
public: | ||
AZ_RTTI(ProfilerModule, "{7C666AFB-E699-42FB-8F32-DAEE5A62CD01}", AZ::Module); | ||
AZ_CLASS_ALLOCATOR(ProfilerModule, AZ::SystemAllocator); | ||
|
||
ProfilerModule() | ||
{ | ||
// 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<ProfilerSystemComponent>(), | ||
}; | ||
} | ||
}; | ||
} | ||
|
||
#if defined(O3DE_GEM_NAME) | ||
AZ_DECLARE_MODULE_CLASS(AZ_JOIN(Gem_, O3DE_GEM_NAME), SuperluminalProfiler::ProfilerModule) | ||
#else | ||
AZ_DECLARE_MODULE_CLASS(Gem_Profiler, SuperluminalProfiler::ProfilerModule) | ||
#endif |
103 changes: 103 additions & 0 deletions
103
Gems/ExternalProfilers/SuperluminalProfiler/Code/Source/ProfilerSystemComponent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* 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 "ProfilerSystemComponent.h" | ||
|
||
#include <AzCore/RTTI/BehaviorContext.h> | ||
#include <AzCore/Serialization/EditContext.h> | ||
#include <AzCore/Serialization/EditContextConstants.inl> | ||
#include <AzCore/Serialization/SerializeContext.h> | ||
|
||
namespace SuperluminalProfiler | ||
{ | ||
static constexpr AZ::Crc32 profilerServiceCrc = AZ_CRC_CE("ProfilerService"); | ||
|
||
void ProfilerSystemComponent::Reflect(AZ::ReflectContext* context) | ||
{ | ||
if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context)) | ||
{ | ||
serialize->Class<ProfilerSystemComponent, AZ::Component>() | ||
->Version(0); | ||
} | ||
} | ||
|
||
void ProfilerSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided) | ||
{ | ||
provided.push_back(profilerServiceCrc); | ||
} | ||
|
||
void ProfilerSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible) | ||
{ | ||
incompatible.push_back(profilerServiceCrc); | ||
} | ||
|
||
void ProfilerSystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required) | ||
{ | ||
} | ||
|
||
void ProfilerSystemComponent::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent) | ||
{ | ||
} | ||
|
||
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() | ||
{ | ||
m_cpuProfiler.Init(); | ||
} | ||
|
||
void ProfilerSystemComponent::Deactivate() | ||
{ | ||
m_cpuProfiler.Shutdown(); | ||
} | ||
|
||
bool ProfilerSystemComponent::IsActive() const | ||
{ | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While superluminal API does not provide anything to trigger a record from the editor, we don't want to leave this unimplemeted either as we can only have one active profiler at a time (with the exception of Pix that is doing its hook directly in profiler.h) |
||
} | ||
|
||
void ProfilerSystemComponent::SetActive([[maybe_unused]] bool enabled) | ||
{ | ||
|
||
} | ||
|
||
bool ProfilerSystemComponent::CaptureFrame([[maybe_unused]] const AZStd::string& outputFilePath) | ||
{ | ||
return true; | ||
} | ||
|
||
bool ProfilerSystemComponent::StartCapture([[maybe_unused]] AZStd::string outputFilePath) | ||
{ | ||
return true; | ||
} | ||
|
||
bool ProfilerSystemComponent::EndCapture() | ||
{ | ||
return true; | ||
} | ||
|
||
bool ProfilerSystemComponent::IsCaptureInProgress() const | ||
{ | ||
return false; | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that only one profiler can be active at a time, I might want to assert there, but ideally I should use a mechanism to say that when this gem is enabled none of the other profiling gem can be enabled, I don't know if we have something like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is, kinda-of. There is a field in gems.json called
provided_unique_service
that you can set to any string, and the scripts to enable gems should check against this. We did this for PhysX4 vs PhysX5https://github.com/o3de/o3de/blob/f29613a5c80d8dbc53016bdaaf3849cd6d77f60f/Gems/PhysX/Core/PhysX4/gem.json#L26
https://github.com/o3de/o3de/blob/f29613a5c80d8dbc53016bdaaf3849cd6d77f60f/Gems/PhysX/Core/PhysX5/gem.json#L26