From: P2P-Next Date: Sat, 14 Aug 2010 11:15:02 +0000 (+0300) Subject: instrumentation/hrktorrent: add time sampling macro; use two-decimal floating point... X-Git-Tag: next-share-m32~9 X-Git-Url: http://p2p-next.cs.pub.ro/gitweb/?a=commitdiff_plain;h=162c2dac004f92091f5869695942f9d9895340c8;p=cs-p2p-next.git instrumentation/hrktorrent: add time sampling macro; use two-decimal floating point printing for upload/download speed --- diff --git a/instrumentation/hrktorrent/core.cpp b/instrumentation/hrktorrent/core.cpp index 3f53046..013dd4d 100644 --- a/instrumentation/hrktorrent/core.cpp +++ b/instrumentation/hrktorrent/core.cpp @@ -62,6 +62,25 @@ PrintStatusStream(std::stringstream &output, int columns, int stdout_is_tty) std::cout.flush(); } +#define SAMPLING_TIME 5 + +static char const* time_now_string() +{ + time_t t = std::time(0); + static char str[200]; + + tm* timeinfo = std::localtime(&t); + std::strftime(str, 200, "%b %d %X", timeinfo); + return str; +} + +static time_t time_now_seconds() +{ + time_t t = std::time(0); + + return t; +} + void* CCore::StatusLoop(void* data) { @@ -121,8 +140,8 @@ CCore::StatusLoop(void* data) if(Settings->GetI("dht") > 0) output << ", dht: " << sstatus.dht_nodes; output << " <> "; - output << "dl: " << Round(sstatus.download_rate/1024, 2) << "kb/s, "; - output << "ul: " << Round(sstatus.upload_rate/1024, 2) << "kb/s <> "; + output << "dl: " << Round(sstatus.download_rate/1024.0, 2) << "kb/s, "; + output << "ul: " << Round(sstatus.upload_rate/1024.0, 2) << "kb/s <> "; output << "dld: " << tstatus.total_done/1048576 << "mb, "; output << "uld: " << sstatus.total_payload_upload/1048576 << "mb, "; output << "size: " << tstatus.total_wanted/1048576 << "mb <> "; @@ -144,16 +163,23 @@ CCore::StatusLoop(void* data) PrintStatusStream(output, columns, stdout_is_tty); output.str(""); - output << "--Peers: "; + /* print peer information each SAMPLING_TIME seconds */ + loopcount++; + if (time_now_seconds() % SAMPLING_TIME != 0) { + sleep(1); + continue; + } /* build peer status message */ + output << "--Peers: (" << time_now_string() << ") "; + t->get_peer_info(peers); std::vector::iterator it = peers.begin(); while (it != peers.end()) { output << "[ ip: " << it->ip; - output << ", dl: " << Round(it->down_speed/1024, 2); - output << ", ul: " << Round(it->up_speed/1024, 2); + output << ", dl: " << Round(it->down_speed/1024.0, 2) << "kb/s"; + output << ", ul: " << Round(it->up_speed/1024.0, 2) << "kb/s"; output << " ]"; it++; } @@ -162,7 +188,6 @@ CCore::StatusLoop(void* data) output.str(""); sleep(1); - loopcount++; } return 0;