mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
removed updateTotals() method. Replaced it with costless on-the-fly update of totals
This commit is contained in:
parent
a00d2c912c
commit
e66c0d1349
@ -196,7 +196,7 @@ MainWindow::MainWindow(QWidget* parent, Qt::WindowFlags flags)
|
|||||||
this->setWindowIcon(QIcon(QString::fromUtf8(":/icons/logo_128.png")));
|
this->setWindowIcon(QIcon(QString::fromUtf8(":/icons/logo_128.png")));
|
||||||
|
|
||||||
/* Create all the dialogs of which we only want one instance */
|
/* Create all the dialogs of which we only want one instance */
|
||||||
_bandwidthGraph = new BandwidthGraph();
|
_bandwidthGraph = NULL ;
|
||||||
|
|
||||||
#ifdef UNFINISHED
|
#ifdef UNFINISHED
|
||||||
applicationWindow = new ApplicationWindow();
|
applicationWindow = new ApplicationWindow();
|
||||||
@ -559,7 +559,7 @@ void MainWindow::createTrayIcon()
|
|||||||
#ifdef ENABLE_WEBUI
|
#ifdef ENABLE_WEBUI
|
||||||
trayMenu->addAction(QIcon(":/images/emblem-web.png"), tr("Show web interface"), this, SLOT(showWebinterface()));
|
trayMenu->addAction(QIcon(":/images/emblem-web.png"), tr("Show web interface"), this, SLOT(showWebinterface()));
|
||||||
#endif // ENABLE_WEBUI
|
#endif // ENABLE_WEBUI
|
||||||
trayMenu->addAction(QIcon(IMAGE_BWGRAPH), tr("Bandwidth Graph"), _bandwidthGraph, SLOT(showWindow()));
|
trayMenu->addAction(QIcon(IMAGE_BWGRAPH), tr("Bandwidth Graph"), this, SLOT(showBandwidthGraph()));
|
||||||
trayMenu->addAction(QIcon(IMAGE_DHT), tr("Statistics"), this, SLOT(showStatisticsWindow()));
|
trayMenu->addAction(QIcon(IMAGE_DHT), tr("Statistics"), this, SLOT(showStatisticsWindow()));
|
||||||
|
|
||||||
|
|
||||||
@ -585,6 +585,14 @@ void MainWindow::createTrayIcon()
|
|||||||
trayIcon->show();
|
trayIcon->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::showBandwidthGraph()
|
||||||
|
{
|
||||||
|
if(_bandwidthGraph == NULL)
|
||||||
|
_bandwidthGraph = new BandwidthGraph();
|
||||||
|
|
||||||
|
_bandwidthGraph->showWindow();
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::createNotifyIcons()
|
void MainWindow::createNotifyIcons()
|
||||||
{
|
{
|
||||||
/* create notify icons */
|
/* create notify icons */
|
||||||
|
@ -198,6 +198,7 @@ public slots:
|
|||||||
//! Go to a specific part of the control panel.
|
//! Go to a specific part of the control panel.
|
||||||
void setNewPage(int page);
|
void setNewPage(int page);
|
||||||
void setCompactStatusMode(bool compact);
|
void setCompactStatusMode(bool compact);
|
||||||
|
void showBandwidthGraph();
|
||||||
|
|
||||||
void toggleStatusToolTip(bool toggle);
|
void toggleStatusToolTip(bool toggle);
|
||||||
protected:
|
protected:
|
||||||
|
@ -102,8 +102,8 @@ QString RSGraphSource::displayValue(float v) const
|
|||||||
|
|
||||||
void RSGraphSource::getCumulatedValues(std::vector<float>& vals) const
|
void RSGraphSource::getCumulatedValues(std::vector<float>& vals) const
|
||||||
{
|
{
|
||||||
for(std::map<std::string,float>::const_iterator it = _totals.begin();it!=_totals.end();++it)
|
for(std::map<std::string,ZeroInitFloat>::const_iterator it = _totals.begin();it!=_totals.end();++it)
|
||||||
vals.push_back(it->second) ;
|
vals.push_back(it->second.v) ;
|
||||||
}
|
}
|
||||||
void RSGraphSource::getCurrentValues(std::vector<QPointF>& vals) const
|
void RSGraphSource::getCurrentValues(std::vector<QPointF>& vals) const
|
||||||
{
|
{
|
||||||
@ -196,10 +196,15 @@ void RSGraphSource::update()
|
|||||||
|
|
||||||
lst.push_back(std::make_pair(ms,it->second)) ;
|
lst.push_back(std::make_pair(ms,it->second)) ;
|
||||||
|
|
||||||
for(std::list<std::pair<qint64,float> >::iterator it2=lst.begin();it2!=lst.end();)
|
float& total ( _totals[it->first].v );
|
||||||
|
|
||||||
|
total += it->second ;
|
||||||
|
|
||||||
|
for(std::list<std::pair<qint64,float> >::iterator it2=lst.begin();it2!=lst.end();) // This loop should be very fast, since we only remove the first elements, if applicable.
|
||||||
if( ms - (*it2).first > _time_limit_msecs)
|
if( ms - (*it2).first > _time_limit_msecs)
|
||||||
{
|
{
|
||||||
//std::cerr << " removing old value with time " << (*it).first/1000.0f << std::endl;
|
//std::cerr << " removing old value with time " << (*it).first/1000.0f << std::endl;
|
||||||
|
total -= (*it2).second ;
|
||||||
it2 = lst.erase(it2) ;
|
it2 = lst.erase(it2) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -210,33 +215,34 @@ void RSGraphSource::update()
|
|||||||
|
|
||||||
for(std::map<std::string,std::list<std::pair<qint64,float> > >::iterator it=_points.begin();it!=_points.end();)
|
for(std::map<std::string,std::list<std::pair<qint64,float> > >::iterator it=_points.begin();it!=_points.end();)
|
||||||
if(it->second.empty())
|
if(it->second.empty())
|
||||||
{
|
{
|
||||||
std::map<std::string,std::list<std::pair<qint64,float> > >::iterator tmp(it) ;
|
std::map<std::string,std::list<std::pair<qint64,float> > >::iterator tmp(it) ;
|
||||||
++tmp;
|
++tmp;
|
||||||
_points.erase(it) ;
|
_totals.erase(it->first) ;
|
||||||
it=tmp ;
|
_points.erase(it) ;
|
||||||
}
|
it=tmp ;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
++it ;
|
++it ;
|
||||||
|
|
||||||
updateTotals();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
void RSGraphSource::updateTotals()
|
void RSGraphSource::updateTotals()
|
||||||
{
|
{
|
||||||
|
std::cerr << "RsGraphSource::updateTotals() for " << _points.size() << " values" << std::endl;
|
||||||
// now compute totals
|
// now compute totals
|
||||||
|
|
||||||
_totals.clear();
|
_totals.clear();
|
||||||
|
|
||||||
for(std::map<std::string,std::list<std::pair<qint64,float> > >::const_iterator it(_points.begin());it!=_points.end();++it)
|
for(std::map<std::string,std::list<std::pair<qint64,float> > >::const_iterator it(_points.begin());it!=_points.end();++it)
|
||||||
{
|
{
|
||||||
float& f = _totals[it->first] ;
|
float& f = _totals[it->first].v ;
|
||||||
|
|
||||||
f = 0.0f ;
|
|
||||||
for(std::list<std::pair<qint64,float> >::const_iterator it2=it->second.begin();it2!=it->second.end();++it2)
|
for(std::list<std::pair<qint64,float> >::const_iterator it2=it->second.begin();it2!=it->second.end();++it2)
|
||||||
f += (*it2).second ;
|
f += (*it2).second ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void RSGraphSource::reset()
|
void RSGraphSource::reset()
|
||||||
{
|
{
|
||||||
|
@ -43,6 +43,17 @@
|
|||||||
#define RSDHT_COLOR Qt::magenta
|
#define RSDHT_COLOR Qt::magenta
|
||||||
#define ALLDHT_COLOR Qt::yellow
|
#define ALLDHT_COLOR Qt::yellow
|
||||||
|
|
||||||
|
struct ZeroInitFloat
|
||||||
|
{
|
||||||
|
ZeroInitFloat() { v=0; }
|
||||||
|
ZeroInitFloat(float f) { v=f; }
|
||||||
|
|
||||||
|
float operator()() const { return v ; }
|
||||||
|
float& operator()() { return v ; }
|
||||||
|
|
||||||
|
float v ;
|
||||||
|
};
|
||||||
|
|
||||||
// This class provides a source value that the graph can retrieve on demand.
|
// This class provides a source value that the graph can retrieve on demand.
|
||||||
// In order to use your own source, derive from RSGraphSource and overload the value() method.
|
// In order to use your own source, derive from RSGraphSource and overload the value() method.
|
||||||
//
|
//
|
||||||
@ -102,13 +113,15 @@ protected slots:
|
|||||||
protected:
|
protected:
|
||||||
virtual void getValues(std::map<std::string,float>& values) const = 0 ;// overload this in your own class to fill in the values you want to display.
|
virtual void getValues(std::map<std::string,float>& values) const = 0 ;// overload this in your own class to fill in the values you want to display.
|
||||||
|
|
||||||
|
#ifdef TO_REMOVE
|
||||||
void updateTotals();
|
void updateTotals();
|
||||||
|
#endif
|
||||||
qint64 getTime() const ; // returns time in ms since RS has started
|
qint64 getTime() const ; // returns time in ms since RS has started
|
||||||
|
|
||||||
// Storage of collected events. The string is any string used to represent the collected data.
|
// Storage of collected events. The string is any string used to represent the collected data.
|
||||||
|
|
||||||
std::map<std::string, std::list<std::pair<qint64,float> > > _points ;
|
std::map<std::string, std::list<std::pair<qint64,float> > > _points ;
|
||||||
std::map<std::string, float> _totals ;
|
std::map<std::string, ZeroInitFloat> _totals ;
|
||||||
|
|
||||||
QTimer *_timer ;
|
QTimer *_timer ;
|
||||||
|
|
||||||
|
@ -88,12 +88,17 @@ void BWGraphSource::update()
|
|||||||
|
|
||||||
lst.push_back(std::make_pair(ms,it->second)) ;
|
lst.push_back(std::make_pair(ms,it->second)) ;
|
||||||
|
|
||||||
|
float& total(_totals[it->first].v) ;
|
||||||
|
|
||||||
|
total += it->second ;
|
||||||
|
|
||||||
unused_vals.erase(it->first) ;
|
unused_vals.erase(it->first) ;
|
||||||
|
|
||||||
for(std::list<std::pair<qint64,float> >::iterator it2=lst.begin();it2!=lst.end();)
|
for(std::list<std::pair<qint64,float> >::iterator it2=lst.begin();it2!=lst.end();)
|
||||||
if( ms - (*it2).first > _time_limit_msecs)
|
if( ms - (*it2).first > _time_limit_msecs)
|
||||||
{
|
{
|
||||||
//std::cerr << " removing old value with time " << (*it).first/1000.0f << std::endl;
|
//std::cerr << " removing old value with time " << (*it).first/1000.0f << std::endl;
|
||||||
|
total -=(*it2).second ;
|
||||||
it2 = lst.erase(it2) ;
|
it2 = lst.erase(it2) ;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -114,6 +119,7 @@ void BWGraphSource::update()
|
|||||||
{
|
{
|
||||||
std::map<std::string,std::list<std::pair<qint64,float> > >::iterator tmp(it) ;
|
std::map<std::string,std::list<std::pair<qint64,float> > >::iterator tmp(it) ;
|
||||||
++tmp;
|
++tmp;
|
||||||
|
_totals.erase(it->first) ;
|
||||||
_points.erase(it) ;
|
_points.erase(it) ;
|
||||||
it=tmp ;
|
it=tmp ;
|
||||||
}
|
}
|
||||||
@ -147,19 +153,31 @@ void BWGraphSource::update()
|
|||||||
break ;
|
break ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_total_duration_seconds = duration/1000.0 ;
|
||||||
|
|
||||||
// now update the totals, and possibly convert into an average if the unit requires it.
|
// now update the totals, and possibly convert into an average if the unit requires it.
|
||||||
|
|
||||||
updateTotals();
|
// updateTotals();
|
||||||
|
|
||||||
if(_current_unit == UNIT_KILOBYTES)
|
// if(_current_unit == UNIT_KILOBYTES)
|
||||||
for(std::map<std::string,float>::iterator it(_totals.begin());it!=_totals.end();++it)
|
// for(std::map<std::string,ZeroInitFloat>::iterator it(_totals.begin());it!=_totals.end();++it)
|
||||||
it->second /= (duration/1000.0) ;
|
// it->second.v /= (duration/1000.0) ;
|
||||||
|
|
||||||
#ifdef BWGRAPH_DEBUG
|
#ifdef BWGRAPH_DEBUG
|
||||||
std::cerr << "Traffic history has size " << mTrafficHistory.size() << std::endl;
|
std::cerr << "Traffic history has size " << mTrafficHistory.size() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BWGraphSource::getCumulatedValues(std::vector<float>& vals) const
|
||||||
|
{
|
||||||
|
if(_current_unit == UNIT_KILOBYTES && _total_duration_seconds > 0.0)
|
||||||
|
for(std::map<std::string,ZeroInitFloat>::const_iterator it = _totals.begin();it!=_totals.end();++it)
|
||||||
|
vals.push_back(it->second.v/_total_duration_seconds) ;
|
||||||
|
else
|
||||||
|
for(std::map<std::string,ZeroInitFloat>::const_iterator it = _totals.begin();it!=_totals.end();++it)
|
||||||
|
vals.push_back(it->second.v) ;
|
||||||
|
}
|
||||||
|
|
||||||
std::string BWGraphSource::makeSubItemName(uint16_t service_id,uint8_t sub_item_type) const
|
std::string BWGraphSource::makeSubItemName(uint16_t service_id,uint8_t sub_item_type) const
|
||||||
{
|
{
|
||||||
RsServiceInfoWithNames& s(mServiceInfoMap[service_id]) ;
|
RsServiceInfoWithNames& s(mServiceInfoMap[service_id]) ;
|
||||||
|
@ -32,6 +32,7 @@ public:
|
|||||||
|
|
||||||
// re-derived from RSGraphSource
|
// re-derived from RSGraphSource
|
||||||
|
|
||||||
|
virtual void getCumulatedValues(std::vector<float>& vals) const;
|
||||||
virtual void getValues(std::map<std::string,float>& values) const;
|
virtual void getValues(std::map<std::string,float>& values) const;
|
||||||
virtual QString displayValue(float v) const;
|
virtual QString displayValue(float v) const;
|
||||||
virtual QString legend(int i,float v,bool show_value=true) const;
|
virtual QString legend(int i,float v,bool show_value=true) const;
|
||||||
@ -67,6 +68,8 @@ private:
|
|||||||
int _friend_graph_type ;
|
int _friend_graph_type ;
|
||||||
int _service_graph_type ;
|
int _service_graph_type ;
|
||||||
|
|
||||||
|
float _total_duration_seconds ;
|
||||||
|
|
||||||
RsPeerId _current_selected_friend ;
|
RsPeerId _current_selected_friend ;
|
||||||
uint16_t _current_selected_service ;
|
uint16_t _current_selected_service ;
|
||||||
int _current_unit ;
|
int _current_unit ;
|
||||||
|
Loading…
Reference in New Issue
Block a user