Advertisement
Guest User

Untitled

a guest
Dec 12th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import time, sys
  4. import numpy as np
  5. import statistics as st
  6.  
  7. time_start  = []
  8. time_end    = []
  9. trans_size  = []
  10. trans_speed = []
  11. stat_size   = []
  12. stat_speed  = []
  13. stat_aver   = []
  14. stat_var    = []
  15.  
  16. # Read log file
  17.  
  18.  
  19. if len(sys.argv) > 1:
  20.     file = open(sys.argv[1], 'r')
  21. else:
  22.     file = open('test.log', 'r')
  23.  
  24. for line in file:
  25.     if 'ItemStarted' in line:
  26.         words = line.split()
  27.         time_sec = time.strptime(words[1] + ' ' + words[2].split('.')[0], "%Y/%m/%d %H:%M:%S")
  28.         time_start.append(time.mktime(time_sec))
  29.  
  30.     elif 'LocalIndexUpdated' in line:
  31.         words = line.split()
  32.         time_sec = time.strptime(words[1] + ' ' + words[2].split('.')[0], "%Y/%m/%d %H:%M:%S")
  33.         time_end.append(time.mktime(time_sec))
  34.         for parse in words:
  35.             if 'size:' in parse:
  36.                 parse = parse.replace(']', '')
  37.                 trans_size.append(float(parse.split(':')[1]))
  38.  
  39. # Check consistency of table sizes, attempt to correct
  40.  
  41. if len(time_end) != len(trans_size):
  42.     print('[ERROR] Incoherent data! Exiting...')
  43.     exit(1)
  44.  
  45. while len(time_start) != len(time_end):
  46.     print('[WARNING] An element has been removed from the time_start list...')
  47.     time_start.pop()
  48.  
  49. # Calculate transfer speeds in MBps
  50.    
  51. trans_speed = np.divide(trans_size, np.subtract(time_end, time_start))
  52. n_run = len(time_end)
  53.  
  54. # Create table for statistics:
  55. #     - stat_size contains the possible file sizes
  56. #     - stat_speed is a 2-D list of the transfer speeds per file size
  57. #
  58. # The idea is to have a table like this:
  59. #
  60. #     file1      file2      file3      file4
  61. #  2.1 MBps   7.3 MBps   0.5 MBps   4.2 MBps
  62. #  2.2 MBps   7.1 MBps   0.3 MBps   4.1 MBps
  63. #  2.0 MBps   7.2 MBps   0.8 MBps   4.7 MBps
  64. #  2.4 MBps   7.5 MBps   0.2 MBps   4.6 MBps
  65.  
  66.  
  67. for i in range(n_run):
  68.     if trans_size[i] not in stat_size:
  69.         stat_size.append(trans_size[i])
  70.         stat_speed.append([])
  71.  
  72.  
  73. for i in range(n_run):
  74.     idx = stat_size.index(trans_size[i])
  75.     stat_speed[idx].append(trans_speed[i])
  76.  
  77. # Print results, grouped by file size
  78.  
  79. n_file = len(stat_size)
  80. for j in range(n_file):
  81.     print()
  82.  
  83.     print("File size:", round(stat_size[j]/1048576, 2), "MB")
  84.  
  85.     print ("Run #    Speed (MBps)")
  86.  
  87.     for jj in range(len(stat_speed[j])):
  88.         print(repr(jj+1).rjust(5), '%15.3f' % float(stat_speed[j][jj]/1048576))
  89.  
  90.     print("Speed average:   %8.2f" % float(st.mean(stat_speed[j])/1048576), "MBps")
  91.     if len(stat_speed[j]) > 1:
  92.         print("      std. dev.: %8.2f" % float(st.stdev(stat_speed[j])/1048576), "MBps")
  93.  
  94.  
  95. exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement