#include "collision.h"
#include "environment.h"
#include "settings.h"
+#include "profiler.h"
core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
void ItemSAO::step(float dtime, bool send_recommended)
{
+ ScopeProfiler sp2(g_profiler, "ItemSAO::step avg", SPT_AVG);
+
assert(m_env);
const float interval = 0.2;
void RatSAO::step(float dtime, bool send_recommended)
{
+ ScopeProfiler sp2(g_profiler, "RatSAO::step avg", SPT_AVG);
+
assert(m_env);
if(m_is_active == false)
void Oerkki1SAO::step(float dtime, bool send_recommended)
{
+ ScopeProfiler sp2(g_profiler, "Oerkki1SAO::step avg", SPT_AVG);
+
assert(m_env);
if(m_is_active == false)
void FireflySAO::step(float dtime, bool send_recommended)
{
+ ScopeProfiler sp2(g_profiler, "FireflySAO::step avg", SPT_AVG);
+
assert(m_env);
if(m_is_active == false)
void MobV2SAO::step(float dtime, bool send_recommended)
{
+ ScopeProfiler sp2(g_profiler, "MobV2SAO::step avg", SPT_AVG);
+
assert(m_env);
Map *map = &m_env->getMap();
Handle players
*/
{
- ScopeProfiler sp(g_profiler, "SEnv: handle players avg", SPT_LOWPASS);
+ ScopeProfiler sp(g_profiler, "SEnv: handle players avg", SPT_AVG);
for(core::list<Player*>::Iterator i = m_players.begin();
i != m_players.end(); i++)
{
*/
if(m_active_blocks_management_interval.step(dtime, 2.0))
{
- ScopeProfiler sp(g_profiler, "SEnv: manage act. block list avg", SPT_LOWPASS);
+ ScopeProfiler sp(g_profiler, "SEnv: manage act. block list avg /2s", SPT_AVG);
/*
Get player block positions
*/
*/
if(m_active_blocks_nodemetadata_interval.step(dtime, 1.0))
{
- ScopeProfiler sp(g_profiler, "SEnv: mess in act. blocks avg", SPT_LOWPASS);
+ ScopeProfiler sp(g_profiler, "SEnv: mess in act. blocks avg /1s", SPT_AVG);
float dtime = 1.0;
if(m_active_blocks_test_interval.step(dtime, 10.0))
{
- ScopeProfiler sp(g_profiler, "SEnv: modify in blocks avg", SPT_LOWPASS);
+ ScopeProfiler sp(g_profiler, "SEnv: modify in blocks avg /10s", SPT_AVG);
//float dtime = 10.0;
for(core::map<v3s16, bool>::Iterator
Step active objects
*/
{
- ScopeProfiler sp(g_profiler, "SEnv: step act. objs avg", SPT_LOWPASS);
+ ScopeProfiler sp(g_profiler, "SEnv: step act. objs avg", SPT_AVG);
//TimeTaker timer("Step active objects");
+
+ g_profiler->avg("SEnv: num of objects", m_active_objects.size());
// This helps the objects to send data at the same time
bool send_recommended = false;
*/
if(m_object_management_interval.step(dtime, 0.5))
{
- ScopeProfiler sp(g_profiler, "SEnv: remove removed objs avg", SPT_LOWPASS);
+ ScopeProfiler sp(g_profiler, "SEnv: remove removed objs avg /.5s", SPT_AVG);
/*
Remove objects that satisfy (m_removed && m_known_by_count==0)
*/
object_hit_delay_timer -= dtime;
- g_profiler->add("Elapsed time", dtime * 1000);
+ g_profiler->add("Elapsed time", dtime);
/*
Log frametime for visualization
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);
}
}
{
i.getNode()->setValue(0);
}
+ m_avgcounts.clear();
}
void print(std::ostream &o)
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();
else
o<<" ";
}
- o<<i.getNode()->getValue();
+ o<<(i.getNode()->getValue() / avgcount);
o<<std::endl;
}
}
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
{
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;
}
}
JMutexAutoLock lock(m_env_mutex);
// Step environment
ScopeProfiler sp(g_profiler, "SEnv step");
- ScopeProfiler sp2(g_profiler, "SEnv step avg", SPT_LOWPASS);
+ ScopeProfiler sp2(g_profiler, "SEnv step avg", SPT_AVG);
m_env.step(dtime);
}