From 3d232e2345d6cf1c17e7db90e3f930c3eb500991 Mon Sep 17 00:00:00 2001 From: Lars Date: Sun, 9 Apr 2023 07:44:43 -1000 Subject: [PATCH] Add MAX profiler option --- src/profiler.cpp | 28 +++++++++++++++++++++++++++- src/profiler.h | 4 +++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/profiler.cpp b/src/profiler.cpp index ab05f7382..56bdc448a 100644 --- a/src/profiler.cpp +++ b/src/profiler.cpp @@ -50,6 +50,9 @@ ScopeProfiler::~ScopeProfiler() case SPT_GRAPH_ADD: m_profiler->graphAdd(m_name, duration); break; + case SPT_MAX: + m_profiler->max(m_name, duration); + break; } } delete m_timer; @@ -64,7 +67,7 @@ void Profiler::add(const std::string &name, float value) { MutexAutoLock lock(m_mutex); { - /* No average shall have been used; mark add used as -2 */ + /* No average shall have been used; mark add/max used as -2 */ std::map::iterator n = m_avgcounts.find(name); if (n == m_avgcounts.end()) { m_avgcounts[name] = -2; @@ -83,6 +86,29 @@ void Profiler::add(const std::string &name, float value) } } +void Profiler::max(const std::string &name, float value) +{ + MutexAutoLock lock(m_mutex); + { + /* No average shall have been used; mark add/max used as -2 */ + auto n = m_avgcounts.find(name); + if (n == m_avgcounts.end()) { + m_avgcounts[name] = -2; + } else { + if (n->second == -1) + n->second = -2; + assert(n->second == -2); + } + } + { + auto n = m_data.find(name); + if (n == m_data.end()) + m_data[name] = value; + else if (value > n->second) + n->second = value; + } +} + void Profiler::avg(const std::string &name, float value) { MutexAutoLock lock(m_mutex); diff --git a/src/profiler.h b/src/profiler.h index b4a0657f9..ea45c8d5c 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -44,6 +44,7 @@ public: void add(const std::string &name, float value); void avg(const std::string &name, float value); + void max(const std::string &name, float value); void clear(); float getValue(const std::string &name) const; @@ -92,7 +93,8 @@ private: enum ScopeProfilerType{ SPT_ADD, SPT_AVG, - SPT_GRAPH_ADD + SPT_GRAPH_ADD, + SPT_MAX }; class ScopeProfiler