added instrumentation for disk access. Useful to benchmark disk cache performance

This commit is contained in:
Arvid Norberg 2009-05-23 03:03:52 +00:00
parent 0127edac14
commit e36ea4ba5d
4 changed files with 36 additions and 0 deletions

7
disk_access.gnuplot Normal file
View File

@ -0,0 +1,7 @@
set term png size 1200,700
set output "disk_access.png"
set xrange [0:*]
set xlabel "time (ms)"
set ylabel "disk offset"
set key box
plot "disk_access.log" using 1:3 title "disk access locations" with steps

View File

@ -262,6 +262,10 @@ namespace libtorrent
void check_invariant() const;
#endif
#ifdef TORRENT_DISK_STATS
std::ofstream m_disk_access_log;
#endif
private:
struct cached_piece_entry

View File

@ -261,6 +261,7 @@ namespace libtorrent
{
#ifdef TORRENT_DISK_STATS
m_log.open("disk_io_thread.log", std::ios::trunc);
m_disk_access_log.open("disk_access.log", std::ios::trunc);
#endif
}

View File

@ -1204,17 +1204,41 @@ ret:
int storage::writev(file::iovec_t const* bufs, int slot, int offset
, int num_bufs)
{
#ifdef TORRENT_DISK_STATS
disk_io_thread* iothread = (disk_io_thread*)disk_pool();
iothread->m_disk_access_log << log_time() << " write "
<< (size_type(slot) * m_files.piece_length() + offset) << std::endl;
#endif
fileop op = { &file::writev, &storage::write_unaligned
, m_settings ? settings().disk_io_write_mode : 0, file::read_write };
#ifdef TORRENT_DISK_STATS
int ret = readwritev(bufs, slot, offset, num_bufs, op);
iothread->m_disk_access_log << log_time() << " write_end "
<< (size_type(slot) * m_files.piece_length() + offset + ret) << std::endl;
return ret;
#else
return readwritev(bufs, slot, offset, num_bufs, op);
#endif
}
int storage::readv(file::iovec_t const* bufs, int slot, int offset
, int num_bufs)
{
#ifdef TORRENT_DISK_STATS
disk_io_thread* iothread = (disk_io_thread*)disk_pool();
iothread->m_disk_access_log << log_time() << " read "
<< (size_type(slot) * m_files.piece_length() + offset) << std::endl;
#endif
fileop op = { &file::readv, &storage::read_unaligned
, m_settings ? settings().disk_io_read_mode : 0, file::read_only };
#ifdef TORRENT_DISK_STATS
int ret = readwritev(bufs, slot, offset, num_bufs, op);
iothread->m_disk_access_log << log_time() << " read_end "
<< (size_type(slot) * m_files.piece_length() + offset + ret) << std::endl;
return ret;
#else
return readwritev(bufs, slot, offset, num_bufs, op);
#endif
}
// much of what needs to be done when reading and writing