70 lines
1.7 KiB
C++
70 lines
1.7 KiB
C++
|
#include "src/PerfCounter.h"
|
||
|
#include <imgui.h>
|
||
|
#include <iostream>
|
||
|
|
||
|
EngineStatistics ES;
|
||
|
|
||
|
uint64_t EngineInstrumentation::GetPrecisionTime() {
|
||
|
using namespace std::chrono; // REMINDER: This is kinda ugly but safes line width
|
||
|
return duration_cast<milliseconds>(high_resolution_clock::now().time_since_epoch()).count();
|
||
|
}
|
||
|
|
||
|
void EngineInstrumentation::PerfomanceSamplerInit() {
|
||
|
ES.frames = 0;
|
||
|
//EngineInstrumentation::lastSampleTime = GetPrecisionTime();
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
void EngineInstrumentation::Update() {
|
||
|
/*
|
||
|
uint64_t MilliSecondsPast = GetPrecisionTime() - EngineInstrumentation::lastSampleTime;
|
||
|
|
||
|
if (MilliSecondsPast >= 1000) {
|
||
|
|
||
|
ES.frameTime = (float)1000 / ES.frames;
|
||
|
ES.FPS = ES.frames;
|
||
|
ES.frames = 0;
|
||
|
//EngineInstrumentation::lastSampleTime = GetPrecisionTime();
|
||
|
}
|
||
|
*/
|
||
|
|
||
|
}
|
||
|
|
||
|
void EngineInstrumentation::ShowStats() {
|
||
|
ImGui::Begin("Statistics", false, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize);
|
||
|
|
||
|
ImGui::Text("FPS: %i", ES.FPS);
|
||
|
ImGui::Text("Frame Time: %f", ES.frameTime);
|
||
|
ImGui::Text("Verts: %i", ES.verts);
|
||
|
ImGui::Text("Draw Calls: %i", ES.DC);
|
||
|
|
||
|
ImGui::End();
|
||
|
}
|
||
|
|
||
|
|
||
|
PerfSampler::PerfSampler(const std::string& name )
|
||
|
: name(name)
|
||
|
{
|
||
|
using namespace std::chrono;
|
||
|
startTime = high_resolution_clock::now();
|
||
|
|
||
|
}
|
||
|
|
||
|
PerfSampler::~PerfSampler()
|
||
|
{
|
||
|
Stop();
|
||
|
}
|
||
|
|
||
|
void PerfSampler::Stop()
|
||
|
{
|
||
|
using namespace std::chrono;
|
||
|
auto end = high_resolution_clock::now();
|
||
|
auto durationInuSeconds =
|
||
|
duration_cast<nanoseconds>(end.time_since_epoch()).count() -
|
||
|
duration_cast<nanoseconds>(startTime.time_since_epoch()).count();
|
||
|
|
||
|
auto ms = durationInuSeconds * 0.001f;
|
||
|
|
||
|
std::cout << "[" << name << "]" << "Took: " << durationInuSeconds << " us (" << ms << " ms)" << std::endl;
|
||
|
}
|