From 2419d0029ac36952aaa74b685d529a3592adb6aa Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 16 Oct 2011 22:39:35 +0300 Subject: Some more profiler stuff to get the hang on what really uses CPU --- src/profiler.h | 61 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'src/profiler.h') diff --git a/src/profiler.h b/src/profiler.h index 8eaf18df5..129118ef6 100644 --- a/src/profiler.h +++ b/src/profiler.h @@ -41,28 +41,48 @@ public: void add(const std::string &name, float value) { JMutexAutoLock lock(m_mutex); - core::map::Node *n = m_data.find(name); - if(n == NULL) { - m_data[name] = value; + /* No average shall have been used; mark add used as -2 */ + core::map::Node *n = m_avgcounts.find(name); + if(n == NULL) + m_avgcounts[name] = -2; + else{ + if(n->getValue() == -1) + n->setValue(-2); + assert(n->getValue() == -2); + } } - else { - n->setValue(n->getValue() + value); + core::map::Node *n = m_data.find(name); + if(n == NULL) + m_data[name] = value; + else + n->setValue(n->getValue() + value); } } - void lowpass(const std::string &name, float value, float factor) + void avg(const std::string &name, float value) { JMutexAutoLock lock(m_mutex); - core::map::Node *n = m_data.find(name); - if(n == NULL) { - m_data[name] = value; + core::map::Node *n = m_avgcounts.find(name); + if(n == NULL) + m_avgcounts[name] = 1; + else{ + /* No add shall have been used */ + assert(n->getValue() != -2); + if(n->getValue() <= 0) + n->setValue(1); + else + n->setValue(n->getValue() + 1); + } } - else { - n->setValue(n->getValue() * (1.0 - 1.0/factor) + value / factor); + core::map::Node *n = m_data.find(name); + if(n == NULL) + m_data[name] = value; + else + n->setValue(n->getValue() + value); } } @@ -75,6 +95,7 @@ public: { i.getNode()->setValue(0); } + m_avgcounts.clear(); } void print(std::ostream &o) @@ -85,6 +106,12 @@ public: i.atEnd() == false; i++) { std::string name = i.getNode()->getKey(); + int avgcount = 1; + core::map::Node *n = m_avgcounts.find(name); + if(n){ + if(n->getValue() >= 1) + avgcount = n->getValue(); + } o<<" "<getValue(); + o<<(i.getNode()->getValue() / avgcount); o< m_data; + core::map m_avgcounts; }; enum ScopeProfilerType{ SPT_ADD, - SPT_LOWPASS + SPT_AVG }; class ScopeProfiler @@ -138,14 +166,15 @@ public: { if(m_timer) { - u32 duration = m_timer->stop(true); + float duration_ms = m_timer->stop(true); + float duration = duration_ms / 1000.0; if(m_profiler){ switch(m_type){ case SPT_ADD: m_profiler->add(m_name, duration); break; - case SPT_LOWPASS: - m_profiler->lowpass(m_name, duration, 20.0); + case SPT_AVG: + m_profiler->avg(m_name, duration); break; } } -- cgit v1.2.3