Debian Codegraph @

Source/Core/VideoCommon/PerformanceTracker.h

raw symbols SCIP
1 // Copyright 2022 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #include <atomic>
7 #include <deque>
8 #include <fstream>
9 #include <optional>
10
11 #include "Common/CommonTypes.h"
12 #include "Common/SPSCQueue.h"
13
14 class PerformanceTracker
15 {
16 public:
17 PerformanceTracker(std::optional<std::string> log_name = std::nullopt,
18 const std::optional<DT> sample_window_duration = std::nullopt);
19 ~PerformanceTracker() = default;
20
21 PerformanceTracker(const PerformanceTracker&) = delete;
22 PerformanceTracker& operator=(const PerformanceTracker&) = delete;
23 PerformanceTracker(PerformanceTracker&&) = delete;
24 PerformanceTracker& operator=(PerformanceTracker&&) = delete;
25
26 void Reset();
27
28 // Calls must come from the same thread.
29 // UpdateStats is expected to be called regularly to empty the SPSC queue.
30 void UpdateStats();
31 void ImPlotPlotLines(const char* label) const;
32
33 // May call from any thread, but not concurrently, not that you'd want to..
34 void Count();
35
36 // May call from any thread.
37 DT GetSampleWindow() const;
38 double GetHzAvg() const;
39 DT GetDtAvg() const;
40 DT GetDtStd() const;
41 DT GetLastRawDt() const;
42 void InvalidateLastTime();
43
44 private:
45 void LogRenderTimeToFile(DT val);
46
47 void HandleRawDt(DT value);
48 void PushFront(DT value);
49 void PopBack();
50
51 // Name of log file and file stream
52 std::optional<std::string> m_log_name;
53 std::ofstream m_bench_file;
54
55 // Last time Count() was called
56 TimePoint m_last_time;
57 std::atomic<bool> m_is_last_time_sane = false;
58
59 // Push'd from Count()
60 // and Pop'd from UpdateStats()
61 Common::SPSCQueue<DT> m_raw_dts;
62 std::atomic<DT> m_last_raw_dt = DT::zero();
63
64 // Amount of time to sample dt's over (defaults to config)
65 const std::optional<DT> m_sample_window_duration;
66
67 // Queue + Running Total used to calculate average dt
68 DT m_dt_total = DT::zero();
69 std::deque<DT> m_dt_queue;
70
71 // Average rate/time throughout the window
72 std::atomic<DT> m_dt_avg = DT::zero(); // Uses Moving Average
73 std::atomic<double> m_hz_avg = 0.0; // Uses Moving Average + Euler Average
74 std::atomic<DT> m_dt_std = DT::zero();
75 };