rotate stats log every hour
This commit is contained in:
parent
aa116cd1d1
commit
4267f0ec5a
|
@ -86,10 +86,6 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "libtorrent/bloom_filter.hpp"
|
#include "libtorrent/bloom_filter.hpp"
|
||||||
#include "libtorrent/rss.hpp"
|
#include "libtorrent/rss.hpp"
|
||||||
|
|
||||||
#ifdef TORRENT_STATS
|
|
||||||
#include <fstream>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if TORRENT_COMPLETE_TYPES_REQUIRED
|
#if TORRENT_COMPLETE_TYPES_REQUIRED
|
||||||
#include "libtorrent/peer_connection.hpp"
|
#include "libtorrent/peer_connection.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
@ -861,9 +857,17 @@ namespace libtorrent
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined TORRENT_STATS
|
#if defined TORRENT_STATS
|
||||||
|
void rotate_stats_log();
|
||||||
|
|
||||||
|
// the last time we rotated the log file
|
||||||
|
ptime m_last_log_rotation;
|
||||||
|
|
||||||
// logger used to write bandwidth usage statistics
|
// logger used to write bandwidth usage statistics
|
||||||
std::ofstream m_stats_logger;
|
FILE* m_stats_logger;
|
||||||
int m_second_counter;
|
// sequence number for log file. Log files are
|
||||||
|
// rotated every hour and the sequence number is
|
||||||
|
// incremented by one
|
||||||
|
int m_log_seq;
|
||||||
// the number of peers that were disconnected this
|
// the number of peers that were disconnected this
|
||||||
// tick due to protocol error
|
// tick due to protocol error
|
||||||
int m_error_peers;
|
int m_error_peers;
|
||||||
|
|
|
@ -788,36 +788,8 @@ namespace aux {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TORRENT_STATS
|
#ifdef TORRENT_STATS
|
||||||
m_stats_logger.open("session_stats.log", std::ios::trunc);
|
m_stats_logger = 0;
|
||||||
m_stats_logger <<
|
m_log_seq = 0;
|
||||||
"second:upload rate:download rate:downloading torrents:seeding torrents"
|
|
||||||
":peers:connecting peers:disk block buffers:num list peers"
|
|
||||||
":peer allocations:peer storage bytes:checking torrents:stopped torrents"
|
|
||||||
":peers bw-up:peers bw-down:peers disk-up:peers disk-down"
|
|
||||||
":smooth upload rate:smooth download rate:disk write queued bytes"
|
|
||||||
":peers down 0:peers down 0-2:peers down 2-5:peers down 5-10:peers down 10-50"
|
|
||||||
":peers down 50-100:peers down 100-"
|
|
||||||
":peers up 0:peers up 0-2:peers up 2-5:peers up 5-10:peers up 10-50: peers up 50-100"
|
|
||||||
":peers up 100-:error peers"
|
|
||||||
":peers down interesting:peers down unchoked:peers down requests"
|
|
||||||
":peers up interested:peers up unchoked:peers up requests"
|
|
||||||
":peer disconnects:peers eof:peers connection reset"
|
|
||||||
":outstanding requests:outstanding end-game requests"
|
|
||||||
":outstanding writing blocks"
|
|
||||||
":end game piece picker blocks"
|
|
||||||
":piece picker blocks"
|
|
||||||
":piece picks"
|
|
||||||
":reject piece picks"
|
|
||||||
":unchoke piece picks"
|
|
||||||
":incoming redundant piece picks"
|
|
||||||
":incoming piece picks"
|
|
||||||
":end game piece picks"
|
|
||||||
":snubbed piece picks"
|
|
||||||
":% failed payload bytes"
|
|
||||||
":% wasted payload bytes"
|
|
||||||
":% protocol bytes"
|
|
||||||
"\n\n";
|
|
||||||
m_second_counter = 0;
|
|
||||||
m_error_peers = 0;
|
m_error_peers = 0;
|
||||||
m_disconnected_peers = 0;
|
m_disconnected_peers = 0;
|
||||||
m_eof_peers = 0;
|
m_eof_peers = 0;
|
||||||
|
@ -831,6 +803,7 @@ namespace aux {
|
||||||
m_incoming_piece_picks = 0;
|
m_incoming_piece_picks = 0;
|
||||||
m_end_game_piece_picks = 0;
|
m_end_game_piece_picks = 0;
|
||||||
m_snubbed_piece_picks = 0;
|
m_snubbed_piece_picks = 0;
|
||||||
|
rotate_stats_log();
|
||||||
#endif
|
#endif
|
||||||
#ifdef TORRENT_DISK_STATS
|
#ifdef TORRENT_DISK_STATS
|
||||||
m_buffer_usage_logger.open("buffer_stats.log", std::ios::trunc);
|
m_buffer_usage_logger.open("buffer_stats.log", std::ios::trunc);
|
||||||
|
@ -888,6 +861,57 @@ namespace aux {
|
||||||
update_unchoke_limit();
|
update_unchoke_limit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TORRENT_STATS
|
||||||
|
void session_impl::rotate_stats_log()
|
||||||
|
{
|
||||||
|
if (m_stats_logger)
|
||||||
|
{
|
||||||
|
++m_log_seq;
|
||||||
|
fclose(m_stats_logger);
|
||||||
|
}
|
||||||
|
error_code ec;
|
||||||
|
create_directory("session_stats", ec);
|
||||||
|
char filename[100];
|
||||||
|
snprintf(filename, sizeof(filename), "session_stats/%d.%04d.log", int(getpid()), m_log_seq);
|
||||||
|
m_stats_logger = fopen(filename, "w+");
|
||||||
|
if (m_stats_logger == 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Failed to create session stats log file \"%s\": (%d) %s\n"
|
||||||
|
, filename, errno, strerror(errno));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_last_log_rotation = time_now();
|
||||||
|
|
||||||
|
fputs("second:upload rate:download rate:downloading torrents:seeding torrents"
|
||||||
|
":peers:connecting peers:disk block buffers:num list peers"
|
||||||
|
":peer allocations:peer storage bytes:checking torrents:stopped torrents"
|
||||||
|
":peers bw-up:peers bw-down:peers disk-up:peers disk-down"
|
||||||
|
":smooth upload rate:smooth download rate:disk write queued bytes"
|
||||||
|
":peers down 0:peers down 0-2:peers down 2-5:peers down 5-10:peers down 10-50"
|
||||||
|
":peers down 50-100:peers down 100-"
|
||||||
|
":peers up 0:peers up 0-2:peers up 2-5:peers up 5-10:peers up 10-50: peers up 50-100"
|
||||||
|
":peers up 100-:error peers"
|
||||||
|
":peers down interesting:peers down unchoked:peers down requests"
|
||||||
|
":peers up interested:peers up unchoked:peers up requests"
|
||||||
|
":peer disconnects:peers eof:peers connection reset"
|
||||||
|
":outstanding requests:outstanding end-game requests"
|
||||||
|
":outstanding writing blocks"
|
||||||
|
":end game piece picker blocks"
|
||||||
|
":piece picker blocks"
|
||||||
|
":piece picks"
|
||||||
|
":reject piece picks"
|
||||||
|
":unchoke piece picks"
|
||||||
|
":incoming redundant piece picks"
|
||||||
|
":incoming piece picks"
|
||||||
|
":end game piece picks"
|
||||||
|
":snubbed piece picks"
|
||||||
|
":% failed payload bytes"
|
||||||
|
":% wasted payload bytes"
|
||||||
|
":% protocol bytes"
|
||||||
|
"\n\n", m_stats_logger);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void session_impl::start_session()
|
void session_impl::start_session()
|
||||||
{
|
{
|
||||||
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
#if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING
|
||||||
|
@ -2540,7 +2564,6 @@ namespace aux {
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TORRENT_STATS
|
#ifdef TORRENT_STATS
|
||||||
++m_second_counter;
|
|
||||||
int downloading_torrents = 0;
|
int downloading_torrents = 0;
|
||||||
int seeding_torrents = 0;
|
int seeding_torrents = 0;
|
||||||
int checking_torrents = 0;
|
int checking_torrents = 0;
|
||||||
|
@ -2551,7 +2574,7 @@ namespace aux {
|
||||||
size_type upload_rate = (m_stat.total_upload() - uploaded) * 1000 / tick_interval_ms;
|
size_type upload_rate = (m_stat.total_upload() - uploaded) * 1000 / tick_interval_ms;
|
||||||
downloaded = m_stat.total_download();
|
downloaded = m_stat.total_download();
|
||||||
uploaded = m_stat.total_upload();
|
uploaded = m_stat.total_upload();
|
||||||
size_type num_peers = 0;
|
int num_peers = 0;
|
||||||
int peer_dl_rate_buckets[7];
|
int peer_dl_rate_buckets[7];
|
||||||
int peer_ul_rate_buckets[7];
|
int peer_ul_rate_buckets[7];
|
||||||
memset(peer_dl_rate_buckets, 0, sizeof(peer_dl_rate_buckets));
|
memset(peer_dl_rate_buckets, 0, sizeof(peer_dl_rate_buckets));
|
||||||
|
@ -2644,68 +2667,81 @@ namespace aux {
|
||||||
++peer_dl_rate_buckets[dl_bucket];
|
++peer_dl_rate_buckets[dl_bucket];
|
||||||
++peer_ul_rate_buckets[ul_bucket];
|
++peer_ul_rate_buckets[ul_bucket];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (now - m_last_log_rotation > hours(1))
|
||||||
|
rotate_stats_log();
|
||||||
|
|
||||||
m_stats_logger
|
if (m_stats_logger)
|
||||||
<< m_second_counter << "\t"
|
{
|
||||||
<< upload_rate << "\t"
|
fprintf(m_stats_logger
|
||||||
<< download_rate << "\t"
|
, "%f\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t"
|
||||||
<< downloading_torrents << "\t"
|
"%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t"
|
||||||
<< seeding_torrents << "\t"
|
"%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t"
|
||||||
<< num_complete_connections << "\t"
|
"%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t"
|
||||||
<< num_half_open << "\t"
|
"%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\t"
|
||||||
<< m_disk_thread.disk_allocations() << "\t"
|
"%d\t%d\t%d\t%d\t%d\t%d\t%f\t%f\t%f\n"
|
||||||
<< num_peers << "\t"
|
, total_milliseconds(now - m_last_log_rotation) / 1000.f
|
||||||
<< logging_allocator::allocations << "\t"
|
, int(upload_rate)
|
||||||
<< logging_allocator::allocated_bytes << "\t"
|
, int(download_rate)
|
||||||
<< checking_torrents << "\t"
|
, downloading_torrents
|
||||||
<< stopped_torrents << "\t"
|
, seeding_torrents
|
||||||
<< m_upload_rate.queue_size() << "\t"
|
, num_complete_connections
|
||||||
<< m_download_rate.queue_size() << "\t"
|
, num_half_open
|
||||||
<< m_disk_queues[peer_connection::upload_channel] << "\t"
|
, m_disk_thread.disk_allocations()
|
||||||
<< m_disk_queues[peer_connection::download_channel] << "\t"
|
, num_peers
|
||||||
<< m_stat.upload_rate() << "\t"
|
, logging_allocator::allocations
|
||||||
<< m_stat.download_rate() << "\t"
|
, logging_allocator::allocated_bytes
|
||||||
<< m_disk_thread.queue_buffer_size() << "\t"
|
, checking_torrents
|
||||||
<< peer_dl_rate_buckets[0] << "\t"
|
, stopped_torrents
|
||||||
<< peer_dl_rate_buckets[1] << "\t"
|
, m_upload_rate.queue_size()
|
||||||
<< peer_dl_rate_buckets[2] << "\t"
|
, m_download_rate.queue_size()
|
||||||
<< peer_dl_rate_buckets[3] << "\t"
|
, m_disk_queues[peer_connection::upload_channel]
|
||||||
<< peer_dl_rate_buckets[4] << "\t"
|
, m_disk_queues[peer_connection::download_channel]
|
||||||
<< peer_dl_rate_buckets[5] << "\t"
|
, m_stat.upload_rate()
|
||||||
<< peer_dl_rate_buckets[6] << "\t"
|
, m_stat.download_rate()
|
||||||
<< peer_ul_rate_buckets[0] << "\t"
|
, int(m_disk_thread.queue_buffer_size())
|
||||||
<< peer_ul_rate_buckets[1] << "\t"
|
, peer_dl_rate_buckets[0]
|
||||||
<< peer_ul_rate_buckets[2] << "\t"
|
, peer_dl_rate_buckets[1]
|
||||||
<< peer_ul_rate_buckets[3] << "\t"
|
, peer_dl_rate_buckets[2]
|
||||||
<< peer_ul_rate_buckets[4] << "\t"
|
, peer_dl_rate_buckets[3]
|
||||||
<< peer_ul_rate_buckets[5] << "\t"
|
, peer_dl_rate_buckets[4]
|
||||||
<< peer_ul_rate_buckets[6] << "\t"
|
, peer_dl_rate_buckets[5]
|
||||||
<< m_error_peers << "\t"
|
, peer_dl_rate_buckets[6]
|
||||||
<< peers_down_interesting << "\t"
|
, peer_ul_rate_buckets[0]
|
||||||
<< peers_down_unchoked << "\t"
|
, peer_ul_rate_buckets[1]
|
||||||
<< peers_down_requests << "\t"
|
, peer_ul_rate_buckets[2]
|
||||||
<< peers_up_interested << "\t"
|
, peer_ul_rate_buckets[3]
|
||||||
<< peers_up_unchoked << "\t"
|
, peer_ul_rate_buckets[4]
|
||||||
<< peers_up_requests << "\t"
|
, peer_ul_rate_buckets[5]
|
||||||
<< m_disconnected_peers << "\t"
|
, peer_ul_rate_buckets[6]
|
||||||
<< m_eof_peers << "\t"
|
, m_error_peers
|
||||||
<< m_connreset_peers << "\t"
|
, peers_down_interesting
|
||||||
<< outstanding_requests << "\t"
|
, peers_down_unchoked
|
||||||
<< outstanding_end_game_requests << "\t"
|
, peers_down_requests
|
||||||
<< outstanding_write_blocks << "\t"
|
, peers_up_interested
|
||||||
<< m_end_game_piece_picker_blocks << "\t"
|
, peers_up_unchoked
|
||||||
<< m_piece_picker_blocks << "\t"
|
, peers_up_requests
|
||||||
<< m_piece_picks << "\t"
|
, m_disconnected_peers
|
||||||
<< m_reject_piece_picks << "\t"
|
, m_eof_peers
|
||||||
<< m_unchoke_piece_picks << "\t"
|
, m_connreset_peers
|
||||||
<< m_incoming_redundant_piece_picks << "\t"
|
, outstanding_requests
|
||||||
<< m_incoming_piece_picks << "\t"
|
, outstanding_end_game_requests
|
||||||
<< m_end_game_piece_picks << "\t"
|
, outstanding_write_blocks
|
||||||
<< m_snubbed_piece_picks << "\t"
|
, m_end_game_piece_picker_blocks
|
||||||
<< (float(m_total_failed_bytes) * 100.f / m_stat.total_payload_download()) << "\t"
|
, m_piece_picker_blocks
|
||||||
<< (float(m_total_redundant_bytes) * 100.f / m_stat.total_payload_download()) << "\t"
|
, m_piece_picks
|
||||||
<< (float(m_stat.total_protocol_download()) * 100.f / m_stat.total_download()) << "\t"
|
, m_reject_piece_picks
|
||||||
<< std::endl;
|
, m_unchoke_piece_picks
|
||||||
|
, m_incoming_redundant_piece_picks
|
||||||
|
, m_incoming_piece_picks
|
||||||
|
, m_end_game_piece_picks
|
||||||
|
, m_snubbed_piece_picks
|
||||||
|
, (float(m_total_failed_bytes) * 100.f / m_stat.total_payload_download())
|
||||||
|
, (float(m_total_redundant_bytes) * 100.f / m_stat.total_payload_download())
|
||||||
|
, (float(m_stat.total_protocol_download()) * 100.f / m_stat.total_download())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
m_error_peers = 0;
|
m_error_peers = 0;
|
||||||
m_disconnected_peers = 0;
|
m_disconnected_peers = 0;
|
||||||
m_eof_peers = 0;
|
m_eof_peers = 0;
|
||||||
|
@ -4467,6 +4503,10 @@ namespace aux {
|
||||||
TORRENT_ASSERT(m_torrents.empty());
|
TORRENT_ASSERT(m_torrents.empty());
|
||||||
TORRENT_ASSERT(m_connections.empty());
|
TORRENT_ASSERT(m_connections.empty());
|
||||||
TORRENT_ASSERT(m_connections.empty());
|
TORRENT_ASSERT(m_connections.empty());
|
||||||
|
|
||||||
|
#ifdef TORRENT_STATS
|
||||||
|
if (m_stats_logger) fclose(m_stats_logger);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
#ifndef TORRENT_NO_DEPRECATE
|
||||||
|
|
Loading…
Reference in New Issue