Client: Add sum and average to packetcounter
authorsfan5 <sfan5@live.de>
Fri, 15 May 2020 13:12:37 +0000 (15:12 +0200)
committersfan5 <sfan5@live.de>
Sun, 17 May 2020 19:37:01 +0000 (21:37 +0200)
src/client/client.cpp
src/client/client.h

index 941fc203dea603fefab8a62e701df4aa1d8cdb17..c03c062c6635a95803c721c48a4cd214c8b2c06e 100644 (file)
@@ -64,6 +64,14 @@ extern gui::IGUIEnvironment* guienv;
        Utility classes
 */
 
+u32 PacketCounter::sum() const
+{
+       u32 n = 0;
+       for (const auto &it : m_packets)
+               n += it.second;
+       return n;
+}
+
 void PacketCounter::print(std::ostream &o) const
 {
        for (const auto &it : m_packets) {
@@ -357,9 +365,11 @@ void Client::step(float dtime)
                if(counter <= 0.0f)
                {
                        counter = 30.0f;
+                       u32 sum = m_packetcounter.sum();
+                       float avg = sum / counter;
 
-                       infostream << "Client packetcounter (" << m_packetcounter_timer
-                                       << "s):"<<std::endl;
+                       infostream << "Client packetcounter (" << counter << "s): "
+                                       << "sum=" << sum << " avg=" << avg << "/s" << std::endl;
                        m_packetcounter.print(infostream);
                        m_packetcounter.clear();
                }
index eea78d45643f388a3e462a6cba81aaba7db71f09..3b1095ac29af48709c4a5414ae8c1aaa63630e17 100644 (file)
@@ -94,11 +94,12 @@ public:
                m_packets.clear();
        }
 
+       u32 sum() const;
        void print(std::ostream &o) const;
 
 private:
        // command, count
-       std::map<u16, u16> m_packets;
+       std::map<u16, u32> m_packets;
 };
 
 class ClientScripting;