Skip to content

Commit

Permalink
Remembering order of inclusion for measurements. This makes it easier…
Browse files Browse the repository at this point in the history
… to find stuff.
  • Loading branch information
Brotcrunsher committed Jan 4, 2025
1 parent 6276527 commit fb465df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 26 deletions.
5 changes: 3 additions & 2 deletions BrotBoxEngine/BBE/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace bbe
bbe::StopWatch m_performanceMeasurement;
struct PerformanceMeasurement
{
bbe::String name;
bbe::List<double> perFrame;
double max = 0.0;
double avg = 0.0;
Expand All @@ -60,7 +61,7 @@ namespace bbe
double minuteMax2 = 0.0;
};
bbe::TimePoint nextMinuteMaxMove;
std::map<const char*, PerformanceMeasurement> m_performanceMeasurements;
bbe::List<PerformanceMeasurement> m_performanceMeasurements;
bool m_performanceMeasurementsRequired = false;
bool m_performanceMeasurementsForced = false;

Expand Down Expand Up @@ -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();

Expand Down
52 changes: 28 additions & 24 deletions BrotBoxEngine/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);

Expand Down

0 comments on commit fb465df

Please sign in to comment.