Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Withdrawn BytesPacketsCount. Header size passed as parameter #2812

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 25 additions & 27 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4712,7 +4712,6 @@ bool srt::CUDT::applyResponseSettings(const CPacket* pHspkt /*[[nullable]]*/) AT
const size_t full_hdr_size = CPacket::UDP_HDR_SIZE + CPacket::HDR_SIZE;
m_iMaxSRTPayloadSize = m_config.iMSS - full_hdr_size;
HLOGC(cnlog.Debug, log << CONID() << "applyResponseSettings: PAYLOAD SIZE: " << m_iMaxSRTPayloadSize);
m_stats.setupHeaderSize(full_hdr_size);

m_iFlowWindowSize = m_ConnRes.m_iFlightFlagSize;
const int udpsize = m_config.iMSS - CPacket::UDP_HDR_SIZE;
Expand Down Expand Up @@ -5577,7 +5576,7 @@ int srt::CUDT::rcvDropTooLateUpTo(int seqno)
enterCS(m_StatsLock);
// Estimate dropped bytes from average payload size.
const uint64_t avgpayloadsz = m_pRcvBuffer->getRcvAvgPayloadSize();
m_stats.rcvr.dropped.count(stats::BytesPacketsCount(iDropCnt * avgpayloadsz, (uint32_t) iDropCnt));
m_stats.rcvr.dropped.count(stats::BytesPackets(iDropCnt * avgpayloadsz, (uint32_t) iDropCnt));
leaveCS(m_StatsLock);
}
return iDropCnt;
Expand All @@ -5601,7 +5600,7 @@ void srt::CUDT::setInitialRcvSeq(int32_t isn)
const int iDropCnt = m_pRcvBuffer->dropAll();
const uint64_t avgpayloadsz = m_pRcvBuffer->getRcvAvgPayloadSize();
sync::ScopedLock sl(m_StatsLock);
m_stats.rcvr.dropped.count(stats::BytesPacketsCount(iDropCnt * avgpayloadsz, (uint32_t) iDropCnt));
m_stats.rcvr.dropped.count(stats::BytesPackets(iDropCnt * avgpayloadsz, (uint32_t) iDropCnt));
}

m_pRcvBuffer->setStartSeqNo(isn);
Expand Down Expand Up @@ -5721,7 +5720,6 @@ void srt::CUDT::acceptAndRespond(const sockaddr_any& agent, const sockaddr_any&
m_iMaxSRTPayloadSize = m_config.iMSS - full_hdr_size;

HLOGC(cnlog.Debug, log << CONID() << "acceptAndRespond: PAYLOAD SIZE: " << m_iMaxSRTPayloadSize);
m_stats.setupHeaderSize(full_hdr_size);

// exchange info for maximum flow window size
m_iFlowWindowSize = w_hs.m_iFlightFlagSize;
Expand Down Expand Up @@ -6497,7 +6495,7 @@ int srt::CUDT::sndDropTooLate()

// If some packets were dropped update stats, socket state, loss list and the parent group if any.
enterCS(m_StatsLock);
m_stats.sndr.dropped.count(stats::BytesPacketsCount((uint64_t) dbytes, (uint32_t) dpkts));
m_stats.sndr.dropped.count(stats::BytesPackets((uint64_t) dbytes, (uint32_t) dpkts));
leaveCS(m_StatsLock);

IF_HEAVY_LOGGING(const int32_t realack = m_iSndLastDataAck);
Expand Down Expand Up @@ -7457,17 +7455,17 @@ void srt::CUDT::bstats(CBytePerfMon *perf, bool clear, bool instantaneous)
perf->pktRcvFilterLoss = m_stats.rcvr.lossFilter.trace.count();

/* perf byte counters include all headers (SRT+UDP+IP) */
perf->byteSent = m_stats.sndr.sent.trace.bytesWithHdr();
perf->byteSentUnique = m_stats.sndr.sentUnique.trace.bytesWithHdr();
perf->byteRecv = m_stats.rcvr.recvd.trace.bytesWithHdr();
perf->byteRecvUnique = m_stats.rcvr.recvdUnique.trace.bytesWithHdr();
perf->byteRetrans = m_stats.sndr.sentRetrans.trace.bytesWithHdr();
perf->byteRcvLoss = m_stats.rcvr.lost.trace.bytesWithHdr();
perf->byteSent = m_stats.sndr.sent.trace.bytesWithHdr(pktHdrSize);
perf->byteSentUnique = m_stats.sndr.sentUnique.trace.bytesWithHdr(pktHdrSize);
perf->byteRecv = m_stats.rcvr.recvd.trace.bytesWithHdr(pktHdrSize);
perf->byteRecvUnique = m_stats.rcvr.recvdUnique.trace.bytesWithHdr(pktHdrSize);
perf->byteRetrans = m_stats.sndr.sentRetrans.trace.bytesWithHdr(pktHdrSize);
perf->byteRcvLoss = m_stats.rcvr.lost.trace.bytesWithHdr(pktHdrSize);

perf->pktSndDrop = m_stats.sndr.dropped.trace.count();
perf->pktRcvDrop = m_stats.rcvr.dropped.trace.count();
perf->byteSndDrop = m_stats.sndr.dropped.trace.bytesWithHdr();
perf->byteRcvDrop = m_stats.rcvr.dropped.trace.bytesWithHdr();
perf->byteSndDrop = m_stats.sndr.dropped.trace.bytesWithHdr(pktHdrSize);
perf->byteRcvDrop = m_stats.rcvr.dropped.trace.bytesWithHdr(pktHdrSize);
perf->pktRcvUndecrypt = m_stats.rcvr.undecrypted.trace.count();
perf->byteRcvUndecrypt = m_stats.rcvr.undecrypted.trace.bytes();

Expand All @@ -7484,22 +7482,22 @@ void srt::CUDT::bstats(CBytePerfMon *perf, bool clear, bool instantaneous)
perf->pktRecvNAKTotal = m_stats.sndr.recvdNak.total.count();
perf->usSndDurationTotal = m_stats.m_sndDurationTotal;

perf->byteSentTotal = m_stats.sndr.sent.total.bytesWithHdr();
perf->byteSentUniqueTotal = m_stats.sndr.sentUnique.total.bytesWithHdr();
perf->byteRecvTotal = m_stats.rcvr.recvd.total.bytesWithHdr();
perf->byteRecvUniqueTotal = m_stats.rcvr.recvdUnique.total.bytesWithHdr();
perf->byteRetransTotal = m_stats.sndr.sentRetrans.total.bytesWithHdr();
perf->byteSentTotal = m_stats.sndr.sent.total.bytesWithHdr(pktHdrSize);
perf->byteSentUniqueTotal = m_stats.sndr.sentUnique.total.bytesWithHdr(pktHdrSize);
perf->byteRecvTotal = m_stats.rcvr.recvd.total.bytesWithHdr(pktHdrSize);
perf->byteRecvUniqueTotal = m_stats.rcvr.recvdUnique.total.bytesWithHdr(pktHdrSize);
perf->byteRetransTotal = m_stats.sndr.sentRetrans.total.bytesWithHdr(pktHdrSize);
perf->pktSndFilterExtraTotal = m_stats.sndr.sentFilterExtra.total.count();
perf->pktRcvFilterExtraTotal = m_stats.rcvr.recvdFilterExtra.total.count();
perf->pktRcvFilterSupplyTotal = m_stats.rcvr.suppliedByFilter.total.count();
perf->pktRcvFilterLossTotal = m_stats.rcvr.lossFilter.total.count();

perf->byteRcvLossTotal = m_stats.rcvr.lost.total.bytesWithHdr();
perf->byteRcvLossTotal = m_stats.rcvr.lost.total.bytesWithHdr(pktHdrSize);
perf->pktSndDropTotal = m_stats.sndr.dropped.total.count();
perf->pktRcvDropTotal = m_stats.rcvr.dropped.total.count();
// TODO: The payload is dropped. Probably header sizes should not be counted?
perf->byteSndDropTotal = m_stats.sndr.dropped.total.bytesWithHdr();
perf->byteRcvDropTotal = m_stats.rcvr.dropped.total.bytesWithHdr();
perf->byteSndDropTotal = m_stats.sndr.dropped.total.bytesWithHdr(pktHdrSize);
perf->byteRcvDropTotal = m_stats.rcvr.dropped.total.bytesWithHdr(pktHdrSize);
perf->pktRcvUndecryptTotal = m_stats.rcvr.undecrypted.total.count();
perf->byteRcvUndecryptTotal = m_stats.rcvr.undecrypted.total.bytes();

Expand Down Expand Up @@ -9021,7 +9019,7 @@ void srt::CUDT::processCtrlDropReq(const CPacket& ctrlpkt)

// Estimate dropped bytes from average payload size.
const uint64_t avgpayloadsz = m_pRcvBuffer->getRcvAvgPayloadSize();
m_stats.rcvr.dropped.count(stats::BytesPacketsCount(iDropCnt * avgpayloadsz, (uint32_t) iDropCnt));
m_stats.rcvr.dropped.count(stats::BytesPackets(iDropCnt * avgpayloadsz, (uint32_t) iDropCnt));
}
}
// When the drop request was received, it means that there are
Expand Down Expand Up @@ -10137,8 +10135,8 @@ int srt::CUDT::handleSocketPacketReception(const vector<CUnit*>& incoming, bool&

const steady_clock::time_point tnow = steady_clock::now();
ScopedLock lg(m_StatsLock);
m_stats.rcvr.dropped.count(stats::BytesPacketsCount(iDropCnt * rpkt.getLength(), iDropCnt));
m_stats.rcvr.undecrypted.count(stats::BytesPacketsCount(rpkt.getLength(), 1));
m_stats.rcvr.dropped.count(stats::BytesPackets(iDropCnt * rpkt.getLength(), iDropCnt));
m_stats.rcvr.undecrypted.count(stats::BytesPackets(rpkt.getLength(), 1));
string why;
if (frequentLogAllowed(FREQLOGFA_ENCRYPTION_FAILURE, tnow, (why)))
{
Expand All @@ -10161,8 +10159,8 @@ int srt::CUDT::handleSocketPacketReception(const vector<CUnit*>& incoming, bool&

const steady_clock::time_point tnow = steady_clock::now();
ScopedLock lg(m_StatsLock);
m_stats.rcvr.dropped.count(stats::BytesPacketsCount(iDropCnt* rpkt.getLength(), iDropCnt));
m_stats.rcvr.undecrypted.count(stats::BytesPacketsCount(rpkt.getLength(), 1));
m_stats.rcvr.dropped.count(stats::BytesPackets(iDropCnt* rpkt.getLength(), iDropCnt));
m_stats.rcvr.undecrypted.count(stats::BytesPackets(rpkt.getLength(), 1));
string why;
if (frequentLogAllowed(FREQLOGFA_ENCRYPTION_FAILURE, tnow, (why)))
{
Expand Down Expand Up @@ -10362,7 +10360,7 @@ int srt::CUDT::processData(CUnit* in_unit)

ScopedLock lg(m_StatsLock);
const uint64_t avgpayloadsz = m_pRcvBuffer->getRcvAvgPayloadSize();
m_stats.rcvr.lost.count(stats::BytesPacketsCount(loss * avgpayloadsz, (uint32_t) loss));
m_stats.rcvr.lost.count(stats::BytesPackets(loss * avgpayloadsz, (uint32_t) loss));

HLOGC(qrlog.Debug,
log << CONID() << "LOSS STATS: n=" << loss << " SEQ: [" << CSeqNo::incseq(m_iRcvCurrPhySeqNo) << " "
Expand Down
8 changes: 1 addition & 7 deletions srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1170,16 +1170,10 @@ class CUDT
time_point tsLastSampleTime; // last performance sample time
int traceReorderDistance;
double traceBelatedTime;

int64_t sndDuration; // real time for sending
time_point sndDurationCounter; // timers to record the sending Duration

void setupHeaderSize(int hsize)
{
sndr.setupHeaderSize(hsize);
rcvr.setupHeaderSize(hsize);
}

} m_stats;

public:
Expand Down
18 changes: 12 additions & 6 deletions srtcore/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2379,6 +2379,12 @@ void CUDTGroup::bstatsSocket(CBytePerfMon* perf, bool clear)

const steady_clock::time_point currtime = steady_clock::now();

// NOTE: Potentially in the group we might be using both IPv4 and IPv6
// links and sending a single packet over these two links could be different.
// These stats then don't make much sense in this form, this has to be
// redesigned. We use the header size as per IPv4, as it was everywhere.
const int pktHdrSize = CPacket::HDR_SIZE + CPacket::UDP_HDR_SIZE;

memset(perf, 0, sizeof *perf);

ScopedLock gg(m_GroupLock);
Expand All @@ -2389,17 +2395,17 @@ void CUDTGroup::bstatsSocket(CBytePerfMon* perf, bool clear)
perf->pktRecvUnique = m_stats.recv.trace.count();
perf->pktRcvDrop = m_stats.recvDrop.trace.count();

perf->byteSentUnique = m_stats.sent.trace.bytesWithHdr();
perf->byteRecvUnique = m_stats.recv.trace.bytesWithHdr();
perf->byteRcvDrop = m_stats.recvDrop.trace.bytesWithHdr();
perf->byteSentUnique = m_stats.sent.trace.bytesWithHdr(pktHdrSize);
perf->byteRecvUnique = m_stats.recv.trace.bytesWithHdr(pktHdrSize);
perf->byteRcvDrop = m_stats.recvDrop.trace.bytesWithHdr(pktHdrSize);

perf->pktSentUniqueTotal = m_stats.sent.total.count();
perf->pktRecvUniqueTotal = m_stats.recv.total.count();
perf->pktRcvDropTotal = m_stats.recvDrop.total.count();

perf->byteSentUniqueTotal = m_stats.sent.total.bytesWithHdr();
perf->byteRecvUniqueTotal = m_stats.recv.total.bytesWithHdr();
perf->byteRcvDropTotal = m_stats.recvDrop.total.bytesWithHdr();
perf->byteSentUniqueTotal = m_stats.sent.total.bytesWithHdr(pktHdrSize);
perf->byteRecvUniqueTotal = m_stats.recv.total.bytesWithHdr(pktHdrSize);
perf->byteRcvDropTotal = m_stats.recvDrop.total.bytesWithHdr(pktHdrSize);

const double interval = static_cast<double>(count_microseconds(currtime - m_stats.tsLastSampleTime));
perf->mbpsSendRate = double(perf->byteSent) * 8.0 / interval;
Expand Down
65 changes: 10 additions & 55 deletions srtcore/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ namespace stats
class Packets
{
public:
typedef Packets count_type;

Packets() : m_count(0) {}

Packets(uint32_t num) : m_count(num) {}
Expand All @@ -48,15 +46,15 @@ class Packets
uint32_t m_count;
};

class BytesPacketsCount
class BytesPackets
{
public:
BytesPacketsCount()
BytesPackets()
: m_bytes(0)
, m_packets(0)
{}

BytesPacketsCount(uint64_t bytes, uint32_t n = 1)
BytesPackets(uint64_t bytes, uint32_t n = 1)
: m_bytes(bytes)
, m_packets(n)
{}
Expand Down Expand Up @@ -84,51 +82,31 @@ class BytesPacketsCount
return m_packets;
}

BytesPacketsCount& operator+= (const BytesPacketsCount& other)
BytesPackets& operator+= (const BytesPackets& other)
{
m_bytes += other.m_bytes;
m_packets += other.m_packets;
return *this;
}

uint64_t bytesWithHdr(size_t hdr_size) const
{
return m_bytes + m_packets * hdr_size;
}

protected:
uint64_t m_bytes;
uint32_t m_packets;
};

class BytesPackets: public BytesPacketsCount
{
public:
typedef BytesPacketsCount count_type;

// Set IPv4-based header size value as a fallback. This will be fixed upon connection.
BytesPackets()
: m_zPacketHeaderSize(CPacket::UDP_HDR_SIZE + CPacket::HDR_SIZE)
{}

public:

void setupHeaderSize(int size)
{
m_zPacketHeaderSize = uint64_t(size);
}

uint64_t bytesWithHdr() const
{
return m_bytes + m_packets * m_zPacketHeaderSize;
}

private:
uint64_t m_zPacketHeaderSize;
};

template <class METRIC_TYPE, class BASE_METRIC_TYPE = METRIC_TYPE>
struct Metric
{
METRIC_TYPE trace;
METRIC_TYPE total;

void count(typename METRIC_TYPE::count_type val)
void count(BASE_METRIC_TYPE val)
{
trace += val;
total += val;
Expand Down Expand Up @@ -166,16 +144,6 @@ struct Sender
Metric<Packets> recvdAck; // The number of ACK packets received by the sender.
Metric<Packets> recvdNak; // The number of ACK packets received by the sender.

void setupHeaderSize(int hdr_size)
{
#define SETHSIZE(var) var.setupHeaderSize(hdr_size)
SETHSIZE(sent);
SETHSIZE(sentUnique);
SETHSIZE(sentRetrans);
SETHSIZE(dropped);
#undef SETHSIZE
}

void reset()
{
sent.reset();
Expand Down Expand Up @@ -219,19 +187,6 @@ struct Receiver
Metric<Packets> sentAck; // The number of ACK packets sent by the receiver.
Metric<Packets> sentNak; // The number of NACK packets sent by the receiver.

void setupHeaderSize(int hdr_size)
{
#define SETHSIZE(var) var.setupHeaderSize(hdr_size)
SETHSIZE(recvd);
SETHSIZE(recvdUnique);
SETHSIZE(recvdRetrans);
SETHSIZE(lost);
SETHSIZE(dropped);
SETHSIZE(recvdBelated);
SETHSIZE(undecrypted);
#undef SETHSIZE
}

void reset()
{
recvd.reset();
Expand Down