Skip to content

Commit

Permalink
Add frame-time recording on application exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
ASxa86 committed Jun 5, 2024
1 parent 1b70105 commit 2008fa2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/core/Kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include <aspire/core/PimplImpl.h>
#include <chrono>
#include <iostream>
#include <mutex>
#include <numeric>

using aspire::core::Kernel;
using aspire::core::Service;
Expand Down Expand Up @@ -46,8 +48,12 @@ auto Kernel::run() -> int
this->pimpl->running = true;
this->pimpl->start = std::chrono::steady_clock::now();

std::vector<std::chrono::steady_clock::duration> frames;

while(this->pimpl->running)
{
const auto frameStart = std::chrono::steady_clock::now();

this->pimpl->elapsed += std::chrono::steady_clock::now() - this->pimpl->start;

{
Expand All @@ -63,8 +69,19 @@ auto Kernel::run() -> int
{
service->frame();
}

frames.emplace_back(std::chrono::steady_clock::now() - frameStart);
}

std::cout << "Frames: " << frames.size() << "\n";

const auto sum = std::accumulate(std::begin(frames), std::end(frames), std::chrono::steady_clock::duration::zero());
const auto avg = std::chrono::duration_cast<std::chrono::duration<double>>(sum).count() / static_cast<double>(frames.size());
const auto fps = 1.0 / avg;

std::cout << "Interval: " << avg << " s\n";
std::cout << "FPS: " << fps << " Hz\n";

return EXIT_SUCCESS;
}

Expand Down

0 comments on commit 2008fa2

Please sign in to comment.