File: parse_peer_log.py

package info (click to toggle)
libtorrent-rasterbar 2.0.11-3
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 18,304 kB
  • sloc: cpp: 190,670; python: 7,142; makefile: 1,374; ansic: 574; sh: 317; xml: 104
file content (75 lines) | stat: -rwxr-xr-x 2,051 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4

from __future__ import print_function

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')):
    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+')

    uploaded_blocks = 0
    downloaded_blocks = 0

    for line in f:
        t = line.split(': ')[0].split('.')[0]
        log_line = False
        if ' ==> PIECE' in line:
            uploaded_blocks += 1
            log_line = True

        if ' <== PIECE' in line:
            downloaded_blocks += 1
            log_line = True

        if log_line:
            print('%s\t%d\t%d' % (t, uploaded_blocks, downloaded_blocks), file=out)

    out.close()
    f.close()

out = open('peers.gnuplot', 'wb')
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)
first = True
for n in log_files:
    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)

print('set title "downloaded blocks"', file=out)
print('set output "peers_download.png"', file=out)
print('plot', end=' ', file=out)
first = True
for n in log_files:
    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)
out.close()

os.system('gnuplot peers.gnuplot')