more buffer categories to help debugging

This commit is contained in:
Arvid Norberg 2009-05-31 22:38:49 +00:00
parent 290942af33
commit 0283f07aed
5 changed files with 32 additions and 12 deletions

View File

@ -222,8 +222,9 @@ namespace libtorrent
int m_allocations; int m_allocations;
#endif #endif
#ifdef TORRENT_DISK_STATS #ifdef TORRENT_DISK_STATS
protected: public:
void rename_buffer(char* buf, char const* category); void rename_buffer(char* buf, char const* category);
protected:
std::map<std::string, int> m_categories; std::map<std::string, int> m_categories;
std::map<char*, std::string> m_buf_to_category; std::map<char*, std::string> m_buf_to_category;
std::ofstream m_log; std::ofstream m_log;

View File

@ -474,6 +474,9 @@ namespace libtorrent
template <class Destructor> template <class Destructor>
void append_send_buffer(char* buffer, int size, Destructor const& destructor) void append_send_buffer(char* buffer, int size, Destructor const& destructor)
{ {
#if TORRENT_DISK_STATS
m_ses.m_disk_thread.rename_buffer(buffer, "queued send buffer");
#endif
m_send_buffer.append_buffer(buffer, size, size, destructor); m_send_buffer.append_buffer(buffer, size, size, destructor);
#ifdef TORRENT_STATS #ifdef TORRENT_STATS
m_ses.m_buffer_usage_logger << log_time() << " append_send_buffer: " << size << std::endl; m_ses.m_buffer_usage_logger << log_time() << " append_send_buffer: " << size << std::endl;

View File

@ -9,8 +9,12 @@ lines = open(sys.argv[1], 'rb').readlines()
# example: # example:
# 16434 read cache: 17 # 16434 read cache: 17
key_order = ['receive buffer', 'send buffer', 'write cache', 'read cache', 'hash temp'] key_order = ['receive buffer', 'send buffer', 'released send buffer', 'posted send buffer',
colors = ['30f030', 'f03030', '80f080', 'f08080', '4040ff'] 'received send buffer', 'dispatched send buffer', 'queued send buffer',
'write cache', 'read cache', 'hash temp']
colors = ['30f030', '001070', '101080', '2040a0',
'4070d0', '80a0f0', 'f03030',
'80f080', 'f08080', '4040ff']
keys = [] keys = []
fields = {} fields = {}
@ -45,13 +49,7 @@ for l in lines:
print >>out, '%d\t' % maximum[i], print >>out, '%d\t' % maximum[i],
print >>out, '\n', print >>out, '\n',
if not c in keys: if not c in keys: continue
keys.append(c)
fields[c] = 0
maximum[c] = 0
field_sum[c] = 0
field_num_samples[c] = 0
field_timestamp[c] = 0
field_sum[c] += fields[c] * float(t - field_timestamp[c]) field_sum[c] += fields[c] * float(t - field_timestamp[c])
field_timestamp[c] = t field_timestamp[c] = t

View File

@ -819,7 +819,7 @@ namespace libtorrent
file::iovec_t b = { buf.get(), buffer_size }; file::iovec_t b = { buf.get(), buffer_size };
ret = p.storage->read_impl(&b, p.piece, start_block * m_block_size, 1); ret = p.storage->read_impl(&b, p.piece, start_block * m_block_size, 1);
l.lock(); l.lock();
if (p.storage->error()) { return -1; } if (p.storage->error()) return -1;
if (ret != buffer_size) if (ret != buffer_size)
{ {
// this means the file wasn't big enough for this read // this means the file wasn't big enough for this read
@ -858,7 +858,7 @@ namespace libtorrent
l.unlock(); l.unlock();
ret = p.storage->read_impl(iov, p.piece, start_block * m_block_size, iov_counter); ret = p.storage->read_impl(iov, p.piece, start_block * m_block_size, iov_counter);
l.lock(); l.lock();
if (p.storage->error()) { return -1; } if (p.storage->error()) return -1;
if (ret != buffer_size) if (ret != buffer_size)
{ {
// this means the file wasn't big enough for this read // this means the file wasn't big enough for this read
@ -1456,6 +1456,9 @@ namespace libtorrent
TORRENT_ASSERT(j.buffer == read_holder.get()); TORRENT_ASSERT(j.buffer == read_holder.get());
read_holder.release(); read_holder.release();
#if TORRENT_DISK_STATS
rename_buffer(j.buffer, "released send buffer");
#endif
break; break;
} }
case disk_io_job::read: case disk_io_job::read:
@ -1517,6 +1520,9 @@ namespace libtorrent
} }
TORRENT_ASSERT(j.buffer == read_holder.get()); TORRENT_ASSERT(j.buffer == read_holder.get());
read_holder.release(); read_holder.release();
#if TORRENT_DISK_STATS
rename_buffer(j.buffer, "released send buffer");
#endif
break; break;
} }
case disk_io_job::write: case disk_io_job::write:
@ -1745,6 +1751,7 @@ namespace libtorrent
* (piece_size / (16 * 1024)) * (piece_size / (16 * 1024))
- total_milliseconds(now - m_last_file_check); - total_milliseconds(now - m_last_file_check);
if (sleep_time < 0) sleep_time = 0; if (sleep_time < 0) sleep_time = 0;
TORRENT_ASSERT(sleep_time < 5 * 1000);
boost::thread::sleep(boost::get_system_time() boost::thread::sleep(boost::get_system_time()
+ boost::posix_time::milliseconds(sleep_time)); + boost::posix_time::milliseconds(sleep_time));
@ -1824,6 +1831,11 @@ namespace libtorrent
#endif #endif
TORRENT_ASSERT(ret != -2 || !j.str.empty() TORRENT_ASSERT(ret != -2 || !j.str.empty()
|| j.action == disk_io_job::hash); || j.action == disk_io_job::hash);
#if TORRENT_DISK_STATS
if ((j.action == disk_io_job::read || j.action == disk_io_job::read_and_hash)
&& j.buffer != 0)
rename_buffer(j.buffer, "posted send buffer");
#endif
post_callback(handler, j, ret); post_callback(handler, j, ret);
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
} catch (std::exception&) } catch (std::exception&)

View File

@ -3510,6 +3510,9 @@ namespace libtorrent
m_reading_bytes -= r.length; m_reading_bytes -= r.length;
disk_buffer_holder buffer(m_ses, j.buffer); disk_buffer_holder buffer(m_ses, j.buffer);
#if TORRENT_DISK_STATS
m_ses.m_disk_thread.rename_buffer(j.buffer, "received send buffer");
#endif
boost::shared_ptr<torrent> t = m_torrent.lock(); boost::shared_ptr<torrent> t = m_torrent.lock();
if (ret != r.length || m_torrent.expired()) if (ret != r.length || m_torrent.expired())
@ -3547,6 +3550,9 @@ namespace libtorrent
<< " | l: " << r.length << " ]\n"; << " | l: " << r.length << " ]\n";
#endif #endif
#if TORRENT_DISK_STATS
m_ses.m_disk_thread.rename_buffer(j.buffer, "dispatched send buffer");
#endif
write_piece(r, buffer); write_piece(r, buffer);
setup_send(); setup_send();
} }