message_counter.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "message_counter.h"
  2. #include <util/stream/str.h>
  3. using namespace NBus;
  4. using namespace NBus::NPrivate;
  5. TMessageCounter::TMessageCounter()
  6. : BytesData(0)
  7. , BytesNetwork(0)
  8. , Count(0)
  9. , CountCompressed(0)
  10. , CountCompressionRequests(0)
  11. {
  12. }
  13. TMessageCounter& TMessageCounter::operator+=(const TMessageCounter& that) {
  14. BytesData += that.BytesData;
  15. BytesNetwork += that.BytesNetwork;
  16. Count += that.Count;
  17. CountCompressed += that.CountCompressed;
  18. CountCompressionRequests += that.CountCompressionRequests;
  19. return *this;
  20. }
  21. TString TMessageCounter::ToString(bool reader) const {
  22. if (reader) {
  23. Y_ASSERT(CountCompressionRequests == 0);
  24. }
  25. TStringStream readValue;
  26. readValue << Count;
  27. if (CountCompressionRequests != 0 || CountCompressed != 0) {
  28. readValue << " (" << CountCompressed << " compr";
  29. if (!reader) {
  30. readValue << ", " << CountCompressionRequests << " compr reqs";
  31. }
  32. readValue << ")";
  33. }
  34. readValue << ", ";
  35. readValue << BytesData << "b";
  36. if (BytesNetwork != BytesData) {
  37. readValue << " (" << BytesNetwork << "b network)";
  38. }
  39. return readValue.Str();
  40. }