PerformanceMetrics.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright 2022 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <array>
  5. #include <shared_mutex>
  6. #include "Common/CommonTypes.h"
  7. #include "VideoCommon/PerformanceTracker.h"
  8. namespace Core
  9. {
  10. class System;
  11. }
  12. class PerformanceMetrics
  13. {
  14. public:
  15. PerformanceMetrics() = default;
  16. ~PerformanceMetrics() = default;
  17. PerformanceMetrics(const PerformanceMetrics&) = delete;
  18. PerformanceMetrics& operator=(const PerformanceMetrics&) = delete;
  19. PerformanceMetrics(PerformanceMetrics&&) = delete;
  20. PerformanceMetrics& operator=(PerformanceMetrics&&) = delete;
  21. // Count Functions
  22. void Reset();
  23. void CountFrame();
  24. void CountVBlank();
  25. void CountThrottleSleep(DT sleep);
  26. void CountPerformanceMarker(Core::System& system, s64 cyclesLate);
  27. // Getter Functions
  28. double GetFPS() const;
  29. double GetVPS() const;
  30. double GetSpeed() const;
  31. double GetMaxSpeed() const;
  32. double GetLastSpeedDenominator() const;
  33. // ImGui Functions
  34. void DrawImGuiStats(const float backbuffer_scale);
  35. private:
  36. PerformanceTracker m_fps_counter{"render_times.txt"};
  37. PerformanceTracker m_vps_counter{"vblank_times.txt"};
  38. PerformanceTracker m_speed_counter{std::nullopt, 1000000};
  39. double m_graph_max_time = 0.0;
  40. mutable std::shared_mutex m_time_lock;
  41. u8 m_time_index = 0;
  42. std::array<TimePoint, 256> m_real_times{};
  43. std::array<TimePoint, 256> m_cpu_times{};
  44. DT m_time_sleeping{};
  45. };
  46. extern PerformanceMetrics g_perf_metrics;