2013-06-02 00:33:11 +02:00
|
|
|
#!/usr/bin/env python
|
2018-06-16 16:12:18 +02:00
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2013-06-02 00:33:11 +02:00
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# usage: parse_peer_log <path-to-libtorrent-peer-logs>
|
|
|
|
|
|
|
|
log_files = []
|
|
|
|
|
|
|
|
for p in glob.iglob(os.path.join(sys.argv[1], '*.log')):
|
2018-06-12 11:43:13 +02:00
|
|
|
name = os.path.split(p)[1]
|
|
|
|
if name == 'main_session.log':
|
|
|
|
continue
|
|
|
|
print(name)
|
|
|
|
f = open(p, 'r')
|
|
|
|
out_file = p + '.dat'
|
|
|
|
log_files.append(out_file)
|
|
|
|
out = open(out_file, 'w+')
|
2013-06-02 00:33:11 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
uploaded_blocks = 0
|
|
|
|
downloaded_blocks = 0
|
2013-06-02 00:33:11 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
for l in f:
|
|
|
|
t = l.split(': ')[0].split('.')[0]
|
|
|
|
log_line = False
|
|
|
|
if ' ==> PIECE' in l:
|
|
|
|
uploaded_blocks += 1
|
|
|
|
log_line = True
|
2013-06-02 00:33:11 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
if ' <== PIECE' in l:
|
|
|
|
downloaded_blocks += 1
|
|
|
|
log_line = True
|
2013-06-02 00:33:11 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
if log_line:
|
|
|
|
print('%s\t%d\t%d' % (t, uploaded_blocks, downloaded_blocks), file=out)
|
2013-06-02 00:33:11 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
out.close()
|
|
|
|
f.close()
|
2013-06-02 00:33:11 +02:00
|
|
|
|
|
|
|
out = open('peers.gnuplot', 'wb')
|
2018-06-12 11:43:13 +02:00
|
|
|
print("set term png size 1200,700", file=out)
|
|
|
|
print('set xrange [0:*]', file=out)
|
|
|
|
print('set xlabel "time"', file=out)
|
|
|
|
print('set ylabel "blocks"', file=out)
|
|
|
|
print('set key box', file=out)
|
|
|
|
print('set xdata time', file=out)
|
|
|
|
print('set timefmt "%H:%M:%S"', file=out)
|
|
|
|
print('set title "uploaded blocks"', file=out)
|
|
|
|
print('set output "peers_upload.png"', file=out)
|
|
|
|
print('plot', end=' ', file=out)
|
2013-06-02 00:33:11 +02:00
|
|
|
first = True
|
|
|
|
for n in log_files:
|
2018-06-12 11:43:13 +02:00
|
|
|
if not first:
|
|
|
|
print(',', end=' ', file=out)
|
|
|
|
first = False
|
|
|
|
print(' "%s" using 1:2 title "%s" with steps' % (n, os.path.split(n)[1].split('.log')[0]), end=' ', file=out)
|
|
|
|
print('', file=out)
|
2013-06-02 00:33:11 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
print('set title "downloaded blocks"', file=out)
|
|
|
|
print('set output "peers_download.png"', file=out)
|
|
|
|
print('plot', end=' ', file=out)
|
2013-06-02 00:33:11 +02:00
|
|
|
first = True
|
|
|
|
for n in log_files:
|
2018-06-12 11:43:13 +02:00
|
|
|
if not first:
|
|
|
|
print(',', end=' ', file=out)
|
|
|
|
first = False
|
|
|
|
print(' "%s" using 1:3 title "%s" with steps' % (n, os.path.split(n)[1].split('.log')[0]), end=' ', file=out)
|
|
|
|
print('', file=out)
|
2013-06-02 00:33:11 +02:00
|
|
|
out.close()
|
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
os.system('gnuplot peers.gnuplot')
|