PerformanceTracker: Use std::deque instead of hand-rolled circular

queue.
This commit is contained in:
Jordan Woyak
2025-03-05 02:06:05 -06:00
parent b2ce3fbefc
commit c763961112
2 changed files with 33 additions and 90 deletions

View File

@ -3,7 +3,7 @@
#pragma once
#include <array>
#include <deque>
#include <fstream>
#include <optional>
#include <shared_mutex>
@ -12,26 +12,6 @@
class PerformanceTracker
{
private:
// Must be powers of 2 for masking to work
static constexpr u64 MAX_DT_QUEUE_SIZE = 1UL << 12;
static constexpr u64 MAX_QUALITY_GRAPH_SIZE = 1UL << 8;
static inline std::size_t IncrementIndex(const std::size_t index)
{
return (index + 1) & (MAX_DT_QUEUE_SIZE - 1);
}
static inline std::size_t DecrementIndex(const std::size_t index)
{
return (index - 1) & (MAX_DT_QUEUE_SIZE - 1);
}
static inline std::size_t GetDifference(const std::size_t begin, const std::size_t end)
{
return (end - begin) & (MAX_DT_QUEUE_SIZE - 1);
}
public:
PerformanceTracker(const std::optional<std::string> log_name = std::nullopt,
const std::optional<DT> sample_window_duration = std::nullopt);
@ -58,20 +38,13 @@ public:
void ImPlotPlotLines(const char* label) const;
private: // Functions for managing dt queue
inline void QueueClear();
inline void QueuePush(DT dt);
inline const DT& QueuePop();
inline const DT& QueueTop() const;
inline const DT& QueueBottom() const;
std::size_t inline QueueSize() const;
bool inline QueueEmpty() const;
// Handle pausing and logging
private:
void LogRenderTimeToFile(DT val);
void SetPaused(bool paused);
void PushFront(DT value);
void PopBack();
bool m_paused = false;
int m_on_state_changed_handle;
@ -87,9 +60,7 @@ private: // Functions for managing dt queue
// Queue + Running Total used to calculate average dt
DT m_dt_total = DT::zero();
std::array<DT, MAX_DT_QUEUE_SIZE> m_dt_queue;
std::size_t m_dt_queue_begin = 0;
std::size_t m_dt_queue_end = 0;
std::deque<DT> m_dt_queue;
// Average rate/time throughout the window
DT m_dt_avg = DT::zero(); // Uses Moving Average