fixed typo
[libtorrent.git] / parse_disk_log.py
blob8b337f1a584e9699cd0f41a9eca60fdf65a8cfd4
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 if len(sys.argv) < 2:
11 print "usage: parse_disk_log.py logfile [seconds]"
12 sys.exit(1)
14 keys = ['write', 'read', 'hash', 'move', 'release', 'idle']
15 throughput_keys = ['write', 'read']
17 # logfile format:
18 # <time(ms)> <state>
19 # example:
20 # 34523 idle
21 # 34722 write
23 if len(sys.argv) > 2:
24 quantization = long(sys.argv[2]) * 1000
25 else:
26 quantization = 5000
28 out = open('disk_io.dat', 'wb')
29 out2 = open('disk_throughput.dat', 'wb')
30 state = 'idle'
31 time = 0
32 i = 0
33 state_timer = {}
34 throughput = {}
35 for k in keys: state_timer[k] = 0
36 for k in throughput_keys: throughput[k] = 0
37 for l in lines:
38 l = l[:-1].split(' ')
39 if len(l) < 2:
40 print l
41 continue
42 try:
43 new_time = long(l[0])
44 while new_time > i + quantization:
45 i += quantization
46 state_timer[state] += i - time
47 time = i
48 for k in keys: print >>out, state_timer[k],
49 print >>out
50 for k in throughput_keys: print >>out2, throughput[k] / 1000.,
51 print >>out2
52 for k in keys: state_timer[k] = 0
53 for k in throughput_keys: throughput[k] = 0
54 state_timer[state] += new_time - time
55 time = new_time
56 state = l[1]
57 if state in throughput_keys:
58 throughput[state] += long(l[2])
59 except:
60 print l
61 out.close()
62 out2.close()
64 out = open('disk_io.gnuplot', 'wb')
65 print >>out, "set term png size 1200,700"
67 print >>out, 'set output "disk_throughput.png"'
68 print >>out, 'set title "disk throughput per %s second(s)"' % (quantization / 1000)
69 print >>out, 'set ylabel "throughput (kB)"'
70 print >>out, 'plot',
71 i = 0
72 for k in throughput_keys:
73 print >>out, ' "disk_throughput.dat" using %d title "%s" with lines,' % (i + 1, throughput_keys[i]),
74 i = i + 1
75 print >>out, 'x=0'
77 print >>out, 'set output "disk_io.png"'
78 print >>out, 'set ylabel "time (ms)"'
79 print >>out, 'set xrange [0:*]'
80 print >>out, 'set title "disk io utilization per %s second(s)"' % (quantization / 1000)
81 print >>out, "set key box"
82 print >>out, "set style data histogram"
83 print >>out, "set style histogram rowstacked"
84 print >>out, "set style fill solid"
85 print >>out, 'plot',
86 i = 0
87 for k in keys:
88 if k != 'idle':
89 print >>out, ' "disk_io.dat" using %d title "%s",' % (i + 1, keys[i]),
90 i = i + 1
91 print >>out, 'x=0'
92 out.close()
94 os.system('gnuplot disk_io.gnuplot');