Skip to main content

FpsMetrics.ixx File

Module defining the FpsMetrics class for frame rate analysis and monitoring. More...

Included Headers

#include <deque> #include <numeric> #include <cstddef> #include <helios.engine.tooling.FrameStats>

Namespaces Index

namespacehelios
namespaceengine
namespacetooling

Classes Index

classFpsMetrics

Aggregates and analyzes frame timing data over a rolling window. More...

Description

Module defining the FpsMetrics class for frame rate analysis and monitoring.

File Listing

The file content with the documentation metadata removed is:

1
5module;
6
7#include <deque>
8#include <numeric>
9#include <cstddef>
10
11export module helios.engine.tooling.FpsMetrics;
12
13import helios.engine.tooling.FrameStats;
14
15export namespace helios::engine::tooling {
16
41 class FpsMetrics {
42
53 std::deque<helios::engine::tooling::FrameStats> history_;
54
66 size_t historySize_ = 60;
67
76 float avgFps_ = 0.0f;
77
86 float avgFrameTime_ = 0.0f;
87
96 float lastWorkTime_ = 0.0f;
97
106 float lastWaitTime_ = 0.0f;
107
115 unsigned long long frameCount_ = 0;
116
124 bool needsUpdate_ = true;
125
139 void update() noexcept {
140 if (!needsUpdate_ || history_.empty()) {
141 return;
142 }
143
144 const auto& stats = history_.back();
145
146 lastWorkTime_ = stats.workTime * 1000.0f;
147 lastWaitTime_ = stats.waitTime * 1000.0f;
148
149 float sumMs = 0.0f;
150 for (const auto& s : history_) {
151 sumMs += s.totalFrameTime * 1000.0f;
152 }
153
154 avgFrameTime_ = sumMs / static_cast<float>(history_.size());
155 avgFps_ = (avgFrameTime_ > 0.0001f) ? (1000.0f / avgFrameTime_) : 0.0f;
156
157 needsUpdate_ = false;
158 }
159
160 public:
161
183 needsUpdate_ = true;
184
185 history_.push_back(stats);
186 if (history_.size() > historySize_) {
187 history_.pop_front();
188 }
189
190 frameCount_++;
191 }
192
204 void setHistorySize(size_t size) {
205 historySize_ = size;
206 while (history_.size() > historySize_) {
207 history_.pop_front();
208 }
209 needsUpdate_ = true;
210 }
211
218 return historySize_;
219 }
220
230 update();
231 return avgFps_;
232 }
233
242 update();
243 return avgFrameTime_;
244 }
245
254 update();
255 return lastWorkTime_;
256 }
257
266 update();
267 return lastWaitTime_;
268 }
269
275 [[nodiscard]] unsigned long long getFrameCount() const noexcept {
276 return frameCount_;
277 }
278
288 update();
289 return avgFrameTime_ * 0.001f;
290 }
291
301 update();
302 return lastWorkTime_ * 0.001f;
303 }
304
314 update();
315 return lastWaitTime_ * 0.001f;
316 }
317
327 [[nodiscard]] const std::deque<helios::engine::tooling::FrameStats>& getHistory() const noexcept {
328 return history_;
329 }
330
338 void reset() {
339 history_.clear();
340 avgFps_ = 0.0f;
341 avgFrameTime_ = 0.0f;
342 lastWorkTime_ = 0.0f;
343 lastWaitTime_ = 0.0f;
344 frameCount_ = 0;
345 needsUpdate_ = false;
346 }
347 };
348}

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.