2010-03-05 19:12:23 +01:00
#! /usr/bin/env python
2008-07-01 20:59:13 +02:00
# Copyright Arvid Norberg 2008. Use, modification and distribution is
# subject to the Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
2011-03-20 09:58:16 +01:00
import os , sys , time , os
2007-09-29 18:14:03 +02:00
2008-12-27 03:22:20 +01:00
stat = open ( sys . argv [ 1 ] )
line = stat . readline ( )
while not ' second: ' in line :
line = stat . readline ( )
keys = line . strip ( ) . split ( ' : ' ) [ 1 : ]
2009-05-04 09:07:23 +02:00
axes = [ ' x1y2 ' , ' x1y2 ' , ' x1y1 ' , ' x1y1 ' , ' x1y1 ' , ' x1y1 ' , ' x1y1 ' , ' x1y1 ' , ' x1y2 ' ]
2008-12-27 03:22:20 +01:00
2011-03-20 09:58:16 +01:00
output_dir = ' session_stats_report '
def gen_report ( name , unit , lines ) :
try :
os . mkdir ( output_dir )
except : pass
2008-12-27 03:22:20 +01:00
out = open ( ' session_stats_ %s .gnuplot ' % name , ' wb ' )
print >> out , " set term png size 1200,700 "
2011-03-20 09:58:16 +01:00
print >> out , ' set output " %s " ' % ( os . path . join ( output_dir , ' session_stats_ %s .png ' % name ) )
2008-12-27 03:22:20 +01:00
print >> out , ' set xrange [0:*] '
print >> out , ' set xlabel " time (s) " '
2011-03-20 09:58:16 +01:00
print >> out , ' set ylabel " %s " ' % unit
2008-12-27 03:22:20 +01:00
print >> out , ' set y2label " Rate (B/s) " '
print >> out , ' set y2range [0:*] '
2010-01-31 22:13:52 +01:00
print >> out , ' set y2tics auto '
print >> out , " set tics nomirror "
2008-12-27 03:22:20 +01:00
print >> out , " set style data lines "
print >> out , " set key box "
print >> out , ' plot ' ,
column = 2
2011-02-02 04:37:09 +01:00
first = True
2011-03-17 06:31:06 +01:00
for k in lines :
try :
column = keys . index ( k ) + 2
except :
print ' " %s " not found ' % k
continue ;
2011-02-02 04:37:09 +01:00
if not first : print >> out , ' , ' ,
2011-02-04 04:02:23 +01:00
axis = ' x1y1 '
if column - 2 < len ( axes ) : axis = axes [ column - 2 ]
print >> out , ' " %s " using 1: %d title " %s " axes %s with steps ' % ( sys . argv [ 1 ] , column , k , axis ) ,
2011-02-02 04:37:09 +01:00
first = False
2008-12-27 03:22:20 +01:00
column = column + 1
2011-02-02 04:37:09 +01:00
print >> out , ' '
2011-03-20 09:58:16 +01:00
print >> out , " set term png size 300,150 "
print >> out , ' set output " %s " ' % ( os . path . join ( output_dir , ' session_stats_ %s _thumb.png ' % name ) )
print >> out , ' set key off '
print >> out , ' unset tics '
print >> out , ' set format x " " '
print >> out , ' set format y " " '
print >> out , ' set xlabel " " '
print >> out , ' set ylabel " " '
print >> out , ' set y2label " " '
print >> out , " replot "
2008-12-27 03:22:20 +01:00
out . close ( )
2011-03-20 09:58:16 +01:00
os . system ( ' gnuplot session_stats_ %s .gnuplot 2>/dev/null ' % name ) ;
sys . stdout . write ( ' . ' )
sys . stdout . flush ( )
def gen_html ( reports ) :
file = open ( os . path . join ( output_dir , ' index.html ' ) , ' w+ ' )
print >> file , ' <html><body> ' ,
for i in reports :
print >> file , ' <h1> %s </h1><h5> %s </h5><a href= " session_stats_ %s .png " ><img src= " session_stats_ %s _thumb.png " ></a> ' % ( i [ 0 ] , i [ 2 ] , i [ 0 ] , i [ 0 ] ) ,
print >> file , ' </body></html> ' ,
file . close ( )
reports = [
( ' torrents ' , ' num ' , ' ' , [ ' downloading torrents ' , ' seeding torrents ' , ' checking torrents ' , ' stopped torrents ' , ' upload-only torrents ' , ' error torrents ' ] ) ,
( ' peers ' , ' num ' , ' ' , [ ' peers ' , ' connecting peers ' , ' connection attempts ' , ' banned peers ' , ' max connections ' ] ) ,
( ' peers_list_size ' , ' num ' , ' ' , [ ' num list peers ' ] ) ,
( ' overall_rates ' , ' Bytes / second ' , ' ' , [ ' upload rate ' , ' download rate ' , ' smooth upload rate ' , ' smooth download rate ' ] ) ,
( ' disk_queue ' , ' Bytes ' , ' bytes queued up by peers, to be written to disk ' , [ ' disk write queued bytes ' , ' disk queue limit ' , ' disk queue low watermark ' ] ) ,
( ' peers_upload ' , ' num ' , ' number of peers by state wrt. uploading ' , [ ' peers up interested ' , ' peers up unchoked ' , ' peers up requests ' , ' peers disk-up ' , ' peers bw-up ' ] ) ,
( ' peers_download ' , ' num ' , ' number of peers by state wrt. downloading ' , [ ' peers down interesting ' , ' peers down unchoked ' , ' peers down requests ' , ' peers disk-down ' , ' peers bw-down ' ] ) ,
( ' peer_errors ' , ' num ' , ' number of peers by error that disconnected them ' , [ ' error peers ' , ' peer disconnects ' , ' peers eof ' , ' peers connection reset ' , ' connect timeouts ' , ' uninteresting peers disconnect ' , ' banned for hash failure ' ] ) ,
( ' waste ' , ' % o f all downloaded bytes ' , ' proportion of bytes wasted ' , [ ' % f ailed payload bytes ' , ' % wasted payload bytes ' , ' % protocol bytes ' ] ) ,
( ' average_disk_time_absolute ' , ' microseconds ' , ' running averages of timings of disk operations ' , [ ' disk read time ' , ' disk write time ' , ' disk queue time ' , ' disk hash time ' , ' disk job time ' , ' disk sort time ' ] ) ,
( ' disk_time ' , ' % o f total disk job time ' , ' proportion of time spent by the disk thread ' , [ ' % r ead time ' , ' % write time ' , ' % ha sh time ' , ' % s ort time ' ] ) ,
( ' disk_cache_hits ' , ' blocks (16kiB) ' , ' ' , [ ' disk block read ' , ' read cache hits ' , ' disk block written ' , ' disk read back ' ] ) ,
( ' disk_cache ' , ' blocks (16kiB) ' , ' disk cache size and usage ' , [ ' read disk cache size ' , ' disk cache size ' , ' disk buffer allocations ' , ' cache size ' ] ) ,
( ' disk_readback ' , ' % o f written blocks ' , ' ' , [ ' % r ead back ' ] ) ,
# ('disk_queue', 'num', '', ['disk queue size', 'disk queued bytes']),
# ('absolute_waste', 'num', '', ['failed bytes', 'redundant bytes', 'download rate']),
( ' connect_candidates ' , ' num ' , ' number of peers we know of that we can connect to ' , [ ' connect candidates ' ] ) ,
2008-12-27 03:22:20 +01:00
2011-03-20 09:58:16 +01:00
#somewhat uninteresting stats
( ' peer_dl_rates ' , ' num ' , ' ' , [ ' peers down 0 ' , ' peers down 0-2 ' , ' peers down 2-5 ' , ' peers down 5-10 ' , ' peers down 50-100 ' , ' peers down 100- ' ] ) ,
( ' peer_dl_rates2 ' , ' num ' , ' ' , [ ' peers down 0-2 ' , ' peers down 2-5 ' , ' peers down 5-10 ' , ' peers down 50-100 ' , ' peers down 100- ' ] ) ,
( ' peer_ul_rates ' , ' num ' , ' ' , [ ' peers up 0 ' , ' peers up 0-2 ' , ' peers up 2-5 ' , ' peers up 5-10 ' , ' peers up 50-100 ' , ' peers up 100- ' ] ) ,
( ' peer_ul_rates2 ' , ' num ' , ' ' , [ ' peers up 0-2 ' , ' peers up 2-5 ' , ' peers up 5-10 ' , ' peers up 50-100 ' , ' peers up 100- ' ] ) ,
( ' piece_picker_end_game ' , ' ' , ' 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 ' ] ) ,
( ' 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 ' ] ) ,
]
2007-09-29 18:14:03 +02:00
2011-03-20 09:58:16 +01:00
print ' generating graphs \n [ %s ] \r [ ' % ( ' ' * len ( reports ) ) ,
for i in reports : gen_report ( i [ 0 ] , i [ 1 ] , i [ 3 ] )
print ' '
print ' generating html '
gen_html ( reports )