This commit is contained in:
Jorijn van der Graaf 2025-11-25 23:36:43 +01:00
commit b41ec7960c
3 changed files with 32 additions and 1 deletions

View file

@ -71,7 +71,30 @@ void Window::LogTiming() {
for (const std::tuple<const RenderingElement*, std::uint_fast32_t, std::uint_fast32_t, std::chrono::nanoseconds>& entry : renderTimings) {
std::cout << std::format("\t{} {}x{} {}", reinterpret_cast<const void*>(std::get<0>(entry)), std::get<1>(entry), std::get<2>(entry), duration_cast<std::chrono::microseconds>(std::get<3>(entry))) << std::endl;
}
std::cout << std::format("Total: {}", duration_cast<std::chrono::milliseconds>(totalUpdate+totalRender)) << std::endl;
std::cout << std::format("Vblank: {}", duration_cast<std::chrono::milliseconds>(vblank)) << std::endl;
std::cout << std::format("Total: {}", duration_cast<std::chrono::milliseconds>(totalUpdate+totalRender+vblank)) << std::endl;
// Add 100-frame average and min-max timing info
if (!frameTimes.empty()) {
// Calculate average
std::chrono::nanoseconds sum(0);
for (const auto& frameTime : frameTimes) {
sum += frameTime;
}
auto average = sum / frameTimes.size();
// Find min and max
auto min = frameTimes.front();
auto max = frameTimes.front();
for (const auto& frameTime : frameTimes) {
if (frameTime < min) min = frameTime;
if (frameTime > max) max = frameTime;
}
std::cout << std::format("Last 100 Frame Times - Avg: {}, Min: {}, Max: {}",
duration_cast<std::chrono::milliseconds>(average),
duration_cast<std::chrono::milliseconds>(min),
duration_cast<std::chrono::milliseconds>(max)) << std::endl;
}
}
#endif

View file

@ -278,6 +278,13 @@ void WindowWayland::wl_surface_frame_done(void* data, struct wl_callback *cb, ui
#ifdef CRAFTER_TIMING
window->frameEnd = std::chrono::high_resolution_clock::now();
window->frameTimes.push_back(window->totalUpdate+window->totalRender);
// Keep only the last 100 frame times
if (window->frameTimes.size() > 100) {
window->frameTimes.erase(window->frameTimes.begin());
}
#endif
window->lastFrameBegin = start;
}