added option for session statistics output
This commit is contained in:
parent
bf25aa0d1c
commit
4a906aa31d
3
Jamfile
3
Jamfile
|
@ -37,6 +37,9 @@ feature.compose <resolve-countries>off : <define>TORRENT_DISABLE_RESOLVE_COUNTRI
|
||||||
feature character-set : ansi unicode : composite propagated link-incompatible ;
|
feature character-set : ansi unicode : composite propagated link-incompatible ;
|
||||||
feature.compose <character-set>unicode : <define>_UNICODE <define>UNICODE ;
|
feature.compose <character-set>unicode : <define>_UNICODE <define>UNICODE ;
|
||||||
|
|
||||||
|
feature statistics : on off : composite propagated link-incompatible ;
|
||||||
|
feature.compose <statistics>on : <define>TORRENT_STATS ;
|
||||||
|
|
||||||
SOURCES =
|
SOURCES =
|
||||||
allocate_resources
|
allocate_resources
|
||||||
alert
|
alert
|
||||||
|
|
|
@ -429,6 +429,12 @@ namespace libtorrent
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
void check_invariant(const char *place = 0);
|
void check_invariant(const char *place = 0);
|
||||||
#endif
|
#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)
|
#if defined(TORRENT_VERBOSE_LOGGING) || defined(TORRENT_LOGGING)
|
||||||
boost::shared_ptr<logger> create_log(std::string const& name
|
boost::shared_ptr<logger> create_log(std::string const& name
|
||||||
, int instance, bool append = true);
|
, int instance, bool append = true);
|
||||||
|
@ -437,10 +443,6 @@ namespace libtorrent
|
||||||
// shutting down. This list is just here to keep them alive during
|
// shutting down. This list is just here to keep them alive during
|
||||||
// whe shutting down process
|
// whe shutting down process
|
||||||
std::list<boost::shared_ptr<tracker_logger> > m_tracker_loggers;
|
std::list<boost::shared_ptr<tracker_logger> > m_tracker_loggers;
|
||||||
|
|
||||||
// logger used to write bandwidth usage statistics
|
|
||||||
boost::shared_ptr<logger> m_stats_logger;
|
|
||||||
int m_second_counter;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
boost::shared_ptr<logger> m_logger;
|
boost::shared_ptr<logger> m_logger;
|
||||||
|
|
|
@ -52,17 +52,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
namespace libtorrent
|
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
|
// DEBUG API
|
||||||
|
|
||||||
struct logger
|
struct logger
|
||||||
|
|
|
@ -178,9 +178,7 @@ namespace libtorrent
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef TORRENT_DISABLE_EXTENSIONS
|
#ifndef TORRENT_DISABLE_EXTENSIONS
|
||||||
|
|
||||||
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*)> ext);
|
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*)> ext);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void set_ip_filter(ip_filter const& f);
|
void set_ip_filter(ip_filter const& f);
|
||||||
|
|
|
@ -510,17 +510,23 @@ namespace libtorrent { namespace detail
|
||||||
m_logger = create_log("main_session", listen_port(), false);
|
m_logger = create_log("main_session", listen_port(), false);
|
||||||
(*m_logger) << time_now_string() << "\n";
|
(*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_dl_bandwidth_manager.m_ses = this;
|
||||||
m_ul_bandwidth_manager.m_ses = this;
|
m_ul_bandwidth_manager.m_ses = this;
|
||||||
#endif
|
#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 ----
|
// ---- generate a peer id ----
|
||||||
static seed_random_generator seeder;
|
static seed_random_generator seeder;
|
||||||
|
|
||||||
|
@ -846,6 +852,29 @@ namespace libtorrent { namespace detail
|
||||||
m_timer.expires_from_now(seconds(1));
|
m_timer.expires_from_now(seconds(1));
|
||||||
m_timer.async_wait(m_strand.wrap(
|
m_timer.async_wait(m_strand.wrap(
|
||||||
bind(&session_impl::second_tick, this, _1)));
|
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
|
// let torrents connect to peers if they want to
|
||||||
// if there are any torrents and any free slots
|
// if there are any torrents and any free slots
|
||||||
|
|
Loading…
Reference in New Issue