Use integer storage and arithmetic for nanosec pcap

quint64 has larger range than double so has better accuracy. However,
for calculating packet rate, use floating-point arithmetic since the
packet rate is a double

Updates #238
This commit is contained in:
Srivats P 2022-01-19 18:43:47 +05:30
parent 45d5e15f23
commit 226705f015

View File

@ -503,12 +503,15 @@ _non_pdml:
stream->mutable_control()->set_num_packets(1);
// setup packet rate to the timing in pcap (as close as possible)
const double kXsecsInSec = nsecResolution ? 1e9 : 1e6;
// use quint64 rather than double to store micro/nano second as
// it has a larger range (~580 years) and therefore better accuracy
const quint64 kXsecsInSec = nsecResolution ? 1e9 : 1e6;
quint64 xsec = (pktHdr.tsSec*kXsecsInSec + pktHdr.tsUsec);
quint64 delta = xsec - lastXsec;
qDebug("pktCount = %d, delta = %llu", pktCount, delta);
if ((pktCount != 1) && delta)
stream->mutable_control()->set_packets_per_sec(kXsecsInSec/delta);
stream->mutable_control()->set_packets_per_sec(double(kXsecsInSec)/delta);
if (prevStream)
prevStream->mutable_control()->CopyFrom(stream->control());
@ -516,7 +519,6 @@ _non_pdml:
lastXsec = xsec;
prevStream = stream;
pktCount++;
qDebug("pktCount = %d", pktCount);
byteCount += pktHdr.inclLen + sizeof(pktHdr);
emit progress(int(byteCount*100/byteTotal)); // in percentage
if (stop_)