Fix profiler assertion failures

oops
This commit is contained in:
sfan5 2024-04-20 14:32:35 +02:00
parent b7887a339d
commit 3bd5169aee
2 changed files with 8 additions and 2 deletions

@ -96,7 +96,7 @@ void Profiler::avg(const std::string &name, float value)
if (it == m_data.end()) { if (it == m_data.end()) {
m_data.emplace(name, DataPair{value, 1}); m_data.emplace(name, DataPair{value, 1});
} else { } else {
assert(it->second.avgcount >= 1); assert(it->second.avgcount >= 0);
it->second.value += value; it->second.value += value;
it->second.avgcount++; it->second.avgcount++;
} }
@ -106,7 +106,7 @@ void Profiler::clear()
{ {
MutexAutoLock lock(m_mutex); MutexAutoLock lock(m_mutex);
for (auto &it : m_data) for (auto &it : m_data)
it.second = DataPair(); it.second.reset();
m_start_time = porting::getTimeMs(); m_start_time = porting::getTimeMs();
} }

@ -90,6 +90,12 @@ private:
float value = 0; float value = 0;
int avgcount = 0; int avgcount = 0;
inline void reset() {
value = 0;
// negative values are used for type checking, so leave them alone
if (avgcount >= 1)
avgcount = 0;
}
inline float getValue() const { inline float getValue() const {
return avgcount >= 1 ? (value / avgcount) : value; return avgcount >= 1 ? (value / avgcount) : value;
} }