profiler_reporting.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // Copyright 2015 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <cstddef>
  6. #include <vector>
  7. #include "common/profiler.h"
  8. #include "common/synchronized_wrapper.h"
  9. namespace Common {
  10. namespace Profiling {
  11. struct TimingCategoryInfo {
  12. static const unsigned int NO_PARENT = -1;
  13. TimingCategory* category;
  14. const char* name;
  15. unsigned int parent;
  16. };
  17. struct ProfilingFrameResult {
  18. /// Time since the last delivered frame
  19. Duration interframe_time;
  20. /// Time spent processing a frame, excluding VSync
  21. Duration frame_time;
  22. /// Total amount of time spent inside each category in this frame. Indexed by the category id
  23. std::vector<Duration> time_per_category;
  24. };
  25. class ProfilingManager final {
  26. public:
  27. ProfilingManager();
  28. unsigned int RegisterTimingCategory(TimingCategory* category, const char* name);
  29. void SetTimingCategoryParent(unsigned int category, unsigned int parent);
  30. const std::vector<TimingCategoryInfo>& GetTimingCategoriesInfo() const {
  31. return timing_categories;
  32. }
  33. /// This should be called after swapping screen buffers.
  34. void BeginFrame();
  35. /// This should be called before swapping screen buffers.
  36. void FinishFrame();
  37. /// Get the timing results from the previous frame. This is updated when you call FinishFrame().
  38. const ProfilingFrameResult& GetPreviousFrameResults() const {
  39. return results;
  40. }
  41. private:
  42. std::vector<TimingCategoryInfo> timing_categories;
  43. Clock::time_point last_frame_end;
  44. Clock::time_point this_frame_start;
  45. ProfilingFrameResult results;
  46. };
  47. struct AggregatedDuration {
  48. Duration avg, min, max;
  49. };
  50. struct AggregatedFrameResult {
  51. /// Time since the last delivered frame
  52. AggregatedDuration interframe_time;
  53. /// Time spent processing a frame, excluding VSync
  54. AggregatedDuration frame_time;
  55. float fps;
  56. /// Total amount of time spent inside each category in this frame. Indexed by the category id
  57. std::vector<AggregatedDuration> time_per_category;
  58. };
  59. class TimingResultsAggregator final {
  60. public:
  61. TimingResultsAggregator(size_t window_size);
  62. void Clear();
  63. void SetNumberOfCategories(size_t n);
  64. void AddFrame(const ProfilingFrameResult& frame_result);
  65. AggregatedFrameResult GetAggregatedResults() const;
  66. size_t max_window_size;
  67. size_t window_size;
  68. size_t cursor;
  69. std::vector<Duration> interframe_times;
  70. std::vector<Duration> frame_times;
  71. std::vector<std::vector<Duration>> times_per_category;
  72. };
  73. ProfilingManager& GetProfilingManager();
  74. SynchronizedRef<TimingResultsAggregator> GetTimingResultsAggregator();
  75. } // namespace Profiling
  76. } // namespace Common