Skip to content

Commit

Permalink
Client: Add sum and average to packetcounter
Browse files Browse the repository at this point in the history
  • Loading branch information
sfan5 committed May 17, 2020
1 parent a9c3a42 commit be38a44
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/client/client.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion src/client/client.h
Expand Up @@ -94,11 +94,12 @@ class PacketCounter
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;
Expand Down

0 comments on commit be38a44

Please sign in to comment.