diff options
author | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-06-28 01:10:42 +0300 |
---|---|---|
committer | Kostyantyn Ovechko <fastinetserver@gmail.com> | 2010-06-28 01:10:42 +0300 |
commit | 34128412ede0122fe448394962dc9eddd6834320 (patch) | |
tree | d37cce4a3b75873daa20f370f70d7cf2ea0269ae | |
parent | Failprove segget.cpp and log errors to error.log (diff) | |
download | idfetch-34128412ede0122fe448394962dc9eddd6834320.tar.gz idfetch-34128412ede0122fe448394962dc9eddd6834320.tar.bz2 idfetch-34128412ede0122fe448394962dc9eddd6834320.zip |
Make time measurement more precise - in milliseconds
-rw-r--r-- | segget/segment.cpp | 17 | ||||
-rw-r--r-- | segget/stats.cpp | 17 |
2 files changed, 23 insertions, 11 deletions
diff --git a/segget/segment.cpp b/segget/segment.cpp index 2b21bd2..74e8d26 100644 --- a/segget/segment.cpp +++ b/segget/segment.cpp @@ -166,7 +166,7 @@ int Tsegment::add_easy_handle_to_multi(CURLM *cm){ return 1; } } -void show_progress(ulong time_diff){ +void show_progress(double time_diff){ try{ stats.total_bytes_per_last_interval=0; for (uint con_num=0; con_num<MAX_CONNECTS; con_num++){ @@ -177,7 +177,7 @@ void show_progress(ulong time_diff){ stats.total_bytes_per_last_interval+=connection_array[con_num].get_bytes_per_last_interval(); msg_segment_progress(con_num,segment->segment_num, segment->try_num, segment->downloaded_bytes,segment->segment_size, - (connection_array[con_num].get_bytes_per_last_interval())/time_diff); + (connection_array[con_num].get_bytes_per_last_interval()*1000)/time_diff); connection_array[con_num].reset_bytes_per_last_interval(); } } @@ -204,16 +204,17 @@ size_t write_data(void *buffer, size_t size, size_t nmemb, void *cur_segment){ } connection_array[segment->connection_num].inc_bytes_per_last_interval(bytes_written); - time_t now_time; - now_time = time((time_t *)NULL); + timeval now_time; + gettimeofday(&now_time,NULL); // ulong diff_sec = difftime(now_time.tv_sec, prev_time.tv_sec) * 1000000; // ulong diff_milli = difftime(now_time.tv_usec, prev_time.tv_usec) + diff_sec; - ulong time_diff=now_time-prev_time; + + double time_diff_msecs=(now_time.tv_sec-stats.previous_time.tv_sec)*1000+(now_time.tv_usec-stats.previous_time.tv_usec)/1000; // debug(segment->file_name+"==="+toString((ulong)now_time)+"=="+toString(now_time)); - if (time_diff >= 1){ + if (time_diff_msecs >= 500){ // debug(segment->file_name+"--->"+toString((ulong)())); - show_progress(time_diff); - prev_time=now_time; + show_progress(time_diff_msecs); + stats.previous_time=now_time; }; // else // debug(segment->file_name+"==="+toString(prev_time.tv_sec)+"=="+toString(prev_time.tv_usec)+"==="+toString((ulong)(diff_milli))); diff --git a/segget/stats.cpp b/segget/stats.cpp index bf201cb..d8f06f6 100644 --- a/segget/stats.cpp +++ b/segget/stats.cpp @@ -3,6 +3,8 @@ #include "connection.cpp" #include "tui.h" +#include <sys/time.h> +using namespace std; class Tstats{ private: @@ -11,7 +13,8 @@ class Tstats{ uint total_size; public: ulong total_bytes_per_last_interval; - ulong last_time_interval; + struct timeval previous_time; + double last_time_interval; uint pkg_count; uint distfiles_count; Tstats(): @@ -19,6 +22,7 @@ class Tstats{ dld_distfiles_count(0), total_size(0), total_bytes_per_last_interval(0), + previous_time(), last_time_interval(1), pkg_count(0), distfiles_count(0) @@ -40,6 +44,10 @@ void Tstats::show_totals(){ show_last_time_interval=last_time_interval; if (total_size>1) show_total_size=total_size; + + struct timeval now_timee; + gettimeofday(&now_timee,NULL); + msg_total("Total" +field(" PKGs:", pkg_count,4) +field(" = DFs:", dld_distfiles_count,4) @@ -47,8 +55,11 @@ void Tstats::show_totals(){ +field(" = Size:", dld_size/1000,7) +field(" / ", total_size/1000,7)+" Kb " +field(" = ", dld_size*100/(1+show_total_size),3)+"%%" - +field(" Total speed: ", (total_bytes_per_last_interval/1000/(show_last_time_interval)),7) - +" Kb/s"); + +field(" Total speed: ", (total_bytes_per_last_interval/(show_last_time_interval)),7) + +" Kb/s" +// +" Secs:"+toString(now_timee.tv_sec) +// +" usecs:"+toString(now_timee.tv_usec) + ); } catch(...) { |