forked from premiere/premiere-libtorrent
improved disk buffer logging and added extra asserts when logging disk buffer stats
This commit is contained in:
parent
ad157d49d2
commit
c047f66454
|
@ -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<std::string, int> m_categories;
|
||||
std::map<char*, std::string> m_buf_to_category;
|
||||
std::ofstream m_log;
|
||||
private:
|
||||
#endif
|
||||
#ifdef TORRENT_DEBUG
|
||||
int m_magic;
|
||||
|
|
|
@ -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"'
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue