StatisticalProfilerHelpers.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 <AzTest/AzTest.h>
  10. #include <AzCore/Math/Crc.h>
  11. #include <AzCore/Statistics/StatisticalProfilerProxy.h>
  12. #include <AzCore/std/parallel/mutex.h>
  13. #include <AzCore/std/parallel/shared_mutex.h>
  14. #include <AzCore/std/parallel/spin_mutex.h>
  15. #include <AzCore/std/parallel/thread.h>
  16. #include <AzCore/std/string/string.h>
  17. #include <AzCore/UnitTest/TestTypes.h>
  18. #include <AzCore/UnitTest/UnitTest.h>
  19. #include <AzCore/Utils/TypeHash.h>
  20. namespace UnitTest
  21. {
  22. AZ_TYPE_SAFE_INTEGRAL(StringHash, size_t);
  23. static constexpr int SmallIterationCount = 10;
  24. static constexpr int MediumIterationCount = 1000;
  25. static constexpr int LargeIterationCount = 100000;
  26. static constexpr AZ::u32 ProfilerProxyGroup = AZ_CRC_CE("StatisticalProfilerProxyTests");
  27. template<typename StatIdType>
  28. StatIdType ConvertNameToStatId(const AZStd::string& name);
  29. template<>
  30. inline AZStd::string ConvertNameToStatId<AZStd::string>(const AZStd::string& name)
  31. {
  32. return name;
  33. }
  34. template<>
  35. inline StringHash ConvertNameToStatId<StringHash>(const AZStd::string& name)
  36. {
  37. AZStd::hash<AZStd::string> hasher;
  38. return StringHash(hasher(name));
  39. }
  40. template<>
  41. inline AZ::Crc32 ConvertNameToStatId<AZ::Crc32>(const AZStd::string& name)
  42. {
  43. return AZ::Crc32(name);
  44. }
  45. template<>
  46. inline AZ::HashValue32 ConvertNameToStatId<AZ::HashValue32>(const AZStd::string& name)
  47. {
  48. return AZ::TypeHash32(name.c_str());
  49. }
  50. template<>
  51. inline AZ::HashValue64 ConvertNameToStatId<AZ::HashValue64>(const AZStd::string& name)
  52. {
  53. return AZ::TypeHash64(name.c_str());
  54. }
  55. }//namespace UnitTest