diff --git a/disk_access.gnuplot b/disk_access.gnuplot new file mode 100644 index 000000000..c17f9c27a --- /dev/null +++ b/disk_access.gnuplot @@ -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 diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index e893e3d0b..46c398f2d 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -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 diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 0f0725574..df8d41f0a 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -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 } diff --git a/src/storage.cpp b/src/storage.cpp index 32be9f58c..ad193cde0 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -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