2010-06-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Renamed member variables
	* src/SpeedCalc.cc
	* src/SpeedCalc.h
pull/1/head
Tatsuhiro Tsujikawa 2010-06-12 13:58:09 +00:00
parent 8d6378b675
commit 8b5bb34a26
3 changed files with 43 additions and 35 deletions

View File

@ -1,3 +1,9 @@
2010-06-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Renamed member variables
* src/SpeedCalc.cc
* src/SpeedCalc.h
2010-06-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Renamed member variables in SegmentMan

View File

@ -43,41 +43,42 @@ namespace aria2 {
#define CHANGE_INTERVAL_SEC 15
SpeedCalc::SpeedCalc():sw(0), maxSpeed(0), prevSpeed(0), accumulatedLength(0),
nextInterval(CHANGE_INTERVAL_SEC)
SpeedCalc::SpeedCalc():_sw(0), _maxSpeed(0), _prevSpeed(0),
_accumulatedLength(0),
_nextInterval(CHANGE_INTERVAL_SEC)
{
std::fill(&lengthArray[0], &lengthArray[2], 0);
std::fill(&_lengthArray[0], &_lengthArray[2], 0);
}
void SpeedCalc::reset() {
std::fill(&lengthArray[0], &lengthArray[2], 0);
std::fill(&cpArray[0], &cpArray[2], global::wallclock);
sw = 0;
maxSpeed = 0;
prevSpeed = 0;
start = global::wallclock;
accumulatedLength = 0;
nextInterval = CHANGE_INTERVAL_SEC;
std::fill(&_lengthArray[0], &_lengthArray[2], 0);
std::fill(&_cpArray[0], &_cpArray[2], global::wallclock);
_sw = 0;
_maxSpeed = 0;
_prevSpeed = 0;
_start = global::wallclock;
_accumulatedLength = 0;
_nextInterval = CHANGE_INTERVAL_SEC;
}
unsigned int SpeedCalc::calculateSpeed() {
int64_t milliElapsed = cpArray[sw].differenceInMillis(global::wallclock);
int64_t milliElapsed = _cpArray[_sw].differenceInMillis(global::wallclock);
if(milliElapsed) {
unsigned int speed = lengthArray[sw]*1000/milliElapsed;
prevSpeed = speed;
maxSpeed = std::max(speed, maxSpeed);
unsigned int speed = _lengthArray[_sw]*1000/milliElapsed;
_prevSpeed = speed;
_maxSpeed = std::max(speed, _maxSpeed);
if(isIntervalOver(milliElapsed)) {
changeSw();
}
return speed;
} else {
return prevSpeed;
return _prevSpeed;
}
}
void SpeedCalc::update(size_t bytes) {
accumulatedLength += bytes;
std::transform(&lengthArray[0], &lengthArray[2], &lengthArray[0],
_accumulatedLength += bytes;
std::transform(&_lengthArray[0], &_lengthArray[2], &_lengthArray[0],
std::bind1st(std::plus<uint64_t>(), (uint64_t)bytes));
if(isIntervalOver()) {
changeSw();
@ -85,27 +86,28 @@ void SpeedCalc::update(size_t bytes) {
}
bool SpeedCalc::isIntervalOver() const {
return nextInterval <= cpArray[sw].difference(global::wallclock);
return _nextInterval <= _cpArray[_sw].difference(global::wallclock);
}
bool SpeedCalc::isIntervalOver(int64_t milliElapsed) const
{
return nextInterval <= milliElapsed/1000;
return _nextInterval <= milliElapsed/1000;
}
void SpeedCalc::changeSw() {
lengthArray[sw] = 0;
cpArray[sw] = global::wallclock;
sw ^= 0x01;
nextInterval = cpArray[sw].difference(global::wallclock)+CHANGE_INTERVAL_SEC;
_lengthArray[_sw] = 0;
_cpArray[_sw] = global::wallclock;
_sw ^= 0x01;
_nextInterval =
_cpArray[_sw].difference(global::wallclock)+CHANGE_INTERVAL_SEC;
}
unsigned int SpeedCalc::calculateAvgSpeed() const {
uint64_t milliElapsed = start.differenceInMillis(global::wallclock);
uint64_t milliElapsed = _start.differenceInMillis(global::wallclock);
// if milliElapsed is too small, the average speed is rubish, better return 0
if(milliElapsed > 4) {
unsigned int speed = accumulatedLength*1000/milliElapsed;
unsigned int speed = _accumulatedLength*1000/milliElapsed;
return speed;
} else {
return 0;

View File

@ -42,14 +42,14 @@ namespace aria2 {
class SpeedCalc {
private:
uint64_t lengthArray[2];
int sw;
Timer cpArray[2];
unsigned int maxSpeed;
unsigned int prevSpeed;
Timer start;
uint64_t accumulatedLength;
time_t nextInterval;
uint64_t _lengthArray[2];
int _sw;
Timer _cpArray[2];
unsigned int _maxSpeed;
unsigned int _prevSpeed;
Timer _start;
uint64_t _accumulatedLength;
time_t _nextInterval;
bool isIntervalOver() const;
@ -65,7 +65,7 @@ public:
unsigned int calculateSpeed();
unsigned int getMaxSpeed() const {
return maxSpeed;
return _maxSpeed;
}
unsigned int calculateAvgSpeed() const;