added more allocation logging for statistics builds. Identified and fixed some memory waste
This commit is contained in:
parent
0aa477ce54
commit
1eb2799a03
|
@ -77,6 +77,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||
#include "libtorrent/udp_socket.hpp"
|
||||
#include "libtorrent/assert.hpp"
|
||||
#include "libtorrent/policy.hpp" // for policy::peer
|
||||
#include "libtorrent/alert.hpp" // for alert_manager
|
||||
|
||||
namespace libtorrent
|
||||
{
|
||||
|
@ -350,7 +351,37 @@ namespace libtorrent
|
|||
// are allocated. It's a pool since we're likely
|
||||
// to have tens of thousands of peers, and a pool
|
||||
// saves significant overhead
|
||||
#ifdef TORRENT_STATS
|
||||
struct logging_allocator
|
||||
{
|
||||
typedef std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
static char* malloc(const size_type bytes)
|
||||
{
|
||||
allocated_bytes += bytes;
|
||||
++allocations;
|
||||
return (char*)::malloc(bytes);
|
||||
}
|
||||
|
||||
static void free(char* const block)
|
||||
{
|
||||
--allocations;
|
||||
return ::free(block);
|
||||
}
|
||||
|
||||
static int allocations;
|
||||
static int allocated_bytes;
|
||||
};
|
||||
boost::object_pool<policy::peer, logging_allocator> m_peer_pool;
|
||||
#else
|
||||
boost::object_pool<policy::peer> m_peer_pool;
|
||||
#endif
|
||||
|
||||
// this vector is used to store the block_info
|
||||
// objects pointed to by partial_piece_info returned
|
||||
// by torrent::get_download_queue.
|
||||
std::vector<block_info> m_block_info_storage;
|
||||
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
// this pool is used to allocate and recycle send
|
||||
|
@ -658,11 +689,6 @@ namespace libtorrent
|
|||
size_type m_total_failed_bytes;
|
||||
size_type m_total_redundant_bytes;
|
||||
|
||||
// this vector is used to store the block_info
|
||||
// objects pointed to by partial_piece_info returned
|
||||
// by torrent::get_download_queue.
|
||||
std::vector<block_info> m_block_info_storage;
|
||||
|
||||
// the main working thread
|
||||
boost::scoped_ptr<boost::thread> m_thread;
|
||||
};
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace libtorrent
|
|||
: m_block_size(block_size)
|
||||
, m_in_use(0)
|
||||
#ifndef TORRENT_DISABLE_POOL_ALLOCATOR
|
||||
, m_pool(block_size, 10)
|
||||
, m_pool(block_size, 16)
|
||||
#endif
|
||||
{
|
||||
#if defined TORRENT_DISK_STATS || defined TORRENT_STATS
|
||||
|
@ -95,6 +95,7 @@ namespace libtorrent
|
|||
char* ret = page_aligned_allocator::malloc(m_block_size);
|
||||
#else
|
||||
char* ret = (char*)m_pool.ordered_malloc();
|
||||
m_pool.set_next_size(16);
|
||||
#endif
|
||||
++m_in_use;
|
||||
#if TORRENT_USE_MLOCK
|
||||
|
@ -161,6 +162,7 @@ namespace libtorrent
|
|||
char* ret = page_aligned_allocator::malloc(m_block_size * num_blocks);
|
||||
#else
|
||||
char* ret = (char*)m_pool.ordered_malloc(num_blocks);
|
||||
m_pool.set_next_size(16);
|
||||
#endif
|
||||
m_in_use += num_blocks;
|
||||
#if TORRENT_USE_MLOCK
|
||||
|
|
|
@ -691,6 +691,7 @@ namespace libtorrent
|
|||
|
||||
if (m_round_robin > iter - m_peers.begin()) ++m_round_robin;
|
||||
peer* p = m_torrent->session().m_peer_pool.malloc();
|
||||
m_torrent->session().m_peer_pool.set_next_size(500);
|
||||
new (p) peer(c.remote(), false, 0);
|
||||
iter = m_peers.insert(iter, p);
|
||||
|
||||
|
@ -831,6 +832,7 @@ namespace libtorrent
|
|||
// we don't have any info about this peer.
|
||||
// add a new entry
|
||||
peer* p = m_torrent->session().m_peer_pool.malloc();
|
||||
m_torrent->session().m_peer_pool.set_next_size(500);
|
||||
new (p) peer(remote, true, src);
|
||||
iter = m_peers.insert(iter, p);
|
||||
|
||||
|
|
|
@ -141,6 +141,11 @@ namespace aux {
|
|||
}
|
||||
};
|
||||
|
||||
#ifdef TORRENT_STATS
|
||||
int session_impl::logging_allocator::allocations = 0;
|
||||
int session_impl::logging_allocator::allocated_bytes = 0;
|
||||
#endif
|
||||
|
||||
session_impl::session_impl(
|
||||
std::pair<int, int> listen_port_range
|
||||
, fingerprint const& cl_fprint
|
||||
|
@ -265,7 +270,8 @@ namespace aux {
|
|||
m_stats_logger.open("session_stats.log", std::ios::trunc);
|
||||
m_stats_logger <<
|
||||
"second:upload rate:download rate:downloading torrents:seeding torrents"
|
||||
":peers:connecting peers:disk block buffers:unchoked peers:num list peers\n\n";
|
||||
":peers:connecting peers:disk block buffers:unchoked peers:num list peers"
|
||||
":peer allocations:peer storage bytes\n\n";
|
||||
m_buffer_usage_logger.open("buffer_stats.log", std::ios::trunc);
|
||||
m_second_counter = 0;
|
||||
m_buffer_allocations = 0;
|
||||
|
@ -1236,6 +1242,8 @@ namespace aux {
|
|||
<< m_disk_thread.disk_allocations() << "\t"
|
||||
<< unchoked_peers << "\t"
|
||||
<< num_peers << "\t"
|
||||
<< logging_allocator::allocations << "\t"
|
||||
<< logging_allocator::allocated_bytes << "\t"
|
||||
<< std::endl;
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue