From 8975310adab0f51b12319a196598e80da55296e3 Mon Sep 17 00:00:00 2001 From: Eric Heien Date: Mon, 24 Feb 2003 23:59:46 +0000 Subject: [PATCH] transfer speed measurement svn path=/trunk/boinc/; revision=961 --- client/net_xfer.C | 20 ++++++++++++++++++++ client/net_xfer.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/client/net_xfer.C b/client/net_xfer.C index 562e81212a..51ed3344b9 100644 --- a/client/net_xfer.C +++ b/client/net_xfer.C @@ -20,6 +20,7 @@ #include "windows_cpp.h" #include +#include #ifdef _WIN32 #include @@ -171,6 +172,8 @@ void NET_XFER::init(char* host, int p, int b) { strcpy(hostname, host); port = p; blocksize = b; + xfer_speed = 0; + last_speed_update = 0; } // Insert a NET_XFER object into the set @@ -314,6 +317,7 @@ int NET_XFER_SET::do_select( retval = nxp->do_xfer(n); max_bytes -= n; bytes_transferred += n; + nxp->update_speed(n); } } else { nxp->io_ready = true; @@ -415,6 +419,22 @@ done: return 0; } +// Update the transfer speed for this NET_XFER +// Decay speed by 1/e every second +// +void NET_XFER::update_speed(int nbytes) { + clock_t now,delta_t; + double x; + + now = clock(); + if (last_speed_update==0) last_speed_update = now; + delta_t = now-last_speed_update; + if (delta_t<=0) delta_t = 0; + x = exp(-(double)delta_t/(double)CLOCKS_PER_SEC); + xfer_speed = (x*xfer_speed)+nbytes; + last_speed_update = now; +} + void NET_XFER::got_error() { error = ERR_IO; io_done = true; diff --git a/client/net_xfer.h b/client/net_xfer.h index a835749c8e..076d55999c 100644 --- a/client/net_xfer.h +++ b/client/net_xfer.h @@ -49,12 +49,15 @@ public: char hostname[256]; int port; int blocksize; + double xfer_speed; // in bytes per second + clock_t last_speed_update; void init(char* host, int port, int blocksize); int get_ip_addr(char *hostname, int &ip_addr); int open_server(); void close_socket(); int do_xfer(int&); + void update_speed(int); void got_error(); };