35 lines
2.1 KiB
C++
35 lines
2.1 KiB
C++
#pragma once
|
|
#include "../src/gui/debug_metrics.h"
|
|
|
|
inline void test_debug_metrics() {
|
|
using namespace debug_metrics;
|
|
frame_history history;
|
|
assert(history.summarize().mean==0);
|
|
history.push(0);history.push(-1);history.push(std::numeric_limits<float>::infinity());
|
|
assert(history.count==0);
|
|
for(int i=0;i<239;++i)history.push(10);
|
|
history.push(100);
|
|
auto stats=history.summarize();
|
|
assert(stats.min==10 && stats.max==100 && stats.p95==10);
|
|
assert(std::fabs(stats.mean-10.375f)<.001f);
|
|
assert(std::fabs(stats.low-25.f)<.001f); // slowest 3 of 240 frames
|
|
history.push(20);assert(history.count==240 && history.next==1);
|
|
|
|
for(ImVec2 screen: {ImVec2{1920,1080},ImVec2{1280,720},ImVec2{800,600},ImVec2{320,240}})
|
|
for(int grid: {4,10,24,64})for(size_t count:{size_t(1),size_t(90),size_t(140)}) {
|
|
const auto box=arrange(screen,count,grid);
|
|
assert(box.columns*box.rows>=int(count));
|
|
assert(box.pos.x>=0 && box.pos.y>=0 && box.pos.x+box.size.x<=screen.x && box.pos.y+box.size.y<=screen.y);
|
|
assert(std::fabs(std::remainder(box.pos.x,float(grid)))<.01f && std::fabs(std::remainder(box.pos.y,float(grid)))<.01f);
|
|
assert(box.header+box.rows*box.row_height+box.padding<=box.size.y+.01f);
|
|
}
|
|
// Reading diagnostics must not activate native hooks or a media worker.
|
|
const auto particles=performance::particles.load();const auto weather=world_weather::enabled.load();auto* media_before=media::instance;
|
|
dashboard metrics;metrics.sample(nullptr);
|
|
assert(!metrics.rows.empty() && particles==performance::particles && weather==world_weather::enabled && media_before==media::instance);
|
|
assert(std::any_of(metrics.rows.begin(),metrics.rows.end(),[](const row& r){return r.label=="profile";}));
|
|
metrics.rows.push_back({"sample sentinel","",false});metrics.sample(nullptr);
|
|
assert(metrics.rows.back().label=="sample sentinel"); // expensive sampling is capped at 2 Hz
|
|
std::cout<<"PASS: Debug metrics frame statistics, responsive grid layout, bounded sampling and passive readers\n";
|
|
}
|