aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2020-05-15 15:12:37 +0200
committersfan5 <sfan5@live.de>2020-05-17 21:37:01 +0200
commitbe38a44ffe2355d909774923a517d8b37f932dfe (patch)
treee10dc65a27aa6dae633f299978bd8f8c9ce60bdd
parenta9c3a423231e26ea3edee51d5f0bf949ca8e529b (diff)
downloadminetest-be38a44ffe2355d909774923a517d8b37f932dfe.tar.gz
minetest-be38a44ffe2355d909774923a517d8b37f932dfe.tar.bz2
minetest-be38a44ffe2355d909774923a517d8b37f932dfe.zip
Client: Add sum and average to packetcounter
-rw-r--r--src/client/client.cpp14
-rw-r--r--src/client/client.h3
2 files changed, 14 insertions, 3 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp
index 941fc203d..c03c062c6 100644
--- a/src/client/client.cpp
+++ b/src/client/client.cpp
@@ -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();
}
diff --git a/src/client/client.h b/src/client/client.h
index eea78d456..3b1095ac2 100644
--- a/src/client/client.h
+++ b/src/client/client.h
@@ -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;