session stats improvements

This commit is contained in:
Arvid Norberg 2008-12-27 02:22:20 +00:00
parent 952ed687cd
commit 927f9623cb
2 changed files with 47 additions and 28 deletions

View File

@ -7,32 +7,40 @@ import os, sys, time
ignore = ['download rate', 'disk block buffers']
keys = ['upload rate', 'download rate', 'downloading torrents', \
'seeding torrents', 'peers', 'connecting peers', 'disk block buffers']
stat = open(sys.argv[1])
line = stat.readline()
while not 'second:' in line:
line = stat.readline()
axes = ['x1y2', 'x1y2', 'x1y1', 'x1y1', 'x1y1', 'x1y1', 'x1y1']
keys = line.strip().split(':')[1:]
out = open('session_stats.gnuplot', 'wb')
print >>out, "set term png size 1200,700"
print >>out, 'set output "session_stats.png"'
print >>out, 'set xrange [0:*]'
print >>out, 'set xlabel "time (s)"'
print >>out, 'set ylabel "number"'
print >>out, 'set y2label "Rate (B/s)"'
print >>out, 'set y2range [0:*]'
print >>out, 'set y2tics 20000'
print >>out, "set style data lines"
print >>out, "set key box"
print >>out, 'plot',
column = 2
for k in keys:
if k in ignore:
column = column + 1
continue
print >>out, ' "%s" using 1:%d title "%s" axes %s with steps,' % (sys.argv[1], column, k, axes[column-2]),
column = column + 1
print >>out, 'x=0'
out.close()
axes = ['x1y2', 'x1y2', 'x1y1', 'x1y1', 'x1y1', 'x1y1', 'x1y1', 'x1y1']
os.system('gnuplot session_stats.gnuplot');
def gen_report(name, lines):
out = open('session_stats_%s.gnuplot' % name, 'wb')
print >>out, "set term png size 1200,700"
print >>out, 'set output "session_stats_%s.png"' % name
print >>out, 'set xrange [0:*]'
print >>out, 'set xlabel "time (s)"'
print >>out, 'set ylabel "number"'
print >>out, 'set y2label "Rate (B/s)"'
print >>out, 'set y2range [0:*]'
print >>out, 'set y2tics 10000'
print >>out, "set style data lines"
print >>out, "set key box"
print >>out, 'plot',
column = 2
for k in keys:
if k not in lines:
column = column + 1
continue
print >>out, ' "%s" using 1:%d title "%s" axes %s with steps,' % (sys.argv[1], column, k, axes[column-2]),
column = column + 1
print >>out, 'x=0'
out.close()
os.system('gnuplot session_stats_%s.gnuplot' % name);
gen_report('rates', ['upload rate', 'download rate', 'downloading torrents', 'seeding torrents', 'peers', 'unchoked peers'])
gen_report('peers', ['peers', 'connecting peers', 'unchoked peers'])
gen_report('buffers', ['upload rate', 'download rate', 'disk block buffers'])

View File

@ -243,7 +243,7 @@ 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\n\n";
":peers:connecting peers:disk block buffers:unchoked peers\n\n";
m_buffer_usage_logger.open("buffer_stats.log", std::ios::trunc);
m_second_counter = 0;
m_buffer_allocations = 0;
@ -1036,6 +1036,12 @@ namespace aux {
++m_second_counter;
int downloading_torrents = 0;
int seeding_torrents = 0;
static size_type downloaded = 0;
static size_type uploaded = 0;
size_type download_rate = (m_stat.total_download() - downloaded) / tick_interval;
size_type upload_rate = (m_stat.total_upload() - uploaded) / tick_interval;
downloaded = m_stat.total_download();
uploaded = m_stat.total_upload();
for (torrent_map::iterator i = m_torrents.begin()
, end(m_torrents.end()); i != end; ++i)
{
@ -1046,24 +1052,29 @@ namespace aux {
}
int num_complete_connections = 0;
int num_half_open = 0;
int unchoked_peers = 0;
for (connection_map::iterator i = m_connections.begin()
, end(m_connections.end()); i != end; ++i)
{
if ((*i)->is_connecting())
++num_half_open;
else
{
++num_complete_connections;
if (!(*i)->is_choked()) ++unchoked_peers;
}
}
m_stats_logger
<< m_second_counter << "\t"
<< m_stat.upload_rate() << "\t"
<< m_stat.download_rate() << "\t"
<< upload_rate << "\t"
<< download_rate << "\t"
<< downloading_torrents << "\t"
<< seeding_torrents << "\t"
<< num_complete_connections << "\t"
<< num_half_open << "\t"
<< m_disk_thread.disk_allocations() << "\t"
<< unchoked_peers << "\t"
<< std::endl;
#endif