From c047f6645400386fb84facea09ca125301fbb484 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Tue, 19 May 2009 07:00:05 +0000 Subject: [PATCH] improved disk buffer logging and added extra asserts when logging disk buffer stats --- include/libtorrent/disk_io_thread.hpp | 3 +++ parse_disk_buffer_log.py | 2 -- src/disk_io_thread.cpp | 31 +++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 327a66d00..210cbf93b 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -217,9 +217,12 @@ namespace libtorrent int m_allocations; #endif #ifdef TORRENT_DISK_STATS + protected: + void disk_buffer_pool::rename_buffer(char* buf, char const* category); std::map m_categories; std::map m_buf_to_category; std::ofstream m_log; + private: #endif #ifdef TORRENT_DEBUG int m_magic; diff --git a/parse_disk_buffer_log.py b/parse_disk_buffer_log.py index b0771e3e1..813f41891 100755 --- a/parse_disk_buffer_log.py +++ b/parse_disk_buffer_log.py @@ -48,8 +48,6 @@ print out.close() -keys = ['check piece', 'send buffer', 'read cache', 'receive buffer', 'hash temp'] - out = open('disk_buffer.gnuplot', 'wb') print >>out, "set term png size 1200,700" print >>out, 'set output "disk_buffer.png"' diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 3812ee388..65f2879fe 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -60,6 +60,8 @@ namespace libtorrent #endif #ifdef TORRENT_DISK_STATS m_log.open("disk_buffers.log", std::ios::trunc); + m_categories["read cache"] = 0; + m_categories["write cache"] = 0; #endif #ifdef TORRENT_DEBUG m_magic = 0x1337; @@ -120,6 +122,21 @@ namespace libtorrent return ret; } +#ifdef TORRENT_DISK_STATS + void disk_buffer_pool::rename_buffer(char* buf, char const* category) + { + TORRENT_ASSERT(m_categories.find(m_buf_to_category[buf]) + != m_categories.end()); + std::string const& prev_category = m_buf_to_category[buf]; + --m_categories[prev_category]; + m_log << log_time() << " " << prev_category << ": " << m_categories[prev_category] << "\n"; + + ++m_categories[category]; + m_buf_to_category[buf] = category; + m_log << log_time() << " " << category << ": " << m_categories[category] << "\n"; + } +#endif + void disk_buffer_pool::free_buffer(char* buf) { TORRENT_ASSERT(buf); @@ -569,6 +586,10 @@ namespace libtorrent TORRENT_ASSERT(find_cached_piece(m_pieces, j, l) == m_pieces.end()); cached_piece_entry p; +#ifdef TORRENT_DISK_STATS + rename_buffer(j.buffer, "write cache"); +#endif + int piece_size = j.storage->info()->piece_size(j.piece); int blocks_in_piece = (piece_size + m_block_size - 1) / m_block_size; @@ -822,6 +843,13 @@ namespace libtorrent TORRENT_ASSERT(cached_read_blocks + cached_write_blocks == m_cache_stats.cache_size); TORRENT_ASSERT(cached_read_blocks == m_cache_stats.read_cache_size); +#ifdef TORRENT_DISK_STATS + int read_allocs = m_categories.find(std::string("read cache"))->second; + int write_allocs = m_categories.find(std::string("write cache"))->second; + TORRENT_ASSERT(cached_read_blocks == read_allocs); + TORRENT_ASSERT(cached_write_blocks == write_allocs); +#endif + // when writing, there may be a one block difference, right before an old piece // is flushed TORRENT_ASSERT(m_cache_stats.cache_size <= m_settings.cache_size + 1); @@ -1317,6 +1345,9 @@ namespace libtorrent --p->num_blocks; } p->blocks[block] = j.buffer; +#ifdef TORRENT_DISK_STATS + rename_buffer(j.buffer, "write cache"); +#endif ++m_cache_stats.cache_size; ++p->num_blocks; p->last_use = time_now();