From fb465dfe42b94c4c9607041b1bc1d456e13d8d6e Mon Sep 17 00:00:00 2001 From: Brotcrunsher Date: Sat, 4 Jan 2025 14:29:35 +0100 Subject: [PATCH] Remembering order of inclusion for measurements. This makes it easier to find stuff. --- BrotBoxEngine/BBE/Game.h | 5 ++-- BrotBoxEngine/Game.cpp | 52 +++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 26 deletions(-) diff --git a/BrotBoxEngine/BBE/Game.h b/BrotBoxEngine/BBE/Game.h index 517cf5f2..37241b34 100644 --- a/BrotBoxEngine/BBE/Game.h +++ b/BrotBoxEngine/BBE/Game.h @@ -51,6 +51,7 @@ namespace bbe bbe::StopWatch m_performanceMeasurement; struct PerformanceMeasurement { + bbe::String name; bbe::List perFrame; double max = 0.0; double avg = 0.0; @@ -60,7 +61,7 @@ namespace bbe double minuteMax2 = 0.0; }; bbe::TimePoint nextMinuteMaxMove; - std::map m_performanceMeasurements; + bbe::List m_performanceMeasurements; bool m_performanceMeasurementsRequired = false; bool m_performanceMeasurementsForced = false; @@ -162,7 +163,7 @@ namespace bbe bool isWindowShow() const; void endMeasure(); - void beginMeasure(const char* tag, bool force = false); // CAREFUL: Static string assumed! + void beginMeasure(const char* tag, bool force = false); bbe::String getMeasuresString(); void drawMeasurement(); diff --git a/BrotBoxEngine/Game.cpp b/BrotBoxEngine/Game.cpp index ea975cfd..0dc1f6bb 100644 --- a/BrotBoxEngine/Game.cpp +++ b/BrotBoxEngine/Game.cpp @@ -347,7 +347,7 @@ void bbe::Game::frameUpdate() nextMinuteMaxMove = bbe::TimePoint().plusMinutes(1); for (auto it = m_performanceMeasurements.begin(); it != m_performanceMeasurements.end(); it++) { - PerformanceMeasurement& pm = it->second; + PerformanceMeasurement& pm = *it; pm.minuteMax2 = pm.minuteMax1; pm.minuteMax1 = 0.0; } @@ -714,23 +714,27 @@ void bbe::Game::endMeasure() if (m_pcurrentPerformanceMeasurementTag) { auto passedTimeSeconds = m_performanceMeasurement.getTimeExpiredNanoseconds() / 1000.0 / 1000.0 / 1000.0; - const bool firstMeasurement = !m_performanceMeasurements.count(m_pcurrentPerformanceMeasurementTag); - PerformanceMeasurement& pm = m_performanceMeasurements[m_pcurrentPerformanceMeasurementTag]; - pm.now = passedTimeSeconds; - pm.max = bbe::Math::max(pm.max, passedTimeSeconds); - pm.minuteMax1 = bbe::Math::max(pm.minuteMax1, passedTimeSeconds); - if (firstMeasurement) + PerformanceMeasurement* pm = m_performanceMeasurements.find([&](const PerformanceMeasurement& pm) { + return pm.name == m_pcurrentPerformanceMeasurementTag; + }); + if (!pm) { - pm.avg = passedTimeSeconds; + PerformanceMeasurement newPm; + newPm.name = m_pcurrentPerformanceMeasurementTag; + newPm.avg = passedTimeSeconds; + m_performanceMeasurements.add(newPm); + pm = &m_performanceMeasurements.last(); } else { - - pm.avg = 0.999 * pm.avg + 0.001 * passedTimeSeconds; + pm->avg = 0.999 * pm->avg + 0.001 * passedTimeSeconds; } + pm->now = passedTimeSeconds; + pm->max = bbe::Math::max(pm->max, passedTimeSeconds); + pm->minuteMax1 = bbe::Math::max(pm->minuteMax1, passedTimeSeconds); if (m_performanceMeasurementsRequired || m_performanceMeasurementsForced) { - pm.perFrame.add(passedTimeSeconds); + pm->perFrame.add(passedTimeSeconds); } } m_pcurrentPerformanceMeasurementTag = nullptr; @@ -749,7 +753,7 @@ bbe::String bbe::Game::getMeasuresString() int32_t maxLen = 0; for (auto it = m_performanceMeasurements.begin(); it != m_performanceMeasurements.end(); it++) { - maxLen = bbe::Math::max(maxLen, (int32_t)strlen(it->first)); + maxLen = bbe::Math::max(maxLen, (int32_t)it->name.getLength()); } bbe::String retVal = bbe::String(" ") * maxLen; @@ -759,9 +763,9 @@ bbe::String bbe::Game::getMeasuresString() { if (it != m_performanceMeasurements.begin()) retVal += "\n"; - const PerformanceMeasurement& pm = it->second; - int32_t padding = maxLen - (int32_t)strlen(it->first); - retVal += it->first; + const PerformanceMeasurement& pm = *it; + int32_t padding = maxLen - (int32_t)pm.name.getLength(); + retVal += pm.name; retVal += ": "; retVal += bbe::String(" ") * padding; retVal += pm.max; @@ -786,13 +790,13 @@ void bbe::Game::drawMeasurement() int32_t maxLen = 0; for (auto it = m_performanceMeasurements.begin(); it != m_performanceMeasurements.end(); it++) { - maxLen = bbe::Math::max(maxLen, (int32_t)strlen(it->first)); + maxLen = bbe::Math::max(maxLen, (int32_t)it->name.getLength()); - maxMax = bbe::Math::max(maxMax, it->second.max); - maxAvg = bbe::Math::max(maxAvg, it->second.avg); - maxNow = bbe::Math::max(maxNow, it->second.now); - maxMinuteMax = bbe::Math::max(maxMinuteMax, it->second.minuteMax1); - maxMinuteMax = bbe::Math::max(maxMinuteMax, it->second.minuteMax2); + maxMax = bbe::Math::max(maxMax, it->max); + maxAvg = bbe::Math::max(maxAvg, it->avg); + maxNow = bbe::Math::max(maxNow, it->now); + maxMinuteMax = bbe::Math::max(maxMinuteMax, it->minuteMax1); + maxMinuteMax = bbe::Math::max(maxMinuteMax, it->minuteMax2); } bbe::String header = bbe::String(" ") * maxLen; @@ -801,9 +805,9 @@ void bbe::Game::drawMeasurement() for (auto it = m_performanceMeasurements.begin(); it != m_performanceMeasurements.end(); it++) { - const PerformanceMeasurement& pm = it->second; - int32_t padding = maxLen - (int32_t)strlen(it->first); - ImGui::Text(it->first); + const PerformanceMeasurement& pm = *it; + int32_t padding = maxLen - (int32_t)it->name.getLength(); + ImGui::Text(it->name); ImGui::SameLine(0.0f, 0.0f); ImGui::Text(": "); ImGui::SameLine(0.0f, 0.0f); ImGui::Text(bbe::String(" ") * padding);