mirror of https://github.com/aria2/aria2
2010-06-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Renamed member variables * src/SpeedCalc.cc * src/SpeedCalc.hpull/1/head
parent
8d6378b675
commit
8b5bb34a26
|
@ -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>
|
2010-06-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Renamed member variables in SegmentMan
|
Renamed member variables in SegmentMan
|
||||||
|
|
|
@ -43,41 +43,42 @@ namespace aria2 {
|
||||||
|
|
||||||
#define CHANGE_INTERVAL_SEC 15
|
#define CHANGE_INTERVAL_SEC 15
|
||||||
|
|
||||||
SpeedCalc::SpeedCalc():sw(0), maxSpeed(0), prevSpeed(0), accumulatedLength(0),
|
SpeedCalc::SpeedCalc():_sw(0), _maxSpeed(0), _prevSpeed(0),
|
||||||
nextInterval(CHANGE_INTERVAL_SEC)
|
_accumulatedLength(0),
|
||||||
|
_nextInterval(CHANGE_INTERVAL_SEC)
|
||||||
{
|
{
|
||||||
std::fill(&lengthArray[0], &lengthArray[2], 0);
|
std::fill(&_lengthArray[0], &_lengthArray[2], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpeedCalc::reset() {
|
void SpeedCalc::reset() {
|
||||||
std::fill(&lengthArray[0], &lengthArray[2], 0);
|
std::fill(&_lengthArray[0], &_lengthArray[2], 0);
|
||||||
std::fill(&cpArray[0], &cpArray[2], global::wallclock);
|
std::fill(&_cpArray[0], &_cpArray[2], global::wallclock);
|
||||||
sw = 0;
|
_sw = 0;
|
||||||
maxSpeed = 0;
|
_maxSpeed = 0;
|
||||||
prevSpeed = 0;
|
_prevSpeed = 0;
|
||||||
start = global::wallclock;
|
_start = global::wallclock;
|
||||||
accumulatedLength = 0;
|
_accumulatedLength = 0;
|
||||||
nextInterval = CHANGE_INTERVAL_SEC;
|
_nextInterval = CHANGE_INTERVAL_SEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int SpeedCalc::calculateSpeed() {
|
unsigned int SpeedCalc::calculateSpeed() {
|
||||||
int64_t milliElapsed = cpArray[sw].differenceInMillis(global::wallclock);
|
int64_t milliElapsed = _cpArray[_sw].differenceInMillis(global::wallclock);
|
||||||
if(milliElapsed) {
|
if(milliElapsed) {
|
||||||
unsigned int speed = lengthArray[sw]*1000/milliElapsed;
|
unsigned int speed = _lengthArray[_sw]*1000/milliElapsed;
|
||||||
prevSpeed = speed;
|
_prevSpeed = speed;
|
||||||
maxSpeed = std::max(speed, maxSpeed);
|
_maxSpeed = std::max(speed, _maxSpeed);
|
||||||
if(isIntervalOver(milliElapsed)) {
|
if(isIntervalOver(milliElapsed)) {
|
||||||
changeSw();
|
changeSw();
|
||||||
}
|
}
|
||||||
return speed;
|
return speed;
|
||||||
} else {
|
} else {
|
||||||
return prevSpeed;
|
return _prevSpeed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpeedCalc::update(size_t bytes) {
|
void SpeedCalc::update(size_t bytes) {
|
||||||
accumulatedLength += bytes;
|
_accumulatedLength += bytes;
|
||||||
std::transform(&lengthArray[0], &lengthArray[2], &lengthArray[0],
|
std::transform(&_lengthArray[0], &_lengthArray[2], &_lengthArray[0],
|
||||||
std::bind1st(std::plus<uint64_t>(), (uint64_t)bytes));
|
std::bind1st(std::plus<uint64_t>(), (uint64_t)bytes));
|
||||||
if(isIntervalOver()) {
|
if(isIntervalOver()) {
|
||||||
changeSw();
|
changeSw();
|
||||||
|
@ -85,27 +86,28 @@ void SpeedCalc::update(size_t bytes) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpeedCalc::isIntervalOver() const {
|
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
|
bool SpeedCalc::isIntervalOver(int64_t milliElapsed) const
|
||||||
{
|
{
|
||||||
return nextInterval <= milliElapsed/1000;
|
return _nextInterval <= milliElapsed/1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SpeedCalc::changeSw() {
|
void SpeedCalc::changeSw() {
|
||||||
lengthArray[sw] = 0;
|
_lengthArray[_sw] = 0;
|
||||||
cpArray[sw] = global::wallclock;
|
_cpArray[_sw] = global::wallclock;
|
||||||
sw ^= 0x01;
|
_sw ^= 0x01;
|
||||||
nextInterval = cpArray[sw].difference(global::wallclock)+CHANGE_INTERVAL_SEC;
|
_nextInterval =
|
||||||
|
_cpArray[_sw].difference(global::wallclock)+CHANGE_INTERVAL_SEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int SpeedCalc::calculateAvgSpeed() const {
|
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 is too small, the average speed is rubish, better return 0
|
||||||
if(milliElapsed > 4) {
|
if(milliElapsed > 4) {
|
||||||
unsigned int speed = accumulatedLength*1000/milliElapsed;
|
unsigned int speed = _accumulatedLength*1000/milliElapsed;
|
||||||
return speed;
|
return speed;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -42,14 +42,14 @@ namespace aria2 {
|
||||||
|
|
||||||
class SpeedCalc {
|
class SpeedCalc {
|
||||||
private:
|
private:
|
||||||
uint64_t lengthArray[2];
|
uint64_t _lengthArray[2];
|
||||||
int sw;
|
int _sw;
|
||||||
Timer cpArray[2];
|
Timer _cpArray[2];
|
||||||
unsigned int maxSpeed;
|
unsigned int _maxSpeed;
|
||||||
unsigned int prevSpeed;
|
unsigned int _prevSpeed;
|
||||||
Timer start;
|
Timer _start;
|
||||||
uint64_t accumulatedLength;
|
uint64_t _accumulatedLength;
|
||||||
time_t nextInterval;
|
time_t _nextInterval;
|
||||||
|
|
||||||
bool isIntervalOver() const;
|
bool isIntervalOver() const;
|
||||||
|
|
||||||
|
@ -65,7 +65,7 @@ public:
|
||||||
unsigned int calculateSpeed();
|
unsigned int calculateSpeed();
|
||||||
|
|
||||||
unsigned int getMaxSpeed() const {
|
unsigned int getMaxSpeed() const {
|
||||||
return maxSpeed;
|
return _maxSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int calculateAvgSpeed() const;
|
unsigned int calculateAvgSpeed() const;
|
||||||
|
|
Loading…
Reference in New Issue