diff --git a/Jamfile b/Jamfile index cac684d55..ff2c0a3ca 100755 --- a/Jamfile +++ b/Jamfile @@ -230,6 +230,9 @@ feature.compose off : TORRENT_USE_IPV6=0 ; feature need-librt : no yes : composite propagated link-incompatible ; +feature full-stats : on off : composite propagated link-incompatible ; +feature.compose off : TORRENT_DISABLE_FULL_STATS ; + feature pool-allocators : on off : composite propagated link-incompatible ; feature.compose off : TORRENT_DISABLE_POOL_ALLOCATOR ; diff --git a/docs/building.rst b/docs/building.rst index 4aed76c87..15ba365fb 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -354,6 +354,12 @@ Build features: | | API. Generates build errors when deprecated | | | functions are used. | +--------------------------+----------------------------------------------------+ +| ``full-stats`` | * ``on`` - default, collects stats for IP overhead | +| | and DHT and trackers. This uses a little bit | +| | extra memory for each peer and torrent. | +| | * ``off`` - only collects the standard stats for | +| | upload and download rate. | ++--------------------------+----------------------------------------------------+ .. _MaxMind: http://www.maxmind.com/app/api diff --git a/docs/tuning.rst b/docs/tuning.rst index 738a99387..d435e7003 100644 --- a/docs/tuning.rst +++ b/docs/tuning.rst @@ -168,6 +168,15 @@ support, you need to patch parts of boost. Also make sure to optimize for size when compiling. +reduce statistics +----------------- + +You can save some memory for each connection and each torrent by reducing the +number of separate rates kept track of by libtorrent. If you build with ``full-stats=off`` +(or ``-DTORRENT_DISABLE_FULL_STATS``) you will save a few hundred bytes for each +connection and torrent. It might make a difference if you have a very large number +of peers or torrents. + play nice with the disk ======================= diff --git a/include/libtorrent/alert_types.hpp b/include/libtorrent/alert_types.hpp index 2ecbe4fa5..5b4e08ff4 100644 --- a/include/libtorrent/alert_types.hpp +++ b/include/libtorrent/alert_types.hpp @@ -1112,14 +1112,16 @@ namespace libtorrent { upload_payload, upload_protocol, + download_payload, + download_protocol, +#ifndef TORRENT_DISABLE_FULL_STATS upload_ip_protocol, upload_dht_protocol, upload_tracker_protocol, - download_payload, - download_protocol, download_ip_protocol, download_dht_protocol, download_tracker_protocol, +#endif num_channels }; diff --git a/include/libtorrent/stat.hpp b/include/libtorrent/stat.hpp index 094458f4e..d839d9392 100644 --- a/include/libtorrent/stat.hpp +++ b/include/libtorrent/stat.hpp @@ -172,38 +172,50 @@ namespace libtorrent void sent_syn(bool ipv6) { +#ifndef TORRENT_DISABLE_FULL_STATS m_stat[upload_ip_protocol].add(ipv6 ? 60 : 40); +#endif } void received_synack(bool ipv6) { +#ifndef TORRENT_DISABLE_FULL_STATS // we received SYN-ACK and also sent ACK back m_stat[download_ip_protocol].add(ipv6 ? 60 : 40); m_stat[upload_ip_protocol].add(ipv6 ? 60 : 40); +#endif } void received_dht_bytes(int bytes) { +#ifndef TORRENT_DISABLE_FULL_STATS TORRENT_ASSERT(bytes >= 0); m_stat[download_dht_protocol].add(bytes); +#endif } void sent_dht_bytes(int bytes) { +#ifndef TORRENT_DISABLE_FULL_STATS TORRENT_ASSERT(bytes >= 0); m_stat[upload_dht_protocol].add(bytes); +#endif } void received_tracker_bytes(int bytes) { +#ifndef TORRENT_DISABLE_FULL_STATS TORRENT_ASSERT(bytes >= 0); m_stat[download_tracker_protocol].add(bytes); +#endif } void sent_tracker_bytes(int bytes) { +#ifndef TORRENT_DISABLE_FULL_STATS TORRENT_ASSERT(bytes >= 0); m_stat[upload_tracker_protocol].add(bytes); +#endif } void received_bytes(int bytes_payload, int bytes_protocol) @@ -228,6 +240,7 @@ namespace libtorrent // account for the overhead caused by it void trancieve_ip_packet(int bytes_transferred, bool ipv6) { +#ifndef TORRENT_DISABLE_FULL_STATS // one TCP/IP packet header for the packet // sent or received, and one for the ACK // The IPv4 header is 20 bytes @@ -238,14 +251,24 @@ namespace libtorrent const int overhead = (std::max)(1, (bytes_transferred + packet_size - 1) / packet_size) * header; m_stat[download_ip_protocol].add(overhead); m_stat[upload_ip_protocol].add(overhead); +#endif } +#ifndef TORRENT_DISABLE_FULL_STATS int upload_ip_overhead() const { return m_stat[upload_ip_protocol].counter(); } int download_ip_overhead() const { return m_stat[download_ip_protocol].counter(); } int upload_dht() const { return m_stat[upload_dht_protocol].counter(); } int download_dht() const { return m_stat[download_dht_protocol].counter(); } int download_tracker() const { return m_stat[download_tracker_protocol].counter(); } int upload_tracker() const { return m_stat[upload_tracker_protocol].counter(); } +#else + int upload_ip_overhead() const { return 0; } + int download_ip_overhead() const { return 0; } + int upload_dht() const { return 0; } + int download_dht() const { return 0; } + int download_tracker() const { return 0; } + int upload_tracker() const { return 0; } +#endif void set_window(int w) { @@ -264,8 +287,11 @@ namespace libtorrent { return int((m_stat[upload_payload].rate_sum() + m_stat[upload_protocol].rate_sum() +#ifndef TORRENT_DISABLE_FULL_STATS + m_stat[upload_ip_protocol].rate_sum() - + m_stat[upload_dht_protocol].rate_sum()) + + m_stat[upload_dht_protocol].rate_sum() +#endif + ) / m_stat[0].window()); } @@ -273,8 +299,11 @@ namespace libtorrent { return int((m_stat[download_payload].rate_sum() + m_stat[download_protocol].rate_sum() +#ifndef TORRENT_DISABLE_FULL_STATS + m_stat[download_ip_protocol].rate_sum() - + m_stat[download_dht_protocol].rate_sum()) + + m_stat[download_dht_protocol].rate_sum() +#endif + ) / m_stat[0].window()); } @@ -282,18 +311,24 @@ namespace libtorrent { return m_stat[upload_payload].total() + m_stat[upload_protocol].total() +#ifndef TORRENT_DISABLE_FULL_STATS + m_stat[upload_ip_protocol].total() + m_stat[upload_dht_protocol].total() - + m_stat[upload_tracker_protocol].total(); + + m_stat[upload_tracker_protocol].total() +#endif + ; } size_type total_download() const { return m_stat[download_payload].total() + m_stat[download_protocol].total() +#ifndef TORRENT_DISABLE_FULL_STATS + m_stat[download_ip_protocol].total() + m_stat[download_dht_protocol].total() - + m_stat[download_tracker_protocol].total(); + + m_stat[download_tracker_protocol].total() +#endif + ; } int upload_payload_rate() const @@ -339,14 +374,16 @@ namespace libtorrent { upload_payload, upload_protocol, + download_payload, + download_protocol, +#ifndef TORRENT_DISABLE_FULL_STATS upload_ip_protocol, upload_dht_protocol, upload_tracker_protocol, - download_payload, - download_protocol, download_ip_protocol, download_dht_protocol, download_tracker_protocol, +#endif num_channels }; diff --git a/src/session_impl.cpp b/src/session_impl.cpp index f9f6ef628..6af04f258 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -2987,6 +2987,7 @@ namespace aux { s.payload_upload_rate = m_stat.transfer_rate(stat::upload_payload); s.total_payload_upload = m_stat.total_transfer(stat::upload_payload); +#ifndef TORRENT_DISABLE_FULL_STATS // IP-overhead s.ip_overhead_download_rate = m_stat.transfer_rate(stat::download_ip_protocol); s.total_ip_overhead_download = m_stat.total_transfer(stat::download_ip_protocol); @@ -3004,6 +3005,25 @@ namespace aux { s.total_tracker_download = m_stat.total_transfer(stat::download_tracker_protocol); s.tracker_upload_rate = m_stat.transfer_rate(stat::upload_tracker_protocol); s.total_tracker_upload = m_stat.total_transfer(stat::upload_tracker_protocol); +#else + // IP-overhead + s.ip_overhead_download_rate = 0; + s.total_ip_overhead_download = 0; + s.ip_overhead_upload_rate = 0; + s.total_ip_overhead_upload = 0; + + // DHT protocol + s.dht_download_rate = 0; + s.total_dht_download = 0; + s.dht_upload_rate = 0; + s.total_dht_upload = 0; + + // tracker + s.tracker_download_rate = 0; + s.total_tracker_download = 0; + s.tracker_upload_rate = 0; + s.total_tracker_upload = 0; +#endif #ifndef TORRENT_DISABLE_DHT if (m_dht)