Add MAX profiler option

This commit is contained in:
Lars 2023-04-09 07:44:43 -10:00 committed by rubenwardy
parent 9d1ae80e89
commit 3d232e2345
2 changed files with 30 additions and 2 deletions

@ -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<std::string, int>::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);

@ -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