PrefabBenchmarkFixture.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #if defined(HAVE_BENCHMARK)
  9. #pragma once
  10. #include <AzCore/UnitTest/TestTypes.h>
  11. #include <AzToolsFramework/Application/ToolsApplication.h>
  12. #include <Prefab/MockPrefabFileIOActionValidator.h>
  13. #include <Prefab/PrefabSystemComponent.h>
  14. #include <Prefab/PrefabTestData.h>
  15. #include <Prefab/PrefabTestUtils.h>
  16. namespace Benchmark
  17. {
  18. using namespace UnitTest::PrefabTestUtils;
  19. class PrefabBenchmarkHarness
  20. {
  21. virtual void SetupHarness(const benchmark::State& state) = 0;
  22. virtual void TeardownHarness(const benchmark::State& state) = 0;
  23. };
  24. class BM_Prefab
  25. : public UnitTest::AllocatorsBenchmarkFixture
  26. , public PrefabBenchmarkHarness
  27. , public UnitTest::TraceBusRedirector
  28. {
  29. public:
  30. void SetupHarness(const benchmark::State& state) override;
  31. void TeardownHarness(const benchmark::State& state) override;
  32. protected:
  33. void SetUp(const benchmark::State& state) override
  34. {
  35. SetupHarness(state);
  36. }
  37. void SetUp(benchmark::State& state) override
  38. {
  39. SetupHarness(state);
  40. }
  41. void TearDown(const benchmark::State& state) override
  42. {
  43. TeardownHarness(state);
  44. }
  45. void TearDown(benchmark::State& state) override
  46. {
  47. TeardownHarness(state);
  48. }
  49. AZ::Entity* CreateEntity(const char* entityName, const AZ::EntityId& parentId = AZ::EntityId());
  50. void CreateEntities(const unsigned int entityCount, AZStd::vector<AZ::Entity*>& entities);
  51. void SetEntityParent(const AZ::EntityId& entityId, const AZ::EntityId& parentId);
  52. void CreateFakePaths(const unsigned int pathCount);
  53. void SetUpMockValidatorForReadPrefab();
  54. void DeleteInstances(const AzToolsFramework::Prefab::InstanceList& instances);
  55. void SetupPrefabSystem();
  56. void TearDownPrefabSystem();
  57. void ResetPrefabSystem();
  58. //prefab specific
  59. AZStd::unique_ptr<AzToolsFramework::ToolsApplication> m_app;
  60. AzToolsFramework::Prefab::PrefabSystemComponent* m_prefabSystemComponent = nullptr;
  61. AzToolsFramework::Prefab::PrefabLoaderInterface* m_prefabLoaderInterface = nullptr;
  62. AzToolsFramework::Prefab::InstanceUpdateExecutorInterface* m_instanceUpdateExecutorInterface = nullptr;
  63. const char* m_pathString = "path/to/template";
  64. AZStd::vector<AZ::IO::Path> m_paths;
  65. AZStd::unique_ptr <UnitTest::MockPrefabFileIOActionValidator> m_mockIOActionValidator;
  66. };
  67. }
  68. #endif