logs_to_csv.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/python3
  2. import subprocess
  3. import os
  4. import sys
  5. import math
  6. import numpy as np
  7. FILE_PARSE_STATE = ["ROUND1", "ESP", "BYTES", "PADDING", "EPOCH"]
  8. if __name__ == "__main__":
  9. if(len(sys.argv)!=3):
  10. print("Incorrect usage!\n")
  11. print("./logs_to_csv.py expects 2 parameters.")
  12. print("Usage: ./logs_to_csv.py <Path to logs folder> <output csv file name>")
  13. exit()
  14. LOGS_FOLDER = sys.argv[1]
  15. OUTPUT_FILE = sys.argv[2]
  16. op_file = open(OUTPUT_FILE, 'w+')
  17. op_file.write("N,M,T,B,E,epoch_total_time,epoch_stddev,\
  18. route_time,route_stddev,storage_time,storage_stddev,bytes_sent\n")
  19. # Iterate over each folder in LOGS_FOLDER
  20. for name in os.listdir(LOGS_FOLDER):
  21. #print(name)
  22. params = name.split('_')
  23. print (params)
  24. n = int(params[0])
  25. M = int(params[1])
  26. t = int(params[2])
  27. b = int(params[3])
  28. expected_real = math.floor(n/M)
  29. print(name)
  30. epoch_time = []
  31. storage_time = []
  32. bytes_sent = 0
  33. state = FILE_PARSE_STATE[0]
  34. for m in range(1,M+1):
  35. EOF = False
  36. f = open(os.path.join(LOGS_FOLDER, name, 's'+str(m)+'.log'),'r')
  37. print(os.path.join(LOGS_FOLDER, name, 's'+str(m)+'.log'))
  38. line_cnt = 0
  39. while(1):
  40. line = f.readline()
  41. line_cnt+=1
  42. if(line == ""):
  43. break
  44. elif(state == "ROUND1"):
  45. if("Round 1" in line):
  46. state = "PADDING"
  47. #print("R1: " + str(line_cnt))
  48. elif(state == "ESP"):
  49. if("end storage processing" in line):
  50. value = line.split(' ')[1]
  51. value = value.strip('(')
  52. value = value.strip(')')
  53. stg_time = float(value)
  54. storage_time.append(stg_time)
  55. state = "BYTES"
  56. elif(state == "PADDING"):
  57. if('padding' in line):
  58. #print("PADDING: " + str(line_cnt))
  59. words = line.split(' ')
  60. log_real = int(words[0])
  61. if(log_real >= expected_real):
  62. state = "ESP"
  63. else:
  64. state = "ROUND1"
  65. elif(state == "BYTES"):
  66. if('bytes_sent' in line):
  67. words = line.split(' ')
  68. bytes_sent = int(words[-1])
  69. state = "EPOCH"
  70. elif(state == "EPOCH"):
  71. if('Epoch' in line and 'time' in line):
  72. #print("EPOCH: " + str(line_cnt))
  73. nwords = line.split(' ')
  74. epoch_time.append(float(nwords[-2]))
  75. state = "ROUND1"
  76. if(len(epoch_time)!=0):
  77. route_time = []
  78. for i in range(len(epoch_time)):
  79. route_time.append(epoch_time[i] - storage_time[i])
  80. epoch_mean = np.mean(epoch_time)
  81. route_mean = np.mean(route_time)
  82. storage_mean = np.mean(storage_time)
  83. epoch_stddev = np.std(epoch_time)
  84. route_stddev = np.std(route_time)
  85. storage_stddev = np.std(storage_time)
  86. epochs = int(len(epoch_time)/M)
  87. print("Num epochs = %d" % epochs);
  88. print("Epoch time = %f +/- %f" %(epoch_mean, epoch_stddev))
  89. print("Route time = %f +/- %f" %(route_mean, route_stddev))
  90. print("Storage time = %f +/- %f" %(storage_mean, storage_stddev))
  91. # Insert it into the output csv file
  92. op_line = str(n) + "," + str(M) + "," + str(t) + "," + str(b) + "," + str(epochs) + ","
  93. op_line+= "{:.4f}".format(epoch_mean) + (",") + "{:.4f}".format(epoch_stddev) + ","
  94. op_line+= "{:.4f}".format(route_mean) + (",") + "{:.4f}".format(route_stddev) + ","
  95. op_line+= "{:.4f}".format(storage_mean) + (",") + "{:.4f}".format(storage_stddev) + ","
  96. op_line+= str(bytes_sent) + "\n"
  97. op_file.write(op_line)
  98. else:
  99. print("No valid logs for %s" % name)