UnityProfilerInterfaceFunctions.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #pragma once
  2. #include <IUnityProfiler.h>
  3. #include <memory>
  4. namespace unity
  5. {
  6. namespace webrtc
  7. {
  8. template<typename T>
  9. inline int CreateCategory(T* instance, UnityProfilerCategoryId* category, const char* name, uint32_t unused)
  10. {
  11. return instance->CreateCategory(category, name, unused);
  12. }
  13. template<>
  14. inline int
  15. CreateCategory(IUnityProfiler* instance, UnityProfilerCategoryId* category, const char* name, uint32_t unused)
  16. {
  17. // IUnityProfiler(V1) is not supported CreateCategory.
  18. *category = kUnityProfilerCategoryRender;
  19. return 0;
  20. }
  21. class UnityProfiler
  22. {
  23. public:
  24. virtual void BeginSample(const UnityProfilerMarkerDesc* markerDesc) = 0;
  25. virtual void BeginSample(
  26. const UnityProfilerMarkerDesc* markerDesc,
  27. uint16_t eventDataCount,
  28. const UnityProfilerMarkerData* eventData) = 0;
  29. virtual void EndSample(const UnityProfilerMarkerDesc* markerDesc) = 0;
  30. virtual int IsAvailable() = 0;
  31. virtual int CreateMarker(
  32. const UnityProfilerMarkerDesc** desc,
  33. const char* name,
  34. UnityProfilerCategoryId category,
  35. UnityProfilerMarkerFlags flags,
  36. int eventDataCount) = 0;
  37. virtual int SetMarkerMetadataName(
  38. const UnityProfilerMarkerDesc* desc,
  39. int index,
  40. const char* metadataName,
  41. UnityProfilerMarkerDataType metadataType,
  42. UnityProfilerMarkerDataUnit metadataUnit) = 0;
  43. virtual int CreateCategory(UnityProfilerCategoryId* category, const char* name, uint32_t unused) = 0;
  44. virtual int RegisterThread(UnityProfilerThreadId* threadId, const char* groupName, const char* name) = 0;
  45. virtual int UnregisterThread(UnityProfilerThreadId threadId) = 0;
  46. virtual ~UnityProfiler() = default;
  47. static std::unique_ptr<UnityProfiler> Get(IUnityInterfaces* unityInterfaces);
  48. };
  49. template<typename T>
  50. class UnityProfilerImpl : public UnityProfiler
  51. {
  52. public:
  53. UnityProfilerImpl(T* profiler)
  54. : profiler_(profiler)
  55. {
  56. }
  57. ~UnityProfilerImpl() override = default;
  58. void BeginSample(const UnityProfilerMarkerDesc* markerDesc) override { profiler_->BeginSample(markerDesc); }
  59. void BeginSample(
  60. const UnityProfilerMarkerDesc* markerDesc,
  61. uint16_t eventDataCount,
  62. const UnityProfilerMarkerData* eventData) override
  63. {
  64. profiler_->BeginSample(markerDesc, eventDataCount, eventData);
  65. }
  66. void EndSample(const UnityProfilerMarkerDesc* markerDesc) override { profiler_->EndSample(markerDesc); }
  67. int IsAvailable() override { return profiler_->IsAvailable(); }
  68. int CreateMarker(
  69. const UnityProfilerMarkerDesc** desc,
  70. const char* name,
  71. UnityProfilerCategoryId category,
  72. UnityProfilerMarkerFlags flags,
  73. int eventDataCount) override
  74. {
  75. return profiler_->CreateMarker(desc, name, category, flags, eventDataCount);
  76. }
  77. int SetMarkerMetadataName(
  78. const UnityProfilerMarkerDesc* desc,
  79. int index,
  80. const char* metadataName,
  81. UnityProfilerMarkerDataType metadataType,
  82. UnityProfilerMarkerDataUnit metadataUnit) override
  83. {
  84. return profiler_->SetMarkerMetadataName(desc, index, metadataName, metadataType, metadataUnit);
  85. }
  86. int CreateCategory(UnityProfilerCategoryId* category, const char* name, uint32_t unused) override
  87. {
  88. return unity::webrtc::CreateCategory(profiler_, category, name, unused);
  89. }
  90. int RegisterThread(UnityProfilerThreadId* threadId, const char* groupName, const char* name) override
  91. {
  92. return profiler_->RegisterThread(threadId, groupName, name);
  93. }
  94. int UnregisterThread(UnityProfilerThreadId threadId) override { return profiler_->UnregisterThread(threadId); }
  95. private:
  96. T* profiler_;
  97. };
  98. }
  99. }