| 1 |
|
| 2 |
|
| 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 |
|
| 29 |
|
| 30 |
void UpdateStats(); |
| 31 |
void ImPlotPlotLines(const char* label) const; |
| 32 |
|
| 33 |
|
| 34 |
void Count(); |
| 35 |
|
| 36 |
|
| 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 |
|
| 52 |
std::optional<std::string> m_log_name; |
| 53 |
std::ofstream m_bench_file; |
| 54 |
|
| 55 |
|
| 56 |
TimePoint m_last_time; |
| 57 |
std::atomic<bool> m_is_last_time_sane = false; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
Common::SPSCQueue<DT> m_raw_dts; |
| 62 |
std::atomic<DT> m_last_raw_dt = DT::zero(); |
| 63 |
|
| 64 |
|
| 65 |
const std::optional<DT> m_sample_window_duration; |
| 66 |
|
| 67 |
|
| 68 |
DT m_dt_total = DT::zero(); |
| 69 |
std::deque<DT> m_dt_queue; |
| 70 |
|
| 71 |
|
| 72 |
std::atomic<DT> m_dt_avg = DT::zero(); |
| 73 |
std::atomic<double> m_hz_avg = 0.0; |
| 74 |
std::atomic<DT> m_dt_std = DT::zero(); |
| 75 |
}; |