LoggingDataAggregator.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. #pragma once
  9. #include <AzCore/Component/EntityUtils.h>
  10. #include <AzCore/EBus/EBus.h>
  11. #include <AzCore/std/containers/unordered_map.h>
  12. #include <AzCore/Memory/SystemAllocator.h>
  13. #include <ScriptCanvas/Core/Endpoint.h>
  14. #include <ScriptCanvas/Core/ExecutionNotificationsBus.h>
  15. #include <ScriptCanvas/Variable/VariableCore.h>
  16. #include <Editor/View/Widgets/LoggingPanel/LoggingWindowTreeItems.h>
  17. #include <Editor/View/Widgets/LoggingPanel/LoggingTypes.h>
  18. namespace ScriptCanvasEditor
  19. {
  20. class LoggingDataAggregator;
  21. class LoggingDataRequests
  22. : public AZ::EBusTraits
  23. {
  24. public:
  25. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  26. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Single;
  27. using BusIdType = LoggingDataId;
  28. virtual bool IsCapturingData() const = 0;
  29. // Return the object to allow for certain large data elements to be passed by reference instead of by value.
  30. virtual const LoggingDataAggregator* FindLoggingData() const = 0;
  31. virtual void EnableRegistration(const AZ::NamedEntityId& namedEntityId, const ScriptCanvas::GraphIdentifier& graphIdentifier) = 0;
  32. virtual void DisableRegistration(const AZ::NamedEntityId& namedEntityId, const ScriptCanvas::GraphIdentifier& graphIdentifier) = 0;
  33. virtual AZ::NamedEntityId FindNamedEntityId(const AZ::EntityId& entityId) = 0;
  34. };
  35. using LoggingDataRequestBus = AZ::EBus<LoggingDataRequests>;
  36. class LoggingDataNotifications
  37. : public AZ::EBusTraits
  38. {
  39. public:
  40. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
  41. using BusIdType = LoggingDataId;
  42. virtual void OnDataCaptureBegin() {};
  43. virtual void OnDataCaptureEnd() {};
  44. virtual void OnEntityGraphRegistered([[maybe_unused]] const AZ::NamedEntityId& entityId, [[maybe_unused]] const ScriptCanvas::GraphIdentifier& assetId) {};
  45. virtual void OnEntityGraphUnregistered([[maybe_unused]] const AZ::NamedEntityId& entityId, [[maybe_unused]] const ScriptCanvas::GraphIdentifier& assetId) {}
  46. virtual void OnEnabledStateChanged([[maybe_unused]] bool isEnabled, [[maybe_unused]] const AZ::NamedEntityId& namedEntityId, [[maybe_unused]] const ScriptCanvas::GraphIdentifier& graphIdentifier) {}
  47. // TODO: Find a better spot for this
  48. virtual void OnTreeItemAdded() {}
  49. };
  50. using LoggingDataNotificationBus = AZ::EBus<LoggingDataNotifications>;
  51. // Container class for all of the local elements
  52. class LoggingDataAggregator
  53. : public LoggingDataRequestBus::Handler
  54. {
  55. public:
  56. AZ_CLASS_ALLOCATOR(LoggingDataAggregator, AZ::SystemAllocator,0);
  57. LoggingDataAggregator();
  58. ~LoggingDataAggregator();
  59. const LoggingDataId& GetDataId() const;
  60. // LoggedDataRequests
  61. const LoggingDataAggregator* FindLoggingData() const override;
  62. void EnableRegistration(const AZ::NamedEntityId& namedEntityId, const ScriptCanvas::GraphIdentifier& graphIdentifier) override;
  63. void DisableRegistration(const AZ::NamedEntityId& namedEntityId, const ScriptCanvas::GraphIdentifier& graphIdentifier) override;
  64. AZ::NamedEntityId FindNamedEntityId(const AZ::EntityId& entityId) override;
  65. ////
  66. bool IsCapturingData() const override = 0;
  67. virtual bool CanCaptureData() const = 0;
  68. // Should be bus methods, but don't want to copy data
  69. const EntityGraphRegistrationMap& GetEntityGraphRegistrationMap() const;
  70. const LoggingEntityMap& GetLoggingEntityMap() const;
  71. const LoggingAssetSet& GetLoggingAssetSet() const;
  72. ////
  73. //
  74. void ProcessSignal(const ScriptCanvas::Signal& signal);
  75. void ProcessNodeStateChanged(const ScriptCanvas::NodeStateChange& stateChangeSignal);
  76. void ProcessInputSignal(const ScriptCanvas::InputSignal& inputSignal);
  77. void ProcessOutputSignal(const ScriptCanvas::OutputSignal& outputSignal);
  78. void ProcessAnnotateNode(const ScriptCanvas::AnnotateNodeSignal& annotateNodeSignal);
  79. void ProcessVariableChangedSignal(const ScriptCanvas::VariableChange& variableChangeSignal);
  80. ////
  81. DebugLogRootItem* GetTreeRoot() const;
  82. void RegisterEntityName(const AZ::EntityId& entityId, AZStd::string_view entityName);
  83. void UnregisterEntityName(const AZ::EntityId& entityId);
  84. protected:
  85. // Methods here for child elements to do something with the data.
  86. virtual void OnRegistrationEnabled(const AZ::NamedEntityId& namedEntityId, const ScriptCanvas::GraphIdentifier& graphIdentifier);
  87. virtual void OnRegistrationDisabled(const AZ::NamedEntityId& namedEntityId, const ScriptCanvas::GraphIdentifier& graphIdentifier);
  88. void ResetData();
  89. void ResetLog();
  90. void RegisterScriptCanvas(const AZ::NamedEntityId& entityId, const ScriptCanvas::GraphIdentifier& graphIdentifier);
  91. void UnregisterScriptCanvas(const AZ::NamedEntityId& entityId, const ScriptCanvas::GraphIdentifier& graphIdentifier);
  92. // Parsed Data Information
  93. //
  94. // Debug Context Information
  95. //
  96. // Will be used for visually displaying the data once we get to it.
  97. AZStd::unordered_map< ScriptCanvas::Endpoint, AZStd::string > m_endpointData;
  98. AZStd::unordered_map< ScriptCanvas::VariableId, AZStd::string > m_variableData;
  99. ////
  100. AZStd::unordered_map< AZ::EntityId, AZStd::string > m_entityNameCache;
  101. AZStd::unordered_map< ScriptCanvas::GraphInfo, ExecutionLogTreeItem* > m_lastAggregateItemMap;
  102. AZStd::unordered_map< ScriptCanvas::GraphInfo, AZStd::vector<ExecutionIdentifier>> m_lastExecutionThreadMap;
  103. private:
  104. DebugLogRootItem* m_debugLogRoot;
  105. // State Information
  106. LoggingDataId m_id;
  107. bool m_ignoreRegistrations;
  108. bool m_hasAnchor;
  109. ScriptCanvas::Timestamp m_anchorTimeStamp;
  110. // TODO: Consider wrapping the three of these up into a single struct.
  111. EntityGraphRegistrationMap m_registrationMap;
  112. LoggingEntityMap m_loggingEntityMapping;
  113. LoggingAssetSet m_loggedAssetSet;
  114. };
  115. }