ScopedProfiler.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "pch.h"
  2. #include "ScopedProfiler.h"
  3. #include "UnityProfilerInterfaceFunctions.h"
  4. namespace unity
  5. {
  6. namespace webrtc
  7. {
  8. ScopedProfiler::ScopedProfiler(UnityProfiler* profiler, const UnityProfilerMarkerDesc& desc)
  9. : profiler_(profiler)
  10. , m_desc(&desc)
  11. {
  12. RTC_DCHECK(profiler);
  13. if (profiler_->IsAvailable())
  14. profiler_->BeginSample(m_desc);
  15. }
  16. ScopedProfiler::~ScopedProfiler()
  17. {
  18. if (profiler_->IsAvailable())
  19. profiler_->EndSample(m_desc);
  20. }
  21. ScopedProfilerThread::ScopedProfilerThread(UnityProfiler* profiler, const char* groupName, const char* name)
  22. : profiler_(profiler)
  23. {
  24. RTC_DCHECK(profiler);
  25. RTC_DCHECK(groupName);
  26. RTC_DCHECK(name);
  27. if (profiler_->IsAvailable())
  28. {
  29. int result = profiler_->RegisterThread(&threadId_, groupName, name);
  30. if (result)
  31. {
  32. RTC_LOG(LS_INFO) << "IUnityProfiler::RegisterThread error:" << result;
  33. throw;
  34. }
  35. }
  36. }
  37. ScopedProfilerThread ::~ScopedProfilerThread()
  38. {
  39. if (profiler_->IsAvailable())
  40. profiler_->UnregisterThread(threadId_);
  41. }
  42. } // end namespace webrtc
  43. } // end namespace unity