From fdd23fc629e9161c6552f7e95af0eec9a8ce02b8 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 27 Mar 2011 20:58:43 +0000 Subject: [PATCH] introduce a lower pass download/upload rate and report in session log --- include/libtorrent/stat.hpp | 36 ++++++++++++++++++++++++++++++++---- parse_session_stats.py | 2 +- src/session_impl.cpp | 11 ++++++++--- src/stat.cpp | 3 ++- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/include/libtorrent/stat.hpp b/include/libtorrent/stat.hpp index b2ee28ae0..4a7a849dd 100644 --- a/include/libtorrent/stat.hpp +++ b/include/libtorrent/stat.hpp @@ -55,7 +55,8 @@ namespace libtorrent stat_channel() : m_counter(0) - , m_average(0) + , m_5_sec_average(0) + , m_30_sec_average(0) , m_total_counter(0) {} @@ -82,7 +83,8 @@ namespace libtorrent // should be called once every second void second_tick(int tick_interval_ms); - int rate() const { return m_average; } + int rate() const { return m_5_sec_average; } + int low_pass_rate() const { return m_30_sec_average; } size_type total() const { return m_total_counter; } void offset(size_type c) @@ -98,7 +100,8 @@ namespace libtorrent void clear() { m_counter = 0; - m_average = 0; + m_5_sec_average = 0; + m_30_sec_average = 0; m_total_counter = 0; } @@ -108,7 +111,8 @@ namespace libtorrent int m_counter; // sliding average - int m_average; + int m_5_sec_average; + int m_30_sec_average; // total counters size_type m_total_counter; @@ -231,6 +235,30 @@ namespace libtorrent m_stat[i].second_tick(tick_interval_ms); } + int low_pass_upload_rate() const + { + return m_stat[upload_payload].low_pass_rate() + + m_stat[upload_protocol].low_pass_rate() +#ifndef TORRENT_DISABLE_FULL_STATS + + m_stat[upload_ip_protocol].low_pass_rate() + + m_stat[upload_dht_protocol].low_pass_rate() + + m_stat[upload_tracker_protocol].low_pass_rate() +#endif + ; + } + + int low_pass_download_rate() const + { + return m_stat[download_payload].low_pass_rate() + + m_stat[download_protocol].low_pass_rate() +#ifndef TORRENT_DISABLE_FULL_STATS + + m_stat[download_ip_protocol].low_pass_rate() + + m_stat[download_dht_protocol].low_pass_rate() + + m_stat[download_tracker_protocol].low_pass_rate() +#endif + ; + } + int upload_rate() const { return m_stat[upload_payload].rate() diff --git a/parse_session_stats.py b/parse_session_stats.py index 1bcd17651..e877f7251 100755 --- a/parse_session_stats.py +++ b/parse_session_stats.py @@ -105,7 +105,7 @@ reports = [ ('torrents', 'num', 'number of torrents in different torrent states', ['downloading torrents', 'seeding torrents', 'checking torrents', 'stopped torrents', 'upload-only torrents', 'error torrents']), ('peers', 'num', 'num connected peers', ['peers', 'connecting peers', 'connection attempts', 'banned peers', 'max connections']), ('peers_list_size', 'num', 'number of known peers (not necessarily connected)', ['num list peers']), - ('overall_rates', 'Bytes / second', 'download and upload rates', ['upload rate', 'download rate', 'smooth upload rate', 'smooth download rate']), + ('overall_rates', 'Bytes / second', 'download and upload rates', ['uploaded bytes', 'downloaded bytes', 'upload rate', 'download rate', 'smooth upload rate', 'smooth download rate']), ('disk_write_queue', 'Bytes', 'bytes queued up by peers, to be written to disk', ['disk write queued bytes', 'disk queue limit', 'disk queue low watermark']), ('peers_upload', 'num', 'number of peers by state wrt. uploading', ['peers up interested', 'peers up unchoked', 'peers up requests', 'peers disk-up', 'peers bw-up', 'max unchoked']), ('peers_download', 'num', 'number of peers by state wrt. downloading', ['peers down interesting', 'peers down unchoked', 'peers down requests', 'peers disk-down', 'peers bw-down']), diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 20931a379..087ac7fa7 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -906,12 +906,12 @@ namespace aux { } m_last_log_rotation = time_now(); - fputs("second:upload rate:download rate:downloading torrents:seeding torrents" + fputs("second:uploaded bytes:downloaded bytes:downloading torrents:seeding torrents" ":peers:connecting peers:disk block buffers:num list peers" ":peer allocations:peer storage bytes" ":checking torrents:stopped torrents:upload-only torrents" ":peers bw-up:peers bw-down:peers disk-up:peers disk-down" - ":smooth upload rate:smooth download rate:disk write queued bytes" + ":upload rate:download rate:disk write queued bytes" ":peers down 0:peers down 0-2:peers down 2-5:peers down 5-10:peers down 10-50" ":peers down 50-100:peers down 100-" ":peers up 0:peers up 0-2:peers up 2-5:peers up 5-10:peers up 10-50:peers up 50-100" @@ -972,6 +972,8 @@ namespace aux { ":tick residual" ":max unchoked" ":read job queue size limit" + ":smooth upload rate" + ":smooth download rate" "\n\n", m_stats_logger); } #endif @@ -2933,7 +2935,8 @@ namespace aux { "%f\t%f\t%f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t" "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t" "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%f\t%f\t" - "%f\t%f\t%d\t%f\t%d\t%d\t%d\t%d\t%d\n" + "%f\t%f\t%d\t%f\t%d\t%d\t%d\t%d\t%d\t%d\t" + "%d\n" , total_milliseconds(now - m_last_log_rotation) / 1000.f , int(m_stat.total_upload() - m_last_uploaded) , int(m_stat.total_download() - m_last_downloaded) @@ -3033,6 +3036,8 @@ namespace aux { , m_tick_residual , m_allowed_upload_slots , m_settings.unchoke_slots_limit * 2 + , m_stat.low_pass_upload_rate() + , m_stat.low_pass_download_rate() ); m_last_cache_status = cs; m_last_failed = m_total_failed_bytes; diff --git a/src/stat.cpp b/src/stat.cpp index 7b7222fa3..96e36ade3 100644 --- a/src/stat.cpp +++ b/src/stat.cpp @@ -43,7 +43,8 @@ void stat_channel::second_tick(int tick_interval_ms) { int sample = int(size_type(m_counter) * 1000 / tick_interval_ms); TORRENT_ASSERT(sample >= 0); - m_average = m_average * 4 / 5 + sample / 5; + m_5_sec_average = m_5_sec_average * 4 / 5 + sample / 5; + m_30_sec_average = m_30_sec_average * 29 / 30 + sample / 30; m_counter = 0; }