aboutsummaryrefslogblamecommitdiffstats
path: root/library/cpp/messagebus/message_counter.cpp
blob: 04d9343f6a2149523a49e00a48fd34767d6685dc (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
                            









                                  
 








                                                                           
                                                      
                 
                                                
















                                                                           
#include "message_counter.h"

#include <util/stream/str.h>

using namespace NBus;
using namespace NBus::NPrivate;

TMessageCounter::TMessageCounter()
    : BytesData(0)
    , BytesNetwork(0)
    , Count(0)
    , CountCompressed(0)
    , CountCompressionRequests(0)
{
}

TMessageCounter& TMessageCounter::operator+=(const TMessageCounter& that) {
    BytesData += that.BytesData;
    BytesNetwork += that.BytesNetwork;
    Count += that.Count;
    CountCompressed += that.CountCompressed;
    CountCompressionRequests += that.CountCompressionRequests;
    return *this;
}

TString TMessageCounter::ToString(bool reader) const {
    if (reader) {
        Y_ASSERT(CountCompressionRequests == 0);
    }

    TStringStream readValue;
    readValue << Count;
    if (CountCompressionRequests != 0 || CountCompressed != 0) {
        readValue << " (" << CountCompressed << " compr";
        if (!reader) {
            readValue << ", " << CountCompressionRequests << " compr reqs";
        }
        readValue << ")";
    }
    readValue << ", ";
    readValue << BytesData << "b";
    if (BytesNetwork != BytesData) {
        readValue << " (" << BytesNetwork << "b network)";
    }
    return readValue.Str();
}