added queued bytes to bandwidth manager and session_stats

This commit is contained in:
Arvid Norberg 2008-12-13 05:12:12 +00:00
parent 8c39f679e7
commit 0638251289
4 changed files with 28 additions and 2 deletions

View File

@ -1416,8 +1416,10 @@ int main(int ac, char* av[])
"==== waste: " << add_suffix(sess_stat.total_redundant_bytes)
<< " fail: " << add_suffix(sess_stat.total_failed_bytes)
<< " unchoked: " << sess_stat.num_unchoked << " / " << sess_stat.allowed_upload_slots
<< " bw queues: (" << sess_stat.up_bandwidth_queue
<< " | " << sess_stat.down_bandwidth_queue << ") "
<< " bw queues: " << sess_stat.up_bandwidth_bytes_queue
<< " (" << sess_stat.up_bandwidth_queue<< ")"
<< " | " << sess_stat.down_bandwidth_bytes_queue
<< " (" << sess_stat.down_bandwidth_queue<< ") "
" write cache hits: " << ((cs.blocks_written - cs.writes) * 100 / cs.blocks_written) << "% "
" read cache hits: " << (cs.blocks_read_hit * 100 / cs.blocks_read) << "% "
" cache size: " << add_suffix(cs.cache_size * 16 * 1024)

View File

@ -115,6 +115,7 @@ struct bandwidth_manager
, m_limit(bandwidth_limit::inf)
, m_drain_quota(0)
, m_current_quota(0)
, m_queued_bytes(0)
, m_channel(channel)
, m_in_hand_out_bandwidth(false)
, m_abort(false)
@ -151,6 +152,7 @@ struct bandwidth_manager
{
m_abort = true;
m_queue.clear();
m_queued_bytes = 0;
m_history.clear();
m_current_quota = 0;
error_code ec;
@ -196,6 +198,12 @@ struct bandwidth_manager
mutex_t::scoped_lock l(m_mutex);
return m_queue.size();
}
int queued_bytes() const
{
mutex_t::scoped_lock l(m_mutex);
return m_queued_bytes;
}
// non prioritized means that, if there's a line for bandwidth,
// others will cut in front of the non-prioritized peers.
@ -220,6 +228,7 @@ struct bandwidth_manager
++i;
}
m_queue.insert(i.base(), bw_queue_entry<PeerConnection, Torrent>(peer, blk, priority));
m_queued_bytes += blk;
if (!m_queue.empty()) hand_out_bandwidth(l);
}
@ -234,14 +243,19 @@ struct bandwidth_manager
}
TORRENT_ASSERT(current_quota == m_current_quota);
int bytes = 0;
typename queue_t::const_iterator j = m_queue.begin();
if (j != m_queue.end())
{
++j;
for (typename queue_t::const_iterator i = m_queue.begin()
, end(m_queue.end()); i != end && j != end; ++i, ++j)
{
TORRENT_ASSERT(i->priority >= j->priority);
bytes += i->max_block_size;
}
}
TORRENT_ASSERT(bytes == m_queued_bytes);
}
#endif
@ -358,6 +372,7 @@ private:
{
bw_queue_entry<PeerConnection, Torrent> qe = m_queue.front();
TORRENT_ASSERT(qe.max_block_size > 0);
m_queued_bytes -= qe.max_block_size;
m_queue.pop_front();
shared_ptr<Torrent> t = qe.torrent.lock();
@ -377,6 +392,7 @@ private:
if (max_assignable == 0)
{
TORRENT_ASSERT(is_in_history(qe.peer.get(), l));
m_queued_bytes += qe.max_block_size;
tmp.push_back(qe);
continue;
}
@ -419,6 +435,7 @@ private:
if (amount < block_size / 4)
{
m_queued_bytes += qe.max_block_size;
tmp.push_back(qe);
// m_queue.push_front(qe);
break;
@ -467,6 +484,7 @@ private:
// these are the consumers that want bandwidth
typedef std::deque<bw_queue_entry<PeerConnection, Torrent> > queue_t;
queue_t m_queue;
int m_queued_bytes;
// these are the consumers that have received bandwidth
// that will expire

View File

@ -91,6 +91,9 @@ namespace libtorrent
int up_bandwidth_queue;
int down_bandwidth_queue;
int up_bandwidth_bytes_queue;
int down_bandwidth_bytes_queue;
int optimistic_unchoke_counter;
int unchoke_counter;

View File

@ -2121,6 +2121,9 @@ namespace aux {
s.up_bandwidth_queue = m_upload_channel.queue_size();
s.down_bandwidth_queue = m_download_channel.queue_size();
s.up_bandwidth_bytes_queue = m_upload_channel.queued_bytes();
s.down_bandwidth_bytes_queue = m_download_channel.queued_bytes();
s.has_incoming_connections = m_incoming_connection;
// total