fixed bug in windows path of file.cpp
[libtorrent.git] / parse_buffer_log.py
blob36ffb594f947c66f997160b2724d16ad23d2db5f
1 #!/bin/python
2 # Copyright Arvid Norberg 2008. Use, modification and distribution is
3 # subject to the Boost Software License, Version 1.0. (See accompanying
4 # file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 import os, sys, time
8 lines = open(sys.argv[1], 'rb').readlines()
10 #keys = ['send_buffer_utilization']
11 keys = ['send_buffer_size', 'used_send_buffer', 'protocol_buffer']
12 #keys = ['send_buffer_alloc', 'send_buffer', 'allocate_buffer_alloc', 'allocate_buffer', 'protocol_buffer']
13 #keys = ['send_buffer_alloc', 'send_buffer', 'allocate_buffer_alloc', 'allocate_buffer', 'protocol_buffer', 'append_send_buffer']
15 average = ['send_buffer_utilization', 'send_buffer_size', 'used_send_buffer']
16 average_interval = 120000
17 render = 'lines'
19 time_limit = -1
20 if len(sys.argv) > 2:
21 time_limit = long(sys.argv[2])
24 # logfile format:
25 # <time(ms)> <key> <value>
26 # example:
27 # 16434 allocate_buffer: 17
28 for k in keys:
30 last_sample = 0
31 average_accumulator = 0
32 average_samples = 0
33 peak = 0
35 out = open(k + '.dat', 'wb')
36 eval_average = False
37 if k in average:
38 eval_average = True
39 peak_out = open(k + '_peak.dat', 'wb')
41 for l in lines:
42 l = l.split(' ')
43 if len(l) != 3:
44 print l
45 continue
46 try:
47 if l[1] == k + ':':
48 if time_limit != -1 and long(l[0]) > time_limit: break
49 time = l[0]
50 value = l[2]
51 if eval_average:
52 while long(time) > last_sample + average_interval:
53 last_sample = last_sample + average_interval
54 if average_samples < 1: average_samples = 1
55 print >>out, '%d %f' % (last_sample, average_accumulator / average_samples)
56 print >>peak_out, '%d %f' % (last_sample, peak)
57 average_accumulator = 0
58 average_samples = 0
59 peak = 0
60 average_accumulator = average_accumulator + float(value)
61 average_samples = average_samples + 1
62 if float(value) > peak: peak = float(value)
63 else:
64 print >>out, time + ' ' + value,
65 except:
66 print l
68 out.close()
69 peak_out.close()
71 out = open('send_buffer.gnuplot', 'wb')
72 print >>out, "set term png size 1200,700"
73 print >>out, 'set output "send_buffer.png"'
74 print >>out, 'set xrange [0:*]'
75 print >>out, 'set xlabel "time (ms)"'
76 print >>out, 'set ylabel "bytes (B)"'
77 print >>out, "set style data lines"
78 print >>out, "set key box"
79 print >>out, 'plot',
80 for k in keys:
81 if k in average:
82 print >>out, ' "%s.dat" using 1:2 title "%s %d seconds average" with %s,' % (k, k, average_interval / 1000., render),
83 print >>out, ' "%s_peak.dat" using 1:2 title "%s %d seconds peak" with %s,' % (k, k, average_interval / 1000., render),
84 else:
85 print >>out, ' "%s.dat" using 1:2 title "%s" with %s,' % (k, k, render),
86 print >>out, 'x=0'
87 out.close()
89 os.system('gnuplot send_buffer.gnuplot')