2015-07-11 07:51:30 +02:00
|
|
|
#!/usr/bin/env python
|
2008-07-01 20:59:13 +02:00
|
|
|
# Copyright Arvid Norberg 2008. Use, modification and distribution is
|
|
|
|
# subject to the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
2007-09-17 10:15:54 +02:00
|
|
|
import os, sys, time
|
|
|
|
|
|
|
|
lines = open(sys.argv[1], 'rb').readlines()
|
|
|
|
|
2007-09-17 10:54:12 +02:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
print "usage: parse_disk_log.py logfile [seconds]"
|
|
|
|
sys.exit(1)
|
2007-09-17 10:15:54 +02:00
|
|
|
|
2010-01-31 22:13:52 +01:00
|
|
|
keys = ['write', 'read', 'read-cache-hit', 'hash', 'move', 'release', 'idle', \
|
2010-01-12 02:56:48 +01:00
|
|
|
'delete', 'check_fastresume', 'check_files', 'clear-cache', \
|
|
|
|
'abort_thread', 'abort_torrent', 'save_resume_data', 'rename_file', \
|
|
|
|
'flushing', 'update_settings', 'finalize_file', 'sorting_job', \
|
|
|
|
'check_cache_hit']
|
2010-01-31 22:13:52 +01:00
|
|
|
throughput_keys = ['write', 'read', 'read-cache-hit']
|
2007-09-17 10:15:54 +02:00
|
|
|
|
|
|
|
# logfile format:
|
|
|
|
# <time(ms)> <state>
|
|
|
|
# example:
|
|
|
|
# 34523 idle
|
|
|
|
# 34722 write
|
|
|
|
|
2007-09-17 10:54:12 +02:00
|
|
|
if len(sys.argv) > 2:
|
2010-01-12 02:56:48 +01:00
|
|
|
quantization = long(sys.argv[2]) * 1000000
|
2007-09-17 10:54:12 +02:00
|
|
|
else:
|
2010-01-17 09:24:21 +01:00
|
|
|
quantization = 1000000
|
2007-09-17 10:15:54 +02:00
|
|
|
|
|
|
|
out = open('disk_io.dat', 'wb')
|
2007-09-17 10:54:12 +02:00
|
|
|
out2 = open('disk_throughput.dat', 'wb')
|
2007-09-17 10:15:54 +02:00
|
|
|
state = 'idle'
|
2009-06-03 11:27:47 +02:00
|
|
|
time = -1
|
|
|
|
start_time = -1
|
2007-09-17 10:15:54 +02:00
|
|
|
i = 0
|
|
|
|
state_timer = {}
|
2007-09-17 10:54:12 +02:00
|
|
|
throughput = {}
|
2007-09-17 10:15:54 +02:00
|
|
|
for k in keys: state_timer[k] = 0
|
2007-09-17 10:54:12 +02:00
|
|
|
for k in throughput_keys: throughput[k] = 0
|
2010-01-31 22:13:52 +01:00
|
|
|
|
2007-09-17 10:15:54 +02:00
|
|
|
for l in lines:
|
2008-12-30 09:20:25 +01:00
|
|
|
l = l.strip().split()
|
2007-09-17 10:15:54 +02:00
|
|
|
if len(l) < 2:
|
|
|
|
print l
|
|
|
|
continue
|
2008-12-30 09:20:25 +01:00
|
|
|
# try:
|
|
|
|
new_time = long(l[0])
|
2009-06-03 11:27:47 +02:00
|
|
|
if time == -1:
|
|
|
|
time = new_time
|
|
|
|
i = new_time
|
|
|
|
start_time = new_time
|
2008-12-30 09:20:25 +01:00
|
|
|
while new_time > i + quantization:
|
|
|
|
i += quantization
|
|
|
|
state_timer[state] += i - time
|
|
|
|
time = i
|
2008-12-30 19:42:26 +01:00
|
|
|
for k in keys: print >>out, (state_timer[k] / float(quantization) * 100.),
|
2008-12-30 09:20:25 +01:00
|
|
|
print >>out
|
2009-06-03 11:27:47 +02:00
|
|
|
print >>out2, time - start_time,
|
|
|
|
for k in throughput_keys:
|
2010-01-31 22:13:52 +01:00
|
|
|
print >>out2, throughput[k] * 1000 / float(quantization),
|
2009-06-03 11:27:47 +02:00
|
|
|
print '-- %s %d' % (k, throughput[k])
|
2008-12-30 09:20:25 +01:00
|
|
|
print >>out2
|
|
|
|
for k in keys: state_timer[k] = 0
|
|
|
|
for k in throughput_keys: throughput[k] = 0
|
|
|
|
state_timer[state] += new_time - time
|
|
|
|
time = new_time
|
|
|
|
state = l[1]
|
|
|
|
if state in throughput_keys:
|
|
|
|
throughput[state] += long(l[2])
|
|
|
|
# except:
|
|
|
|
# print l
|
2009-06-03 11:27:47 +02:00
|
|
|
|
|
|
|
i += quantization
|
|
|
|
state_timer[state] += i - time
|
|
|
|
time = i
|
|
|
|
for k in keys: print >>out, (state_timer[k] / float(quantization) * 100.),
|
|
|
|
print >>out
|
|
|
|
print >>out2, time - start_time,
|
|
|
|
for k in throughput_keys:
|
2010-01-31 22:13:52 +01:00
|
|
|
print >>out2, throughput[k] * 1000 / float(quantization),
|
2009-06-03 11:27:47 +02:00
|
|
|
print '-- %s %d' % (k, throughput[k])
|
|
|
|
print >>out2
|
|
|
|
for k in keys: state_timer[k] = 0
|
|
|
|
for k in throughput_keys: throughput[k] = 0
|
2007-09-17 10:15:54 +02:00
|
|
|
out.close()
|
2007-09-17 10:54:12 +02:00
|
|
|
out2.close()
|
2007-09-17 10:15:54 +02:00
|
|
|
|
|
|
|
out = open('disk_io.gnuplot', 'wb')
|
|
|
|
print >>out, "set term png size 1200,700"
|
2007-09-17 10:54:12 +02:00
|
|
|
|
|
|
|
print >>out, 'set output "disk_throughput.png"'
|
2010-01-17 09:24:21 +01:00
|
|
|
print >>out, 'set title "disk throughput per %f second(s)"' % (quantization / float(1000000))
|
2008-12-31 19:24:51 +01:00
|
|
|
print >>out, 'set ylabel "throughput (kB/s)"'
|
2007-09-17 10:54:12 +02:00
|
|
|
print >>out, 'plot',
|
|
|
|
i = 0
|
|
|
|
for k in throughput_keys:
|
2010-01-31 22:13:52 +01:00
|
|
|
print >>out, ' "disk_throughput.dat" using 1:%d title "%s" with lines,' % (i + 2, throughput_keys[i]),
|
2007-09-17 10:54:12 +02:00
|
|
|
i = i + 1
|
|
|
|
print >>out, 'x=0'
|
|
|
|
|
2007-09-17 10:15:54 +02:00
|
|
|
print >>out, 'set output "disk_io.png"'
|
2008-12-30 19:42:26 +01:00
|
|
|
print >>out, 'set ylabel "utilization (%)"'
|
2007-09-17 10:54:12 +02:00
|
|
|
print >>out, 'set xrange [0:*]'
|
2010-01-17 09:24:21 +01:00
|
|
|
print >>out, 'set title "disk io utilization per %f second(s)"' % (quantization / float(1000000))
|
2007-09-17 10:15:54 +02:00
|
|
|
print >>out, "set key box"
|
|
|
|
print >>out, "set style data histogram"
|
|
|
|
print >>out, "set style histogram rowstacked"
|
|
|
|
print >>out, "set style fill solid"
|
|
|
|
print >>out, 'plot',
|
|
|
|
i = 0
|
|
|
|
for k in keys:
|
|
|
|
if k != 'idle':
|
|
|
|
print >>out, ' "disk_io.dat" using %d title "%s",' % (i + 1, keys[i]),
|
|
|
|
i = i + 1
|
|
|
|
print >>out, 'x=0'
|
|
|
|
out.close()
|
|
|
|
|
|
|
|
os.system('gnuplot disk_io.gnuplot');
|
|
|
|
|