diff --git a/include/libtorrent/disk_io_thread.hpp b/include/libtorrent/disk_io_thread.hpp index 15d3c422f..71d69fc9c 100644 --- a/include/libtorrent/disk_io_thread.hpp +++ b/include/libtorrent/disk_io_thread.hpp @@ -189,6 +189,10 @@ namespace libtorrent { return m_allocations; } #endif +#ifdef TORRENT_DISK_STATS + std::ofstream m_disk_access_log; +#endif + void release_memory(); int in_use() const { return m_in_use; } @@ -269,10 +273,6 @@ namespace libtorrent void check_invariant() const; #endif -#ifdef TORRENT_DISK_STATS - std::ofstream m_disk_access_log; -#endif - struct cached_block_entry { cached_block_entry(): buf(0) {} diff --git a/src/disk_io_thread.cpp b/src/disk_io_thread.cpp index 82f43d050..6225f28b3 100644 --- a/src/disk_io_thread.cpp +++ b/src/disk_io_thread.cpp @@ -62,6 +62,9 @@ namespace libtorrent m_log.open("disk_buffers.log", std::ios::trunc); m_categories["read cache"] = 0; m_categories["write cache"] = 0; + + m_log.open("disk_io_thread.log", std::ios::trunc); + m_disk_access_log.open("disk_access.log", std::ios::trunc); #endif #ifdef TORRENT_DEBUG m_magic = 0x1337; @@ -282,10 +285,6 @@ namespace libtorrent , m_work(io_service::work(m_ios)) , m_disk_io_thread(boost::ref(*this)) { -#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 } disk_io_thread::~disk_io_thread() diff --git a/src/storage.cpp b/src/storage.cpp index 88912be7a..238844eca 100644 --- a/src/storage.cpp +++ b/src/storage.cpp @@ -1206,16 +1206,22 @@ ret: , 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; + disk_buffer_pool* pool = disk_pool(); + if (pool) + { + pool->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; + if (pool) + { + pool->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); @@ -1226,16 +1232,22 @@ ret: , 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; + disk_buffer_pool* pool = disk_pool(); + if (pool) + { + pool->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; + if (pool) + { + pool->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);