added option for session statistics output

This commit is contained in:
Arvid Norberg 2007-05-13 22:01:21 +00:00
parent bf25aa0d1c
commit 4a906aa31d
5 changed files with 45 additions and 24 deletions

View File

@ -37,6 +37,9 @@ feature.compose <resolve-countries>off : <define>TORRENT_DISABLE_RESOLVE_COUNTRI
feature character-set : ansi unicode : composite propagated link-incompatible ;
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 =
allocate_resources
alert

View File

@ -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<logger> 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<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:
boost::shared_ptr<logger> m_logger;

View File

@ -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

View File

@ -178,9 +178,7 @@ namespace libtorrent
#endif
#ifndef TORRENT_DISABLE_EXTENSIONS
void add_extension(boost::function<boost::shared_ptr<torrent_plugin>(torrent*)> ext);
#endif
void set_ip_filter(ip_filter const& f);

View File

@ -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