Perfs monitor update
This commit is contained in:
parent
d152296d43
commit
1946f16385
@ -14,9 +14,10 @@ DebugUI::DebugUI() {
|
||||
gDbgText.setFillColor(sf::Color::White);
|
||||
}
|
||||
|
||||
void DebugUI::UpdateDebugData(const double cpu_usage, const double loop_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage) {
|
||||
void DebugUI::UpdateDebugData(const double cpu_usage, const double cpu_time, const double cycle_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage) {
|
||||
gDbgStats.cpu_usage = cpu_usage;
|
||||
gDbgStats.loop_time = loop_time;
|
||||
gDbgStats.cpu_time = cpu_time;
|
||||
gDbgStats.cycle_time = cycle_time;
|
||||
gDbgStats.fps = fps;
|
||||
gDbgStats.ram_virt_usage = ram_virt_usage;
|
||||
gDbgStats.ram_phys_usage = ram_phys_usage;
|
||||
@ -26,7 +27,7 @@ void DebugUI::DrawDebugData(std::shared_ptr<sf::RenderWindow> context) {
|
||||
std::ostringstream outStrStream;
|
||||
outStrStream << std::fixed;
|
||||
|
||||
outStrStream << std::setprecision(0) << "CPU: " << gDbgStats.cpu_usage << "% (cycle time: " << std::setprecision(3) << gDbgStats.loop_time << "ms)" << std::endl;
|
||||
outStrStream << std::setprecision(0) << "CPU: " << gDbgStats.cpu_usage << "% (cycle: " << std::setprecision(3) << gDbgStats.cpu_time << "/" << gDbgStats.cycle_time << "ms)" << std::endl;
|
||||
outStrStream << std::setprecision(1) << "RAM: " << gDbgStats.ram_virt_usage << "MB(V) / " << gDbgStats.ram_phys_usage << "MB(P)" << std::endl;
|
||||
outStrStream << std::setprecision(0) << "FPS: " << gDbgStats.fps;
|
||||
|
||||
|
@ -10,7 +10,8 @@
|
||||
|
||||
struct sDbgStats {
|
||||
double cpu_usage;
|
||||
double loop_time;
|
||||
double cpu_time;
|
||||
double cycle_time;
|
||||
int fps;
|
||||
std::size_t ram_virt_usage;
|
||||
std::size_t ram_phys_usage;
|
||||
@ -21,7 +22,7 @@ public:
|
||||
DebugUI();
|
||||
~DebugUI() {}
|
||||
|
||||
void UpdateDebugData(const double cpu_usage, const double loop_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage);
|
||||
void UpdateDebugData(const double cpu_usage, const double cpu_time, const double cycle_time, const int fps, const std::size_t ram_virt_usage, const std::size_t ram_phys_usage);
|
||||
void DrawDebugData(std::shared_ptr<sf::RenderWindow> context);
|
||||
|
||||
private:
|
||||
|
@ -75,7 +75,7 @@ WorldUI::WorldUI() : UI() {
|
||||
sViewSettings.antialiasingLevel = 8;
|
||||
sViewSettings.sRgbCapable = true;
|
||||
|
||||
if (!mUIRender.create(1280, 560, sViewSettings)) // Only the upper of the screen is renderer as the UI hide whats left.
|
||||
if (!mUIRender.create(1280, 324, sViewSettings)) // Only the upper of the screen is renderer as the UI hide whats left.
|
||||
throw std::runtime_error("Texture renderer creation failure");
|
||||
|
||||
mUIRender.setSmooth(true);
|
||||
|
21
Game.cpp
21
Game.cpp
@ -1,6 +1,7 @@
|
||||
#include "Game.hpp"
|
||||
#include "icon.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <numeric>
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
@ -54,16 +55,18 @@ void Game::InitWindows() {
|
||||
GAME_STATUS Game::Tick(SysTimer& time) {
|
||||
static std::vector<double> msTicksMonitoring;
|
||||
static double mPrevdelta = 0;
|
||||
static double mLastCycleSleepDelta = 0;
|
||||
static unsigned int mFrameCnt = 0;
|
||||
double mDelta = time.GetDeltaTimeUs();
|
||||
|
||||
// Debug performance computations
|
||||
if (mDbgUI != nullptr && mPerfsTimer != nullptr) {
|
||||
msTicksMonitoring.push_back((mDelta - mPrevdelta) / (1000000.f / TARGET_FPS));
|
||||
msTicksMonitoring.push_back(((1000000.f / TARGET_FPS) - mLastCycleSleepDelta) * TARGET_FPS / 1000000.f);
|
||||
if (mPerfsTimer->GetDeltaTime() >= 1000) { // Every 1s
|
||||
double cpuUsage = 100 * std::accumulate(msTicksMonitoring.begin(), msTicksMonitoring.end(), (double)(0)) / msTicksMonitoring.size();
|
||||
// This average CPU/cycle_time method can monitor when CPU is in overload state (>0%) or in underload one (<0%)
|
||||
double cpuUsage = 200 * std::accumulate(msTicksMonitoring.begin(), msTicksMonitoring.end(), (double)(0)) / msTicksMonitoring.size() - 100;
|
||||
|
||||
mDbgUI->UpdateDebugData(cpuUsage, ((mDelta - mPrevdelta) / 1000), mFrameCnt, (PerfsGetVirtMem() / 1000), (PerfsGetPhysMem() / 1000));
|
||||
mDbgUI->UpdateDebugData(cpuUsage, (((1000000.f / TARGET_FPS) - mLastCycleSleepDelta) / 1000), ((-mPrevdelta + time.GetDeltaTimeUs()) / 1000), mFrameCnt, (PerfsGetVirtMem() / 1000), (PerfsGetPhysMem() / 1000));
|
||||
|
||||
mFrameCnt = 0;
|
||||
msTicksMonitoring.clear();
|
||||
@ -88,10 +91,16 @@ GAME_STATUS Game::Tick(SysTimer& time) {
|
||||
Render();
|
||||
mFrameCnt++;
|
||||
time.Reset();
|
||||
mPrevdelta = -mDelta;
|
||||
} else {
|
||||
mPrevdelta = mDelta;
|
||||
mDelta = -mDelta;
|
||||
}
|
||||
mPrevdelta = mDelta;
|
||||
|
||||
// Sleep for remaining time to avoid useless CPU usage
|
||||
mLastCycleSleepDelta = (1000000.f / TARGET_FPS) - (-mPrevdelta + time.GetDeltaTimeUs());
|
||||
if (mLastCycleSleepDelta > 0)
|
||||
sf::sleep(sf::microseconds(mLastCycleSleepDelta));
|
||||
else
|
||||
mLastCycleSleepDelta = 0;
|
||||
|
||||
// Return the current process stat to the head process (TODO: convert to thread)
|
||||
if (mMainWindow->isOpen())
|
||||
|
Loading…
x
Reference in New Issue
Block a user