mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-18 20:34:26 -05:00
fixed bugs in upload speed computation
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1007 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
6ac5d40df9
commit
bb904ea8e8
@ -5,9 +5,9 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
ftFileProvider::ftFileProvider(std::string path, uint64_t size, std::string
|
||||
hash) : mSize(size), hash(hash), file_name(path), fd(NULL),transfer_rate(0)
|
||||
hash) : mSize(size), hash(hash), file_name(path), fd(NULL),transfer_rate(0),total_size(0)
|
||||
{
|
||||
lastTS = times(NULL) ;
|
||||
lastTS = time(NULL) ;
|
||||
}
|
||||
|
||||
ftFileProvider::~ftFileProvider(){
|
||||
@ -48,14 +48,31 @@ bool ftFileProvider::FileDetails(FileInfo &info)
|
||||
info.path = file_name;
|
||||
info.fname = RsDirUtil::getTopDir(file_name);
|
||||
info.transfered = req_loc ;
|
||||
info.lastTS = lastTS;
|
||||
info.status = FT_STATE_DOWNLOADING ;
|
||||
|
||||
info.peers.clear() ;
|
||||
|
||||
TransferInfo inf ;
|
||||
inf.peerId = lastRequestor ;
|
||||
inf.tfRate = transfer_rate/1024.0 ;
|
||||
inf.status = FT_STATE_DOWNLOADING ;
|
||||
|
||||
long int clk = sysconf(_SC_CLK_TCK) ;
|
||||
time_t now = time(NULL) ;
|
||||
|
||||
clock_t now_t = times(NULL) ;
|
||||
|
||||
long int diff = (long int)now_t - (long int)lastTS_t ; // in bytes/s. Average over multiple samples
|
||||
|
||||
if(diff > 100)
|
||||
{
|
||||
transfer_rate = total_size / (float)diff * clk ;
|
||||
total_size = 0 ;
|
||||
lastTS_t = now_t ;
|
||||
}
|
||||
|
||||
inf.tfRate = transfer_rate/1024.0 ;
|
||||
info.tfRate = transfer_rate/1024.0 ;
|
||||
info.peers.push_back(inf) ;
|
||||
|
||||
/* Use req_loc / req_size to estimate data rate */
|
||||
@ -123,15 +140,11 @@ bool ftFileProvider::getFileData(uint64_t offset, uint32_t &chunk_size, void *da
|
||||
* (d) timestamp
|
||||
*/
|
||||
|
||||
clock_t now = times(NULL);
|
||||
time_t now = time(NULL);
|
||||
req_loc = offset;
|
||||
lastTS = now ;
|
||||
req_size = data_size;
|
||||
|
||||
transfer_rate = req_size / (float)(std::max(sysconf(_SC_CLK_TCK),(long int)now - (long int)lastTS) / (float)sysconf(_SC_CLK_TCK)) ; // in bytes/s. Average over two samples
|
||||
|
||||
std::cout << "req_size = " << req_size << ", now="<< now << ", lastTS=" << lastTS << ", lastTS-now=" << now-lastTS << ", speed = " << transfer_rate << ", clk=" << sysconf(_SC_CLK_TCK) << std::endl ;
|
||||
|
||||
lastTS = now;
|
||||
total_size += req_size ;
|
||||
}
|
||||
else {
|
||||
std::cerr << "No data to read" << std::endl;
|
||||
|
@ -65,8 +65,12 @@ virtual int initializeFileAttrs(); /* does for both */
|
||||
std::string lastRequestor;
|
||||
uint64_t req_loc;
|
||||
uint32_t req_size;
|
||||
clock_t lastTS;
|
||||
time_t lastTS;
|
||||
clock_t lastTS_t;
|
||||
|
||||
// these two are used for speed estimation
|
||||
float transfer_rate ;
|
||||
uint32_t total_size ;
|
||||
|
||||
/*
|
||||
* Mutex Required for stuff below
|
||||
|
Loading…
Reference in New Issue
Block a user