Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import time, sys
- import numpy as np
- import statistics as st
- time_start = []
- time_end = []
- trans_size = []
- trans_speed = []
- stat_size = []
- stat_speed = []
- stat_aver = []
- stat_var = []
- # Read log file
- if len(sys.argv) > 1:
- file = open(sys.argv[1], 'r')
- else:
- file = open('test.log', 'r')
- for line in file:
- if 'ItemStarted' in line:
- words = line.split()
- time_sec = time.strptime(words[1] + ' ' + words[2].split('.')[0], "%Y/%m/%d %H:%M:%S")
- time_start.append(time.mktime(time_sec))
- elif 'LocalIndexUpdated' in line:
- words = line.split()
- time_sec = time.strptime(words[1] + ' ' + words[2].split('.')[0], "%Y/%m/%d %H:%M:%S")
- time_end.append(time.mktime(time_sec))
- for parse in words:
- if 'size:' in parse:
- parse = parse.replace(']', '')
- trans_size.append(float(parse.split(':')[1]))
- # Check consistency of table sizes, attempt to correct
- if len(time_end) != len(trans_size):
- print('[ERROR] Incoherent data! Exiting...')
- exit(1)
- while len(time_start) != len(time_end):
- print('[WARNING] An element has been removed from the time_start list...')
- time_start.pop()
- # Calculate transfer speeds in MBps
- trans_speed = np.divide(trans_size, np.subtract(time_end, time_start))
- n_run = len(time_end)
- # Create table for statistics:
- # - stat_size contains the possible file sizes
- # - stat_speed is a 2-D list of the transfer speeds per file size
- #
- # The idea is to have a table like this:
- #
- # file1 file2 file3 file4
- # 2.1 MBps 7.3 MBps 0.5 MBps 4.2 MBps
- # 2.2 MBps 7.1 MBps 0.3 MBps 4.1 MBps
- # 2.0 MBps 7.2 MBps 0.8 MBps 4.7 MBps
- # 2.4 MBps 7.5 MBps 0.2 MBps 4.6 MBps
- for i in range(n_run):
- if trans_size[i] not in stat_size:
- stat_size.append(trans_size[i])
- stat_speed.append([])
- for i in range(n_run):
- idx = stat_size.index(trans_size[i])
- stat_speed[idx].append(trans_speed[i])
- # Print results, grouped by file size
- n_file = len(stat_size)
- for j in range(n_file):
- print()
- print("File size:", round(stat_size[j]/1048576, 2), "MB")
- print ("Run # Speed (MBps)")
- for jj in range(len(stat_speed[j])):
- print(repr(jj+1).rjust(5), '%15.3f' % float(stat_speed[j][jj]/1048576))
- print("Speed average: %8.2f" % float(st.mean(stat_speed[j])/1048576), "MBps")
- if len(stat_speed[j]) > 1:
- print(" std. dev.: %8.2f" % float(st.stdev(stat_speed[j])/1048576), "MBps")
- exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement