sign: Calculate stream stats only if configured

Stream Stats Rx and Tx both are calculated only if 'Track Stream Stats'
is configured on the port
This commit is contained in:
Srivats P 2016-12-06 21:41:47 +05:30
parent 028843c55a
commit 35c56b9181
6 changed files with 47 additions and 7 deletions

View File

@ -27,7 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
class PacketSequence
{
public:
PacketSequence() {
PacketSequence(bool trackGuidStats) {
trackGuidStats_ = trackGuidStats;
sendQueue_ = pcap_sendqueue_alloc(1*1024*1024);
lastPacket_ = NULL;
packets_ = 0;
@ -61,7 +62,7 @@ public:
lastPacket_ = (struct pcap_pkthdr *)
(sendQueue_->buffer + sendQueue_->len);
ret = pcap_sendqueue_queue(sendQueue_, pktHeader, pktData);
if (ret >= 0) {
if (trackGuidStats_ && (ret >= 0)) {
uint guid;
if (SignProtocol::packetGuid(pktData, pktHeader->caplen, &guid)) {
streamStatsMeta_[guid].tx_pkts++;
@ -79,6 +80,9 @@ public:
int repeatSize_;
long usecDelay_;
StreamStats streamStatsMeta_;
private:
bool trackGuidStats_;
};
#endif

View File

@ -132,12 +132,32 @@ bool PcapPort::setRateAccuracy(AbstractPort::Accuracy accuracy)
bool PcapPort::startStreamStatsTracking()
{
return rxStatsPoller_->start();
if (!transmitter_->setStreamStatsTracking(true))
goto _tx_fail;
if (!rxStatsPoller_->start())
goto _rx_fail;
return true;
_rx_fail:
transmitter_->setStreamStatsTracking(false);
_tx_fail:
qWarning("failed to start stream stats tracking");
return false;
}
bool PcapPort::stopStreamStatsTracking()
{
return rxStatsPoller_->stop();
if (!transmitter_->setStreamStatsTracking(false))
goto _tx_fail;
if (!rxStatsPoller_->stop())
goto _rx_fail;
return true;
_rx_fail:
transmitter_->setStreamStatsTracking(true);
_tx_fail:
qWarning("failed to stop stream stats tracking");
return false;
}
void PcapPort::startDeviceEmulation()

View File

@ -43,6 +43,11 @@ bool PcapTransmitter::setRateAccuracy(
return txThread_.setRateAccuracy(accuracy);
}
bool PcapTransmitter::setStreamStatsTracking(bool enable)
{
return txThread_.setStreamStatsTracking(enable);
}
void PcapTransmitter::clearPacketList()
{
txThread_.clearPacketList();

View File

@ -33,6 +33,7 @@ public:
~PcapTransmitter();
bool setRateAccuracy(AbstractPort::Accuracy accuracy);
bool setStreamStatsTracking(bool enable);
void clearPacketList();
void loopNextPacketSet(qint64 size, qint64 repeats,

View File

@ -39,6 +39,7 @@ PcapTxThread::PcapTxThread(const char *device)
#endif
state_ = kNotStarted;
stop_ = false;
trackStreamStats_ = false;
clearPacketList();
handle_ = pcap_open_live(device, 64 /* FIXME */, 0, 1000 /* ms */, errbuf);
@ -82,6 +83,12 @@ bool PcapTxThread::setRateAccuracy(
return true;
}
bool PcapTxThread::setStreamStatsTracking(bool enable)
{
trackStreamStats_ = enable;
return true;
}
void PcapTxThread::clearPacketList()
{
Q_ASSERT(!isRunning());
@ -103,7 +110,7 @@ void PcapTxThread::clearPacketList()
void PcapTxThread::loopNextPacketSet(qint64 size, qint64 repeats,
long repeatDelaySec, long repeatDelayNsec)
{
currentPacketSequence_ = new PacketSequence;
currentPacketSequence_ = new PacketSequence(trackStreamStats_);
currentPacketSequence_->repeatCount_ = repeats;
currentPacketSequence_->usecDelay_ = repeatDelaySec * long(1e6)
+ repeatDelayNsec/1000;
@ -141,7 +148,7 @@ bool PcapTxThread::appendToPacketList(long sec, long nsec,
}
//! \todo (LOW): calculate sendqueue size
currentPacketSequence_ = new PacketSequence;
currentPacketSequence_ = new PacketSequence(trackStreamStats_);
packetSequenceList_.append(currentPacketSequence_);
@ -342,6 +349,7 @@ _restart:
}
_exit:
if (trackStreamStats_)
updateStreamStats();
state_ = kFinished;

View File

@ -34,6 +34,7 @@ public:
~PcapTxThread();
bool setRateAccuracy(AbstractPort::Accuracy accuracy);
bool setStreamStatsTracking(bool enable);
void clearPacketList();
void loopNextPacketSet(qint64 size, qint64 repeats,
@ -87,6 +88,7 @@ private:
volatile bool stop_;
volatile State state_;
bool trackStreamStats_;
StatsTuple *stats_;
StatsTuple lastStats_;
StreamStats streamStats_;