MaliHwCounters.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include <AnKi/Core/MaliHwCounters.h>
  6. #define ANKI_HWCPIPE_ENABLE (ANKI_OS_ANDROID == 1)
  7. #if ANKI_HWCPIPE_ENABLE
  8. # include <ThirdParty/HwcPipe/hwcpipe.h>
  9. #endif
  10. namespace anki {
  11. MaliHwCounters::MaliHwCounters()
  12. {
  13. #if ANKI_HWCPIPE_ENABLE
  14. const hwcpipe::CpuCounterSet cpuCounters;
  15. const hwcpipe::GpuCounterSet gpuCounters = {hwcpipe::GpuCounter::GpuCycles, hwcpipe::GpuCounter::ExternalMemoryWriteBytes,
  16. hwcpipe::GpuCounter::ExternalMemoryReadBytes};
  17. hwcpipe::HWCPipe* hwc = newInstance<hwcpipe::HWCPipe>(CoreMemoryPool::getSingleton(), cpuCounters, gpuCounters);
  18. hwc->run();
  19. m_impl = hwc;
  20. #else
  21. (void)m_impl; // Shut up the compiler
  22. #endif
  23. }
  24. MaliHwCounters::~MaliHwCounters()
  25. {
  26. #if ANKI_HWCPIPE_ENABLE
  27. hwcpipe::HWCPipe* hwc = static_cast<hwcpipe::HWCPipe*>(m_impl);
  28. hwc->stop();
  29. deleteInstance(CoreMemoryPool::getSingleton(), hwc);
  30. m_impl = nullptr;
  31. #endif
  32. }
  33. void MaliHwCounters::sample(MaliHwCountersOut& out)
  34. {
  35. out = {};
  36. #if ANKI_HWCPIPE_ENABLE
  37. hwcpipe::HWCPipe* hwc = static_cast<hwcpipe::HWCPipe*>(m_impl);
  38. const hwcpipe::Measurements m = hwc->sample();
  39. if(m.gpu)
  40. {
  41. auto readCounter = [&](hwcpipe::GpuCounter counter) -> U64 {
  42. auto it = m.gpu->find(counter);
  43. ANKI_ASSERT(it != m.gpu->end());
  44. const hwcpipe::Value val = it->second;
  45. return val.get<U64>();
  46. };
  47. out.m_gpuActive = readCounter(hwcpipe::GpuCounter::GpuCycles);
  48. out.m_readBandwidth = readCounter(hwcpipe::GpuCounter::ExternalMemoryReadBytes);
  49. out.m_writeBandwidth = readCounter(hwcpipe::GpuCounter::ExternalMemoryWriteBytes);
  50. }
  51. #endif
  52. }
  53. } // end namespace anki