Skip to content

Commit

Permalink
Avoid copying ConsumerStatsImpl or ProducerStatsImpl
Browse files Browse the repository at this point in the history
  • Loading branch information
BewareMyPower committed Mar 20, 2023
1 parent 8242c4b commit adfedf6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/stats/ConsumerStatsImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,15 @@ void ConsumerStatsImpl::flushAndReset(const boost::system::error_code& ec) {
}

Lock lock(mutex_);
ConsumerStatsImpl tmp = *this;
std::ostringstream oss;
oss << *this;
numBytesRecieved_ = 0;
receivedMsgMap_.clear();
ackedMsgMap_.clear();
lock.unlock();

scheduleTimer();
LOG_INFO(tmp);
LOG_INFO(oss.str());
}

ConsumerStatsImpl::~ConsumerStatsImpl() { timer_->cancel(); }
Expand Down
5 changes: 3 additions & 2 deletions lib/stats/ProducerStatsImpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ void ProducerStatsImpl::flushAndReset(const boost::system::error_code& ec) {
}

Lock lock(mutex_);
ProducerStatsImpl tmp = *this;
std::ostringstream oss;
oss << *this;
numMsgsSent_ = 0;
numBytesSent_ = 0;
sendMap_.clear();
Expand All @@ -81,7 +82,7 @@ void ProducerStatsImpl::flushAndReset(const boost::system::error_code& ec) {
lock.unlock();

scheduleTimer();
LOG_INFO(tmp);
LOG_INFO(oss.str());
}

void ProducerStatsImpl::messageSent(const Message& msg) {
Expand Down

0 comments on commit adfedf6

Please sign in to comment.