sign: port stream tx stats are updated when TxThread finishes; actual Tx stream stats collection by TxThread is still pending

This commit is contained in:
Srivats P 2016-11-11 21:22:07 +05:30
parent cffada4c07
commit afcb4126b5
10 changed files with 91 additions and 24 deletions

View File

@ -54,14 +54,6 @@ AbstractPort::AbstractPort(int id, const char *device)
maxStatsValue_ = ULLONG_MAX; // assume 64-bit stats
memset((void*) &stats_, 0, sizeof(stats_));
resetStats();
// FIXME: temporary data for testing
{
StreamStatsTuple sst;
streamStats_.insert(1001, sst);
memset(&sst, 0, sizeof(sst));
streamStats_.insert(1002, sst);
}
}
AbstractPort::~AbstractPort()
@ -662,7 +654,7 @@ void AbstractPort::streamStatsAll(OstProto::StreamStatsList *stats)
{
// FIXME: change input param to a non-OstProto type and/or have
// a getFirst/Next like API?
QHashIterator<uint, StreamStatsTuple> i(streamStats_);
StreamStatsIterator i(streamStats_);
while (i.hasNext())
{
i.next();

View File

@ -20,7 +20,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#ifndef _SERVER_ABSTRACT_PORT_H
#define _SERVER_ABSTRACT_PORT_H
#include <QHash>
#include "streamstats.h"
#include <QList>
#include <QtGlobal>
@ -131,13 +132,6 @@ public:
quint64 neighborMacAddress(int streamId, int frameIndex);
protected:
struct StreamStatsTuple
{
quint64 rx_pkts;
quint64 rx_bytes;
quint64 tx_pkts;
quint64 tx_bytes;
};
void addNote(QString note);
@ -152,7 +146,7 @@ protected:
quint64 maxStatsValue_;
struct PortStats stats_;
QHash<uint, StreamStatsTuple> streamStats_;
StreamStats streamStats_;
//! \todo Need lock for stats access/update
DeviceManager *deviceManager_;

View File

@ -31,6 +31,7 @@ win32 {
LIBS += -lm
LIBS += -lprotobuf
HEADERS += drone.h \
pcaptransmitter.h \
myservice.h
SOURCES += \
devicemanager.cpp \

View File

@ -31,7 +31,7 @@ PcapPort::PcapPort(int id, const char *device)
{
monitorRx_ = new PortMonitor(device, kDirectionRx, &stats_);
monitorTx_ = new PortMonitor(device, kDirectionTx, &stats_);
transmitter_ = new PcapTransmitter(device);
transmitter_ = new PcapTransmitter(device, streamStats_);
capturer_ = new PortCapturer(device);
emulXcvr_ = new EmulationTransceiver(device, deviceManager_);

View File

@ -19,14 +19,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "pcaptransmitter.h"
PcapTransmitter::PcapTransmitter(const char *device)
: txThread_(device)
PcapTransmitter::PcapTransmitter(
const char *device,
StreamStats &portStreamStats)
: streamStats_(portStreamStats), txThread_(device)
{
memset(&stats_, 0, sizeof(stats_));
txStats_.setTxThreadStats(&stats_);
txStats_.start(); // TODO: alongwith user transmit start
txThread_.setStats(&stats_);
connect(&txThread_, SIGNAL(finished()), SLOT(updateTxThreadStreamStats()));
}
PcapTransmitter::~PcapTransmitter()
@ -92,3 +95,21 @@ bool PcapTransmitter::isRunning()
{
return txThread_.isRunning();
}
void PcapTransmitter::updateTxThreadStreamStats()
{
PcapTxThread *txThread = dynamic_cast<PcapTxThread*>(sender());
const StreamStats& threadStreamStats = txThread->streamStats();
StreamStatsIterator i(threadStreamStats);
while (i.hasNext())
{
i.next();
uint guid = i.key();
StreamStatsTuple sst = i.value();
streamStats_[guid].tx_pkts += sst.tx_pkts;
streamStats_[guid].tx_bytes += sst.tx_bytes;
}
txThread->clearStreamStats();
}

View File

@ -25,10 +25,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "pcaptxthread.h"
#include "statstuple.h"
class PcapTransmitter
class PcapTransmitter : QObject
{
Q_OBJECT
public:
PcapTransmitter(const char *device);
PcapTransmitter(const char *device, StreamStats &portStreamStats);
~PcapTransmitter();
bool setRateAccuracy(AbstractPort::Accuracy accuracy);
@ -46,8 +47,10 @@ public:
void start();
void stop();
bool isRunning();
private slots:
void updateTxThreadStreamStats();
private:
StreamStats &streamStats_;
PcapTxThread txThread_;
PcapTxStats txStats_;
StatsTuple stats_;

View File

@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
#include "pcaptxstats.h"
#include "pcaptxstats.h"
#include "statstuple.h"
PcapTxStats::PcapTxStats()

View File

@ -203,6 +203,16 @@ void PcapTxThread::setStats(StatsTuple *stats)
stats_ = stats;
}
const StreamStats& PcapTxThread::streamStats()
{
return streamStats_;
}
void PcapTxThread::clearStreamStats()
{
streamStats_.clear();
}
void PcapTxThread::run()
{
//! \todo (MED) Stream Mode - continuous: define before implement
@ -325,6 +335,11 @@ _restart:
}
_exit:
// TODO: update stream stats
// FIXME: temporary data for testing
streamStats_[1001].tx_pkts = 12345;
streamStats_[1001].tx_bytes = 56789;
state_ = kFinished;
}

View File

@ -47,6 +47,9 @@ public:
void setStats(StatsTuple *stats);
const StreamStats& streamStats();
void clearStreamStats();
void run();
void start();
@ -82,6 +85,7 @@ private:
volatile State state_;
StatsTuple *stats_;
StreamStats streamStats_;
};
#endif

36
server/streamstats.h Normal file
View File

@ -0,0 +1,36 @@
/*
Copyright (C) 2016 Srivats P.
This file is part of "Ostinato"
This is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef _STREAM_STATS_H
#define _STREAM_STATS_H
#include <QHash>
struct StreamStatsTuple
{
quint64 rx_pkts;
quint64 rx_bytes;
quint64 tx_pkts;
quint64 tx_bytes;
};
typedef QHash<uint, StreamStatsTuple> StreamStats;
typedef QHashIterator<uint, StreamStatsTuple> StreamStatsIterator;
#endif