diff --git a/src/profiler.cpp b/src/profiler.cpp index 8ad80311c..ab8fbe496 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -96,7 +96,7 @@ void Profiler::avg(const std::string &name, float value) if (it == m_data.end()) { m_data.emplace(name, DataPair{value, 1}); } else { - assert(it->second.avgcount >= 1); + assert(it->second.avgcount >= 0); it->second.value += value; it->second.avgcount++; } @@ -106,7 +106,7 @@ void Profiler::clear() { MutexAutoLock lock(m_mutex); for (auto &it : m_data) - it.second = DataPair(); + it.second.reset(); m_start_time = porting::getTimeMs(); } diff --git a/src/profiler.h b/src/profiler.h index f2aa7c6d5..e7135d9c2 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -90,6 +90,12 @@ private: float value = 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 { return avgcount >= 1 ? (value / avgcount) : value; }