mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 07:59:35 -05:00
saving current work on new bandwidth display. Still need to add names for services/peers, and use an appropriate curve style
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@8608 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
37f68bc3b6
commit
989f80786e
@ -64,6 +64,7 @@ pqistreamer::pqistreamer(RsSerialiser *rss, const RsPeerId& id, BinInterface *bi
|
||||
mAvgLastUpdate = mCurrReadTS = mCurrSentTS = time(NULL);
|
||||
mIncomingSize = 0 ;
|
||||
|
||||
mStatisticsTimeStamp = 0 ;
|
||||
/* allocated once */
|
||||
mPkt_rpend_size = 0;
|
||||
mPkt_rpending = 0;
|
||||
@ -1093,7 +1094,9 @@ int pqistreamer::locked_compute_out_pkt_size() const
|
||||
|
||||
int pqistreamer::locked_gatherStatistics(std::list<RSTrafficClue>& out_lst,std::list<RSTrafficClue>& in_lst)
|
||||
{
|
||||
// std::cerr << "(II) called overloaded function pqistreamer::locked_gatherStatistics(). " << std::endl;
|
||||
out_lst = mPreviousStatsChunk_Out ;
|
||||
in_lst = mPreviousStatsChunk_In ;
|
||||
|
||||
return 1 ;
|
||||
}
|
||||
|
||||
|
@ -2,21 +2,48 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
//#define BWGRAPH_DEBUG 1
|
||||
|
||||
void BWGraphSource::update()
|
||||
{
|
||||
// std::cerr << "Updating BW graphsource..." << std::endl;
|
||||
|
||||
std::list<RSTrafficClue> in_rstcl ;
|
||||
std::list<RSTrafficClue> out_rstcl ;
|
||||
#ifdef BWGRAPH_DEBUG
|
||||
std::cerr << "Updating BW graphsource..." << std::endl;
|
||||
#endif
|
||||
|
||||
TrafficHistoryChunk thc ;
|
||||
rsConfig->getTrafficInfo(thc.out_rstcl,thc.in_rstcl);
|
||||
|
||||
#ifdef BWGRAPH_DEBUG
|
||||
std::cerr << " got " << std::dec << thc.out_rstcl.size() << " out clues" << std::endl;
|
||||
std::cerr << " got " << std::dec << thc.in_rstcl.size() << " in clues" << std::endl;
|
||||
#endif
|
||||
|
||||
// keep track of them, in case we need to change the sorting
|
||||
|
||||
thc.time_stamp = time(NULL) ;
|
||||
thc.time_stamp = getTime() ;
|
||||
mTrafficHistory.push_back(thc) ;
|
||||
|
||||
// add visible friends/services
|
||||
|
||||
for(std::list<RSTrafficClue>::const_iterator it(thc.out_rstcl.begin());it!=thc.out_rstcl.end();++it)
|
||||
{
|
||||
mVisibleFriends.insert(it->peer_id) ;
|
||||
mVisibleServices.insert(it->service_id) ;
|
||||
}
|
||||
|
||||
for(std::list<RSTrafficClue>::const_iterator it(thc.in_rstcl.begin());it!=thc.in_rstcl.end();++it)
|
||||
{
|
||||
mVisibleFriends.insert(it->peer_id) ;
|
||||
mVisibleServices.insert(it->service_id) ;
|
||||
}
|
||||
|
||||
#ifdef BWGRAPH_DEBUG
|
||||
std::cerr << " visible friends: " << std::dec << mVisibleFriends.size() << std::endl;
|
||||
std::cerr << " visible service: " << std::dec << mVisibleServices.size() << std::endl;
|
||||
#endif
|
||||
|
||||
// now, convert data to current curve points.
|
||||
|
||||
std::map<std::string,float> vals ;
|
||||
convertTrafficClueToValues(thc.out_rstcl,vals) ;
|
||||
|
||||
@ -54,11 +81,26 @@ void BWGraphSource::update()
|
||||
// also clears history
|
||||
|
||||
for(std::list<TrafficHistoryChunk>::iterator it = mTrafficHistory.begin();it!=mTrafficHistory.end();++it)
|
||||
if( ms - 1000*(*it).time_stamp > _time_limit_msecs)
|
||||
{
|
||||
#ifdef BWGRAPH_DEBUG
|
||||
std::cerr << "TS=" << (*it).time_stamp << ", ms = " << ms << ", diff=" << ms - (*it).time_stamp << " compared to " << _time_limit_msecs << std::endl;
|
||||
#endif
|
||||
|
||||
if( ms - (*it).time_stamp > _time_limit_msecs)
|
||||
{
|
||||
it = mTrafficHistory.erase(it) ;
|
||||
|
||||
#ifdef BWGRAPH_DEBUG
|
||||
std::cerr << "Removing 1 item of traffic history" << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
break ;
|
||||
}
|
||||
|
||||
#ifdef BWGRAPH_DEBUG
|
||||
std::cerr << "Traffic history has size " << mTrafficHistory.size() << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void BWGraphSource::convertTrafficClueToValues(const std::list<RSTrafficClue>& lst,std::map<std::string,float>& vals) const
|
||||
@ -109,6 +151,7 @@ void BWGraphSource::convertTrafficClueToValues(const std::list<RSTrafficClue>& l
|
||||
}
|
||||
}
|
||||
break ;
|
||||
|
||||
case GRAPH_TYPE_ALL:
|
||||
switch(_service_graph_type)
|
||||
{
|
||||
@ -228,25 +271,100 @@ QString BWGraphSource::niceNumber(float v) const
|
||||
return QString::number(v/(1024*1024.0*1024),'f',2) + " GB";
|
||||
}
|
||||
|
||||
void BWGraphSource::setSelector(int selector_class,int selector_type,const std::string& selector_client_string)
|
||||
void BWGraphSource::setSelector(int selector_type,int graph_type,const std::string& selector_client_string)
|
||||
{
|
||||
std::cerr << "Setting Graph Source selector to " << selector_type << " - " << graph_type << " - " << selector_client_string << std::endl;
|
||||
|
||||
bool changed = false ;
|
||||
|
||||
if(selector_type == SELECTOR_TYPE_FRIEND && (_friend_graph_type != graph_type || (graph_type == GRAPH_TYPE_SINGLE && selector_client_string != _current_selected_friend.toStdString())))
|
||||
{
|
||||
changed = true ;
|
||||
_friend_graph_type = graph_type ;
|
||||
if(graph_type == GRAPH_TYPE_SINGLE)
|
||||
{
|
||||
|
||||
RsPeerId ns(selector_client_string) ;
|
||||
|
||||
if(!ns.isNull())
|
||||
_current_selected_friend = ns ;
|
||||
else
|
||||
std::cerr << "(EE) Cannot set current friend to " << selector_client_string << ": unrecognized friend string." << std::endl;
|
||||
}
|
||||
}
|
||||
else if(selector_type == SELECTOR_TYPE_SERVICE && _service_graph_type != graph_type)
|
||||
{
|
||||
changed = true ;
|
||||
_service_graph_type = graph_type ;
|
||||
}
|
||||
|
||||
// now re-convert all traffic history into the appropriate curves
|
||||
|
||||
if(changed)
|
||||
recomputeCurrentCurves() ;
|
||||
}
|
||||
void BWGraphSource::setUnit(int unit)
|
||||
{
|
||||
if(unit == _current_unit)
|
||||
return ;
|
||||
|
||||
_current_unit = unit ;
|
||||
|
||||
recomputeCurrentCurves() ;
|
||||
}
|
||||
void BWGraphSource::setDirection(int dir)
|
||||
{
|
||||
if(dir == _current_direction)
|
||||
return ;
|
||||
|
||||
_current_direction = dir ;
|
||||
|
||||
recomputeCurrentCurves() ;
|
||||
}
|
||||
void BWGraphSource::recomputeCurrentCurves()
|
||||
{
|
||||
std::cerr << "BWGraphSource: recomputing current curves." << std::endl;
|
||||
|
||||
_points.clear() ;
|
||||
|
||||
// now, convert data to current curve points.
|
||||
|
||||
for(std::list<TrafficHistoryChunk>::const_iterator it(mTrafficHistory.begin());it!=mTrafficHistory.end();++it)
|
||||
{
|
||||
std::map<std::string,float> vals ;
|
||||
qint64 ms = (*it).time_stamp ;
|
||||
|
||||
if(_current_direction==DIRECTION_UP)
|
||||
convertTrafficClueToValues((*it).out_rstcl,vals) ;
|
||||
else
|
||||
convertTrafficClueToValues((*it).in_rstcl,vals) ;
|
||||
|
||||
for(std::map<std::string,float>::iterator it2=vals.begin();it2!=vals.end();++it2)
|
||||
_points[it2->first].push_back(std::make_pair(ms,it2->second)) ;
|
||||
}
|
||||
|
||||
std::cerr << " points() contains " << _points.size() << " curves." << std::endl;
|
||||
}
|
||||
|
||||
BWGraph::BWGraph(QWidget *parent) : RSGraphWidget(parent)
|
||||
{
|
||||
_local_source = new BWGraphSource() ;
|
||||
|
||||
std::cerr << "creaitng new BWGraph Source " << (void*)_local_source << std::endl;
|
||||
_local_source->setCollectionTimeLimit(30*60*1000) ; // 30 mins
|
||||
_local_source->setCollectionTimePeriod(1000) ; // collect every second
|
||||
_local_source->setDigits(2) ;
|
||||
_local_source->start() ;
|
||||
_local_source->setUnit(BWGraphSource::UNIT_KILOBYTES) ;
|
||||
_local_source->setDirection(BWGraphSource::DIRECTION_UP) ;
|
||||
_local_source->setSelector(BWGraphSource::SELECTOR_TYPE_FRIEND,BWGraphSource::GRAPH_TYPE_ALL) ;
|
||||
_local_source->setSelector(BWGraphSource::SELECTOR_TYPE_SERVICE,BWGraphSource::GRAPH_TYPE_SUM) ;
|
||||
|
||||
setSource(_local_source) ;
|
||||
|
||||
setTimeScale(1.0f) ; // 1 pixels per second of time.
|
||||
|
||||
resetFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ;
|
||||
setFlags(RSGRAPH_FLAGS_LOG_SCALE_Y) ;
|
||||
resetFlags(RSGRAPH_FLAGS_PAINT_STYLE_PLAIN) ;
|
||||
|
||||
setFlags(RSGRAPH_FLAGS_SHOW_LEGEND) ;
|
||||
|
@ -16,6 +16,7 @@ public:
|
||||
enum { SELECTOR_TYPE_FRIEND=0x00, SELECTOR_TYPE_SERVICE=0x01 };
|
||||
enum { GRAPH_TYPE_SINGLE=0x00, GRAPH_TYPE_ALL=0x01, GRAPH_TYPE_SUM=0x02 };
|
||||
enum { UNIT_KILOBYTES=0x00, UNIT_COUNT=0x01 };
|
||||
enum { DIRECTION_UP=0x00, DIRECTION_DOWN=0x01 };
|
||||
|
||||
// re-derived from RSGraphSource
|
||||
|
||||
@ -27,10 +28,21 @@ public:
|
||||
|
||||
// own methdods to control what's used to create displayed info
|
||||
|
||||
void setSelector(int selector_class,int selector_type,const std::string& selector_client_string = std::string()) ;
|
||||
void setSelector(int selector_type, int graph_type, const std::string& selector_client_string = std::string()) ;
|
||||
void setDirection(int dir) ;
|
||||
void setUnit(int unit) ;
|
||||
|
||||
int direction() const { return _current_direction ;}
|
||||
int unit() const { return _current_unit ;}
|
||||
int friendGraphType() const { return _friend_graph_type ;}
|
||||
int serviceGraphType() const { return _service_graph_type ;}
|
||||
|
||||
const std::set<RsPeerId>& visibleFriends() const { return mVisibleFriends; }
|
||||
const std::set<uint16_t>& visibleServices() const { return mVisibleServices; }
|
||||
|
||||
protected:
|
||||
void convertTrafficClueToValues(const std::list<RSTrafficClue> &lst, std::map<std::string, float> &vals) const;
|
||||
void recomputeCurrentCurves() ;
|
||||
|
||||
private:
|
||||
QString niceNumber(float v) const;
|
||||
@ -41,12 +53,16 @@ private:
|
||||
int _friend_graph_type ;
|
||||
int _service_graph_type ;
|
||||
|
||||
RsPeerId _current_selected_friend ;
|
||||
RsPeerId _current_selected_friend ;
|
||||
std::string _current_selected_friend_name ;
|
||||
uint16_t _current_selected_service ;
|
||||
int _current_unit ;
|
||||
uint16_t _current_selected_service ;
|
||||
int _current_unit ;
|
||||
int _current_direction ;
|
||||
|
||||
std::list<TrafficHistoryChunk> mTrafficHistory ;
|
||||
|
||||
std::set<RsPeerId> mVisibleFriends ;
|
||||
std::set<uint16_t> mVisibleServices ;
|
||||
};
|
||||
|
||||
class BWGraph: public RSGraphWidget
|
||||
@ -56,6 +72,8 @@ class BWGraph: public RSGraphWidget
|
||||
|
||||
BWGraphSource *source() ;
|
||||
|
||||
const std::set<RsPeerId>& visibleFriends() const { return _local_source->visibleFriends(); }
|
||||
const std::set<uint16_t>& visibleServices() const { return _local_source->visibleServices(); }
|
||||
protected:
|
||||
BWGraphSource *_local_source ;
|
||||
};
|
||||
|
@ -1,5 +1,9 @@
|
||||
#include <QComboBox>
|
||||
#include <QTimer>
|
||||
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "util/RsProtectedTimer.h"
|
||||
#include "retroshare-gui/RsAutoUpdatePage.h"
|
||||
#include "BandwidthStatsWidget.h"
|
||||
|
||||
BandwidthStatsWidget::BandwidthStatsWidget(QWidget *parent)
|
||||
@ -7,10 +11,112 @@ BandwidthStatsWidget::BandwidthStatsWidget(QWidget *parent)
|
||||
{
|
||||
ui.setupUi(this) ;
|
||||
|
||||
// now add one button per service
|
||||
|
||||
ui.friend_CB->addItem(tr("Sum")) ;
|
||||
ui.friend_CB->addItem(tr("All")) ;
|
||||
|
||||
ui.service_CB->addItem(tr("Sum")) ;
|
||||
ui.service_CB->addItem(tr("All")) ;
|
||||
|
||||
ui.unit_CB->addItem(tr("KB/s")) ;
|
||||
ui.unit_CB->addItem(tr("Count")) ;
|
||||
|
||||
// Setup connections
|
||||
|
||||
QObject::connect(ui.friend_CB ,SIGNAL(currentIndexChanged(int)),this, SLOT( updateFriendSelection(int))) ;
|
||||
QObject::connect(ui.updn_CB ,SIGNAL(currentIndexChanged(int)),this, SLOT( updateUpDownSelection(int))) ;
|
||||
QObject::connect(ui.unit_CB ,SIGNAL(currentIndexChanged(int)),this, SLOT( updateUnitSelection(int))) ;
|
||||
QObject::connect(ui.service_CB,SIGNAL(currentIndexChanged(int)),this, SLOT(updateServiceSelection(int))) ;
|
||||
|
||||
// setup one timer for auto-update
|
||||
|
||||
mTimer = new QTimer(this) ;
|
||||
connect(mTimer, SIGNAL(timeout()), this, SLOT(updateComboBoxes())) ;
|
||||
mTimer->setSingleShot(false) ;
|
||||
mTimer->start(2000) ;
|
||||
}
|
||||
|
||||
void BandwidthStatsWidget::updateComboBoxes()
|
||||
{
|
||||
if(!isVisible())
|
||||
return ;
|
||||
|
||||
if(RsAutoUpdatePage::eventsLocked())
|
||||
return ;
|
||||
|
||||
// Setup button/combobox info
|
||||
|
||||
uint32_t indx = 2 ;
|
||||
RsPeerDetails details ;
|
||||
RsPeerId current_friend_id(ui.friend_CB->itemData(ui.friend_CB->currentIndex()).toString().toStdString()) ;
|
||||
|
||||
for(std::set<RsPeerId>::const_iterator it(ui.bwgraph_BW->visibleFriends().begin());it!=ui.bwgraph_BW->visibleFriends().end();++it)
|
||||
{
|
||||
if( (*it).toStdString() != ui.friend_CB->itemData(indx).toString().toStdString())
|
||||
{
|
||||
std::cerr << " friends: " << *it << " not in combo at place " << indx << ". Adding it." << std::endl;
|
||||
|
||||
QString name = "[Unknown]" ;
|
||||
QVariant data ;
|
||||
|
||||
if(rsPeers->getPeerDetails(*it,details))
|
||||
{
|
||||
name = QString::fromUtf8(details.name.c_str())+" ("+QString::fromUtf8(details.location.c_str())+")" ;
|
||||
data = QVariant(QString::fromStdString( (*it).toStdString())) ;
|
||||
}
|
||||
|
||||
if(ui.friend_CB->count() <= indx)
|
||||
ui.friend_CB->addItem(name,data) ;
|
||||
else
|
||||
{
|
||||
ui.friend_CB->setItemText(indx,name) ;
|
||||
ui.friend_CB->setItemData(indx,data) ;
|
||||
}
|
||||
|
||||
if(current_friend_id == *it && ui.friend_CB->currentIndex() != indx)
|
||||
ui.friend_CB->setCurrentIndex(indx) ;
|
||||
}
|
||||
++indx ;
|
||||
}
|
||||
|
||||
while(ui.friend_CB->count() > indx)
|
||||
{
|
||||
std::cerr << " friends: removing item " << ui.friend_CB->count()-1 << " currently " << ui.friend_CB->count() << " items" << std::endl;
|
||||
ui.friend_CB->removeItem(ui.friend_CB->count()-1) ;
|
||||
}
|
||||
|
||||
// now one entry per service
|
||||
|
||||
indx = 2 ;
|
||||
uint16_t current_service_id = ui.service_CB->itemData(ui.service_CB->currentIndex()).toInt() ;
|
||||
|
||||
for(std::set<uint16_t>::const_iterator it(ui.bwgraph_BW->visibleServices().begin());it!=ui.bwgraph_BW->visibleServices().end();++it)
|
||||
{
|
||||
if(*it != ui.service_CB->itemData(indx).toInt())
|
||||
{
|
||||
std::cerr << " services: " << std::hex << *it << std::dec << " not in combo at place " << indx << ". Adding it." << std::endl;
|
||||
|
||||
if(ui.service_CB->count() <= indx)
|
||||
ui.service_CB->addItem(QString::number(*it,16),QVariant(*it)) ;
|
||||
else
|
||||
{
|
||||
ui.service_CB->setItemText(indx,QString::number(*it,16)) ;
|
||||
ui.service_CB->setItemData(indx,QVariant(*it)) ;
|
||||
}
|
||||
|
||||
if(current_service_id == *it && ui.service_CB->currentIndex() != indx)
|
||||
ui.service_CB->setCurrentIndex(indx) ;
|
||||
|
||||
}
|
||||
++indx ;
|
||||
}
|
||||
|
||||
while(ui.service_CB->count() > indx)
|
||||
{
|
||||
std::cerr << " services: removing item " << ui.service_CB->count()-1 << std::endl;
|
||||
ui.service_CB->removeItem(ui.service_CB->count()-1) ;
|
||||
}
|
||||
}
|
||||
|
||||
void BandwidthStatsWidget::updateFriendSelection(int n)
|
||||
@ -53,3 +159,18 @@ void BandwidthStatsWidget::updateServiceSelection(int n)
|
||||
ui.bwgraph_BW->source()->setSelector(BWGraphSource::SELECTOR_TYPE_SERVICE,BWGraphSource::GRAPH_TYPE_SINGLE,ui.service_CB->itemData(ci,Qt::UserRole).toString().toStdString()) ;
|
||||
}
|
||||
}
|
||||
|
||||
void BandwidthStatsWidget::updateUpDownSelection(int n)
|
||||
{
|
||||
if(n==0)
|
||||
ui.bwgraph_BW->source()->setDirection(BWGraphSource::DIRECTION_UP) ;
|
||||
else
|
||||
ui.bwgraph_BW->source()->setDirection(BWGraphSource::DIRECTION_DOWN) ;
|
||||
}
|
||||
void BandwidthStatsWidget::updateUnitSelection(int n)
|
||||
{
|
||||
if(n==0)
|
||||
ui.bwgraph_BW->source()->setUnit(BWGraphSource::UNIT_KILOBYTES) ;
|
||||
else
|
||||
ui.bwgraph_BW->source()->setUnit(BWGraphSource::UNIT_COUNT) ;
|
||||
}
|
||||
|
@ -3,13 +3,20 @@
|
||||
|
||||
class BandwidthStatsWidget: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BandwidthStatsWidget(QWidget *parent) ;
|
||||
|
||||
protected slots:
|
||||
void updateFriendSelection(int n);
|
||||
void updateServiceSelection(int n);
|
||||
void updateComboBoxes() ;
|
||||
void updateUpDownSelection(int n);
|
||||
void updateUnitSelection(int n);
|
||||
|
||||
private:
|
||||
Ui::BwStatsWidget ui;
|
||||
|
||||
QTimer *mTimer ;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user