From 07d197a2d049aedb77536edeb3b20e51cc8c9588 Mon Sep 17 00:00:00 2001 From: Determinant Date: Sun, 7 Apr 2019 12:50:56 -0400 Subject: ... --- include/salticidae/network.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/include/salticidae/network.h b/include/salticidae/network.h index 1b871f5..11f720a 100644 --- a/include/salticidae/network.h +++ b/include/salticidae/network.h @@ -79,12 +79,14 @@ class MsgNetwork: public ConnPool { #ifdef SALTICIDAE_MSG_STAT mutable std::atomic nsent; mutable std::atomic nrecv; + mutable std::atomic nsentb; + mutable std::atomic nrecvb; #endif public: Conn(): msg_state(HEADER) #ifdef SALTICIDAE_MSG_STAT - , nsent(0), nrecv(0) + , nsent(0), nrecv(0), nsentb(0), nrecvb(0) #endif {} @@ -95,8 +97,14 @@ class MsgNetwork: public ConnPool { #ifdef SALTICIDAE_MSG_STAT size_t get_nsent() const { return nsent; } size_t get_nrecv() const { return nrecv; } - void clear_nsent() const { nsent = 0; } - void clear_nrecv() const { nrecv = 0; } + size_t get_nsentb() const { return nsentb; } + size_t get_nrecvb() const { return nrecvb; } + void clear_msgstat() const { + nsent.store(0, std::memory_order_relaxed); + nrecv.store(0, std::memory_order_relaxed); + nsentb.store(0, std::memory_order_relaxed); + nrecvb.store(0, std::memory_order_relaxed); + } #endif protected: @@ -116,8 +124,6 @@ class MsgNetwork: public ConnPool { queue_t incoming_msgs; protected: -#ifdef SALTICIDAE_MSG_STAT -#endif ConnPool::Conn *create_conn() override { return new Conn(); } @@ -157,10 +163,11 @@ class MsgNetwork: public ConnPool { SALTICIDAE_LOG_DEBUG("got message %s from %s", std::string(msg).c_str(), std::string(*conn).c_str()); - it->second(msg, conn); #ifdef SALTICIDAE_MSG_STAT conn->nrecv++; + conn->nrecvb += msg.get_length(); #endif + it->second(msg, conn); } if (++cnt == burst_size) return true; } @@ -182,8 +189,6 @@ class MsgNetwork: public ConnPool { template bool send_msg(MsgType &&msg, const conn_t &conn); using ConnPool::listen; -#ifdef SALTICIDAE_MSG_STAT -#endif conn_t connect(const NetAddr &addr) { return static_pointer_cast(ConnPool::connect(addr)); } @@ -467,6 +472,7 @@ bool MsgNetwork::send_msg(MsgType &&_msg, const conn_t &conn) { std::string(*conn).c_str()); #ifdef SALTICIDAE_MSG_STAT conn->nsent++; + conn->nsentb += msg.get_length(); #endif return conn->write(std::move(msg_data)); } -- cgit v1.2.3-70-g09d2