From 90d8030269a0c4f88f291889c45ce95a6c39a7a2 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 28 Jun 2011 22:20:34 +0000 Subject: [PATCH] log VM stats alongside the session stats --- include/libtorrent/aux_/session_impl.hpp | 21 ++++++++++++ parse_session_stats.py | 5 ++- src/session_impl.cpp | 43 +++++++++++++++++++++++- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 26960e630..91083022a 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -94,6 +94,13 @@ POSSIBILITY OF SUCH DAMAGE. #include #endif +#if TORRENT_STATS && defined __MACH__ +#include +#include +#include +#include +#endif + namespace libtorrent { @@ -116,6 +123,19 @@ namespace libtorrent { struct session_impl; +#if defined TORRENT_STATS && !defined __MACH__ + struct vm_statistics_data_t + { + boost::uint64_t active_count; + boost::uint64_t inactive_count; + boost::uint64_t wire_count; + boost::uint64_t free_count; + boost::uint64_t pageins; + boost::uint64_t pageouts; + boost::uint64_t faults; + }; +#endif + #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING struct tracker_logger; #endif @@ -912,6 +932,7 @@ namespace libtorrent int m_connection_attempts; int m_num_banned_peers; int m_banned_for_hash_failure; + vm_statistics_data_t m_last_vm_stat; #endif // each second tick the timer takes a little diff --git a/parse_session_stats.py b/parse_session_stats.py index 1d990b204..ff60b62d4 100755 --- a/parse_session_stats.py +++ b/parse_session_stats.py @@ -122,7 +122,10 @@ reports = [ ('disk_queue', 'number of queued disk jobs', '', 'queued disk jobs', ['disk queue size', 'disk read queue size', 'read job queue size limit']), ('disk_iops', 'operations/s', '', 'number of disk operations per second', ['read ops/s', 'write ops/s']), ('mixed mode', 'rate', 'B/s', 'rates by transport protocol', ['TCP up rate','TCP down rate','uTP up rate','uTP down rate','TCP up limit','TCP down limit']), - ('uTP delay', 'buffer delay', 's', 'network delays measured by uTP', ['uTP peak send delay','uTP avg send delay']), + ('uTP delay', 'buffering delay', 's', 'network delays measured by uTP', ['uTP peak send delay','uTP avg send delay']), + ('system memory', '', '', 'virtual memory page count', ['active resident pages', 'inactive resident pages', 'pinned resident pages', 'free pages']), + ('memory paging', '', '', 'vm disk activity', ['pageins', 'pageouts']), + ('page faults', '', '', '', ['page faults']), # ('absolute_waste', 'num', '', ['failed bytes', 'redundant bytes', 'download rate']), #somewhat uninteresting stats diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 8b43175fa..8aaa81597 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -810,6 +810,11 @@ namespace aux { m_stats_logger = 0; m_log_seq = 0; m_stats_logging_enabled = true; + + memset(&m_last_cache_status, 0, sizeof(m_last_cache_status)); + extern void get_vm_stats(vm_statistics_data_t* vm_stat); + get_vm_stats(&m_last_vm_stat); + reset_stat_counters(); rotate_stats_log(); #endif @@ -969,6 +974,13 @@ namespace aux { ":uTP avg send delay" ":read ops/s" ":write ops/s" + ":active resident pages" + ":inactive resident pages" + ":pinned resident pages" + ":free pages" + ":pageins" + ":pageouts" + ":page faults" "\n\n", m_stats_logger); } #endif @@ -3049,6 +3061,21 @@ namespace aux { } #ifdef TORRENT_STATS + + void get_vm_stats(vm_statistics_data_t* vm_stat) + { + memset(vm_stat, 0, sizeof(*vm_stat)); +#if defined __MACH__ + mach_port_t host_port = mach_host_self(); + mach_msg_type_number_t host_count = HOST_VM_INFO_COUNT; + kern_return_t error = host_statistics(host_port, HOST_VM_INFO, + (host_info_t)vm_stat, &host_count); +#elif defined TORRENT_LINUX + // TODO: read straight from /proc/meminfo ? +#endif + } + + void session_impl::enable_stats_logging(bool s) { if (m_stats_logging_enabled == s) return; @@ -3235,7 +3262,11 @@ namespace aux { if (now - m_last_log_rotation > hours(1)) rotate_stats_log(); - + + // system memory stats + vm_statistics_data_t vm_stat; + get_vm_stats(&vm_stat); + if (m_stats_logger) { cache_status cs = m_disk_thread.status(); @@ -3356,11 +3387,21 @@ namespace aux { STAT_LOG(f, float(utp_num_delay_sockets ? float(utp_send_delay_sum) / float(utp_num_delay_sockets) : 0) / 1000000.f); STAT_LOG(f, float(cs.reads - m_last_cache_status.reads) * 1000.0 / float(tick_interval_ms)); STAT_LOG(f, float(cs.writes - m_last_cache_status.writes) * 1000.0 / float(tick_interval_ms)); + + STAT_LOG(d, int(vm_stat.active_count)); + STAT_LOG(d, int(vm_stat.inactive_count)); + STAT_LOG(d, int(vm_stat.wire_count)); + STAT_LOG(d, int(vm_stat.free_count)); + STAT_LOG(d, int(vm_stat.pageins - m_last_vm_stat.pageins)); + STAT_LOG(d, int(vm_stat.pageouts - m_last_vm_stat.pageouts)); + STAT_LOG(d, int(vm_stat.faults - m_last_vm_stat.faults)); + fprintf(m_stats_logger, "\n"); #undef STAT_LOG m_last_cache_status = cs; + m_last_vm_stat = vm_stat; m_last_failed = m_total_failed_bytes; m_last_redundant = m_total_redundant_bytes; m_last_uploaded = m_stat.total_upload();