replaced std::isprint with one that is not dependent on locale. Fixes #384
[libtorrent.git] / parse_dht_log.py
blob51af6525e4af1d914fe1d99f15a0d237719aef42
1 import sys
2 import os
4 up_time_quanta = 60
6 f = open(sys.argv[1])
8 announce_histogram = {}
9 node_uptime_histogram = {}
11 for i in xrange(0, 50): announce_histogram[i] = 0
12 for i in xrange(0, 5000, up_time_quanta): node_uptime_histogram[i] = 0
14 counter = 0;
16 for line in f:
17 counter += 1
18 if counter % 1000 == 0:
19 print '\r%d' % counter,
20 try:
21 if 'distance:' in line:
22 l = line.split(' ')
24 d = int(l[4])
25 announce_histogram[d] += 1
26 if 'NODE FAILED' in line:
27 l = line.split(' ')
28 if int(l[9]) != 1: continue;
29 d = int(l[11])
30 node_uptime_histogram[d - (d % up_time_quanta)] += 1
31 except:
32 print line.split(' ')
34 out = open('dht_announce_distribution.dat', 'w+')
35 for k,v in announce_histogram.items():
36 print >>out, '%d %d' % (k, v)
37 out.close()
39 out = open('dht_node_uptime_distribution.dat', 'w+')
40 for k,v in node_uptime_histogram.items():
41 print >>out, '%d %d' % (k + up_time_quanta/2, v)
42 out.close()
44 out = open('dht.gnuplot', 'w+')
45 out.write('''
46 set term png size 1200,700 small
47 set output "dht_announce_distribution.png"
48 set title "bucket # announces are made against relative to target node-id"
49 set ylabel "# of announces"
50 set style fill solid border -1 pattern 2
51 plot "dht_announce_distribution.dat" using 1:2 title "announces" with boxes
53 set terminal postscript
54 set output "dht_announce_distribution.ps"
55 replot
57 set term png size 1200,700 small
58 set output "dht_node_uptime_distribution.png"
59 set title "node up time"
60 set ylabel "# of nodes"
61 set xlabel "uptime (seconds)"
62 set boxwidth %f
63 set style fill solid border -1 pattern 2
64 plot "dht_node_uptime_distribution.dat" using 1:2 title "nodes" with boxes
65 ''' % up_time_quanta)
66 out.close()
68 os.system('gnuplot dht.gnuplot');