diff --git a/Jamfile b/Jamfile index b44630581..64202c7c4 100755 --- a/Jamfile +++ b/Jamfile @@ -37,6 +37,9 @@ feature.compose off : TORRENT_DISABLE_RESOLVE_COUNTRI feature character-set : ansi unicode : composite propagated link-incompatible ; feature.compose unicode : _UNICODE UNICODE ; +feature statistics : on off : composite propagated link-incompatible ; +feature.compose on : TORRENT_STATS ; + SOURCES = allocate_resources alert diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index 49c79bdc0..74220ba47 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -429,6 +429,12 @@ namespace libtorrent #ifndef NDEBUG void check_invariant(const char *place = 0); #endif + +#ifdef TORRENT_STATS + // logger used to write bandwidth usage statistics + std::ofstream m_stats_logger; + int m_second_counter; +#endif #if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING) boost::shared_ptr create_log(std::string const& name , int instance, bool append = true); @@ -437,10 +443,6 @@ namespace libtorrent // shutting down. This list is just here to keep them alive during // whe shutting down process std::list > m_tracker_loggers; - - // logger used to write bandwidth usage statistics - boost::shared_ptr m_stats_logger; - int m_second_counter; public: boost::shared_ptr m_logger; diff --git a/include/libtorrent/debug.hpp b/include/libtorrent/debug.hpp index 78df16b7a..39c4b0222 100755 --- a/include/libtorrent/debug.hpp +++ b/include/libtorrent/debug.hpp @@ -52,17 +52,6 @@ POSSIBILITY OF SUCH DAMAGE. namespace libtorrent { - - // PROFILING CODE -#ifdef TORRENT_PROFILE - - void add_checkpoint(std::string const& str); - void print_checkpoints(); -#define TORRENT_CHECKPOINT(str) libtorrent::add_checkpoint(str) -#else -#define TORRENT_CHECKPOINT(str) void(0) -#endif - // DEBUG API struct logger diff --git a/include/libtorrent/session.hpp b/include/libtorrent/session.hpp index ddc05b092..7cd9961bd 100755 --- a/include/libtorrent/session.hpp +++ b/include/libtorrent/session.hpp @@ -178,9 +178,7 @@ namespace libtorrent #endif #ifndef TORRENT_DISABLE_EXTENSIONS - void add_extension(boost::function(torrent*)> ext); - #endif void set_ip_filter(ip_filter const& f); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 9888dc137..4a72d6752 100755 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -510,17 +510,23 @@ namespace libtorrent { namespace detail m_logger = create_log("main_session", listen_port(), false); (*m_logger) << time_now_string() << "\n"; - m_stats_logger = create_log("session_stats", listen_port(), false); - (*m_stats_logger) << - "1. second\n" - "2. hard upload quota\n" - "3. hard download quota\n" - "\n"; - m_second_counter = 0; m_dl_bandwidth_manager.m_ses = this; m_ul_bandwidth_manager.m_ses = this; #endif +#ifdef TORRENT_STATS + m_stats_logger.open("session_stats"); + m_stats_logger << + "1. second\n" + "2. upload rate\n" + "3. download rate\n" + "4. downloading torrents\n" + "5. seeding torrents\n" + "6. peers\n" + "\n"; + m_second_counter = 0; +#endif + // ---- generate a peer id ---- static seed_random_generator seeder; @@ -846,6 +852,29 @@ namespace libtorrent { namespace detail m_timer.expires_from_now(seconds(1)); m_timer.async_wait(m_strand.wrap( bind(&session_impl::second_tick, this, _1))); + +#ifdef TORRENT_STATS + ++m_second_counter; + int downloading_torrents = 0; + int seeding_torrents = 0; + for (torrent_map::iterator i = m_torrents.begin() + , end(m_torrents.end()); i != end; ++i) + { + if (i->second->is_seed()) + ++seeding_torrents; + else + ++downloading_torrents; + } + m_stats_logger + << m_second_counter << "\t" + << m_stat.upload_rate() << "\t" + << m_stat.download_rate() << "\t" + << downloading_torrents << "\t" + << seeding_torrents << "\t" + << m_connections.size() << "\t" + "\n"; +#endif + // let torrents connect to peers if they want to // if there are any torrents and any free slots