Some more profiler stuff to get the hang on what really uses CPU
authorPerttu Ahola <celeron55@gmail.com>
Sun, 16 Oct 2011 19:39:35 +0000 (22:39 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 16 Oct 2011 19:39:35 +0000 (22:39 +0300)
src/content_sao.cpp
src/environment.cpp
src/game.cpp
src/profiler.h
src/server.cpp

index 1968b7b6a073ee92886f38b8804ea2f1e1c91d2d..9569b6586cc4c9f8e04732d8fe2c6d01d9f471e9 100644 (file)
@@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "collision.h"
 #include "environment.h"
 #include "settings.h"
+#include "profiler.h"
 
 core::map<u16, ServerActiveObject::Factory> ServerActiveObject::m_types;
 
@@ -137,6 +138,8 @@ ServerActiveObject* ItemSAO::create(ServerEnvironment *env, u16 id, v3f pos,
 
 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;
@@ -291,6 +294,8 @@ ServerActiveObject* RatSAO::create(ServerEnvironment *env, u16 id, v3f pos,
 
 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)
@@ -480,6 +485,8 @@ ServerActiveObject* Oerkki1SAO::create(ServerEnvironment *env, u16 id, v3f pos,
 
 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)
@@ -752,6 +759,8 @@ ServerActiveObject* FireflySAO::create(ServerEnvironment *env, u16 id, v3f pos,
 
 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)
@@ -1065,6 +1074,8 @@ static void explodeSquare(Map *map, v3s16 p0, v3s16 size)
 
 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();
 
index 99dc6d62be495172ff12400e954e2e09f786fcc9..47743bfc796703b624571cca0947ee55963d5641 100644 (file)
@@ -684,7 +684,7 @@ void ServerEnvironment::step(float dtime)
                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++)
                {
@@ -726,7 +726,7 @@ void ServerEnvironment::step(float dtime)
        */
        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
                */
@@ -803,7 +803,7 @@ void ServerEnvironment::step(float dtime)
        */
        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;
 
@@ -842,7 +842,7 @@ void ServerEnvironment::step(float dtime)
        
        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
@@ -1045,8 +1045,10 @@ void ServerEnvironment::step(float dtime)
                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;
@@ -1086,7 +1088,7 @@ void ServerEnvironment::step(float dtime)
        */
        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)
                */
index 276857f80612945bc58198d578531d921c2238ce..e666e084d6d20a8f9b85c696ac71a99a840939be 100644 (file)
@@ -1070,7 +1070,7 @@ void the_game(
 
                object_hit_delay_timer -= dtime;
 
-               g_profiler->add("Elapsed time", dtime * 1000);
+               g_profiler->add("Elapsed time", dtime);
 
                /*
                        Log frametime for visualization
index 8eaf18df5effb290e88ec49d2a37758d94e82121..129118ef6216c567281044f1e8b8741f009f764a 100644 (file)
@@ -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;
                                }
                        }
index ed0c97c29145559390e6c7ea348dafd36fd3e5a1..14c019d52fc8e6e944756e11d672d20e9e4daed9 100644 (file)
@@ -1214,7 +1214,7 @@ void Server::AsyncRunStep()
                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);
        }