ProfilerSystemComponent.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "ProfilerSystemComponent.h"
  9. #include <AzCore/IO/FileIO.h>
  10. #include <AzCore/RTTI/BehaviorContext.h>
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <AzCore/Serialization/EditContextConstants.inl>
  13. #include <AzCore/Serialization/SerializeContext.h>
  14. #include <optick.h>
  15. namespace OptickProfiler
  16. {
  17. static constexpr AZ::Crc32 profilerServiceCrc = AZ_CRC_CE("ProfilerService");
  18. void ProfilerSystemComponent::Reflect(AZ::ReflectContext* context)
  19. {
  20. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  21. {
  22. serialize->Class<ProfilerSystemComponent, AZ::Component>()->Version(0);
  23. }
  24. }
  25. void ProfilerSystemComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
  26. {
  27. provided.push_back(profilerServiceCrc);
  28. }
  29. void ProfilerSystemComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
  30. {
  31. incompatible.push_back(profilerServiceCrc);
  32. }
  33. void ProfilerSystemComponent::GetRequiredServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& required)
  34. {
  35. }
  36. void ProfilerSystemComponent::GetDependentServices([[maybe_unused]] AZ::ComponentDescriptor::DependencyArrayType& dependent)
  37. {
  38. }
  39. ProfilerSystemComponent::ProfilerSystemComponent()
  40. {
  41. if (AZ::Debug::ProfilerSystemInterface::Get() == nullptr)
  42. {
  43. AZ::Debug::ProfilerSystemInterface::Register(this);
  44. }
  45. }
  46. ProfilerSystemComponent::~ProfilerSystemComponent()
  47. {
  48. if (AZ::Debug::ProfilerSystemInterface::Get() == this)
  49. {
  50. AZ::Debug::ProfilerSystemInterface::Unregister(this);
  51. }
  52. }
  53. void ProfilerSystemComponent::Activate()
  54. {
  55. m_eventForwarder.Init();
  56. }
  57. void ProfilerSystemComponent::Deactivate()
  58. {
  59. m_eventForwarder.Shutdown();
  60. }
  61. bool ProfilerSystemComponent::IsActive() const
  62. {
  63. return false;
  64. }
  65. void ProfilerSystemComponent::SetActive([[maybe_unused]] bool enabled)
  66. {
  67. }
  68. bool ProfilerSystemComponent::CaptureFrame([[maybe_unused]] const AZStd::string& outputFilePath)
  69. {
  70. return false;
  71. }
  72. bool ProfilerSystemComponent::StartCapture(AZStd::string outputFilePath)
  73. {
  74. if (!m_cpuCaptureInProgress && Optick::StartCapture())
  75. {
  76. m_captureFile = AZStd::move(outputFilePath);
  77. m_cpuCaptureInProgress = true;
  78. return true;
  79. }
  80. return false;
  81. }
  82. bool ProfilerSystemComponent::EndCapture()
  83. {
  84. if (m_cpuCaptureInProgress && Optick::StopCapture())
  85. {
  86. m_cpuCaptureInProgress = false;
  87. return Optick::SaveCapture(m_captureFile.c_str());
  88. }
  89. return false;
  90. }
  91. bool ProfilerSystemComponent::IsCaptureInProgress() const
  92. {
  93. return m_cpuCaptureInProgress;
  94. }
  95. } // namespace OptickProfiler