hwcpipe.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Copyright (c) 2019 ARM Limited.
  3. *
  4. * SPDX-License-Identifier: MIT
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to
  8. * deal in the Software without restriction, including without limitation the
  9. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  10. * sell copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. * SOFTWARE.
  23. */
  24. #pragma once
  25. #include "cpu_profiler.h"
  26. #include "gpu_profiler.h"
  27. #include <functional>
  28. #include <memory>
  29. namespace hwcpipe
  30. {
  31. struct Measurements
  32. {
  33. const CpuMeasurements *cpu{nullptr};
  34. const GpuMeasurements *gpu{nullptr};
  35. };
  36. /** A class that collects CPU/GPU performance data. */
  37. class HWCPipe
  38. {
  39. public:
  40. #ifndef HWCPIPE_NO_JSON
  41. // Initializes HWCPipe via a JSON configuration string
  42. explicit HWCPipe(const char *json_string);
  43. #endif
  44. // Initializes HWCPipe with the specified counters
  45. HWCPipe(CpuCounterSet enabled_cpu_counters, GpuCounterSet enabled_gpu_counters);
  46. // Initializes HWCPipe with a default set of counters
  47. HWCPipe();
  48. // Sets the enabled counters for the CPU profiler
  49. void set_enabled_cpu_counters(CpuCounterSet counters);
  50. // Sets the enabled counters for the GPU profiler
  51. void set_enabled_gpu_counters(GpuCounterSet counters);
  52. // Starts a profiling session
  53. void run();
  54. // Sample the counters. The function returns pointers to the CPU and GPU
  55. // measurements maps, if the corresponding profiler is enabled.
  56. // The entries in the maps are the counters that are both available and enabled.
  57. // A profiling session must be running when sampling the counters.
  58. Measurements sample();
  59. // Stops the active profiling session
  60. void stop();
  61. const CpuProfiler *cpu_profiler()
  62. {
  63. return cpu_profiler_.get();
  64. }
  65. const GpuProfiler *gpu_profiler()
  66. {
  67. return gpu_profiler_.get();
  68. }
  69. private:
  70. std::unique_ptr<CpuProfiler> cpu_profiler_{};
  71. std::unique_ptr<GpuProfiler> gpu_profiler_{};
  72. void create_profilers(CpuCounterSet enabled_cpu_counters, GpuCounterSet enabled_gpu_counters);
  73. };
  74. } // namespace hwcpipe