summaryrefslogtreecommitdiff
path: root/src/profiler.h
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-10-16 22:39:35 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-10-16 22:39:35 +0300
commit2419d0029ac36952aaa74b685d529a3592adb6aa (patch)
treeeb0c1fa1aa1167611e72d83f69bf16cf466a8466 /src/profiler.h
parentb8f2dcea4de03b21f353240935a3295f237f258f (diff)
downloadminetest-2419d0029ac36952aaa74b685d529a3592adb6aa.tar.gz
minetest-2419d0029ac36952aaa74b685d529a3592adb6aa.tar.bz2
minetest-2419d0029ac36952aaa74b685d529a3592adb6aa.zip
Some more profiler stuff to get the hang on what really uses CPU
Diffstat (limited to 'src/profiler.h')
-rw-r--r--src/profiler.h61
1 files changed, 45 insertions, 16 deletions
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<std::string, float>::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<std::string, int>::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<std::string, float>::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<std::string, float>::Node *n = m_data.find(name);
- if(n == NULL)
{
- m_data[name] = value;
+ core::map<std::string, int>::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<std::string, float>::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<std::string, int>::Node *n = m_avgcounts.find(name);
+ if(n){
+ if(n->getValue() >= 1)
+ avgcount = n->getValue();
+ }
o<<" "<<name<<": ";
s32 clampsize = 40;
s32 space = clampsize - name.size();
@@ -95,7 +122,7 @@ public:
else
o<<" ";
}
- o<<i.getNode()->getValue();
+ o<<(i.getNode()->getValue() / avgcount);
o<<std::endl;
}
}
@@ -103,11 +130,12 @@ public:
private:
JMutex m_mutex;
core::map<std::string, float> m_data;
+ core::map<std::string, int> 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;
}
}