logs_to_csv.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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", "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\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. state = FILE_PARSE_STATE[0]
  33. for m in range(1,M+1):
  34. EOF = False
  35. f = open(os.path.join(LOGS_FOLDER, name, 's'+str(m)+'.log'),'r')
  36. print(os.path.join(LOGS_FOLDER, name, 's'+str(m)+'.log'))
  37. line_cnt = 0
  38. while(1):
  39. line = f.readline()
  40. line_cnt+=1
  41. if(line == ""):
  42. break
  43. elif(state == "ROUND1"):
  44. if("Round 1" in line):
  45. state = "PADDING"
  46. #print("R1: " + str(line_cnt))
  47. elif(state == "ESP"):
  48. if("end storage_received" in line):
  49. value = line.split(' ')[1]
  50. value = value.strip('(')
  51. value = value.strip(')')
  52. stg_time = float(value)
  53. storage_time.append(stg_time)
  54. #print("ESP: " + str(line_cnt))
  55. state = "EPOCH"
  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 == "EPOCH"):
  66. if('Epoch' in line and 'time' in line):
  67. #print("EPOCH: " + str(line_cnt))
  68. nwords = line.split(' ')
  69. epoch_time.append(float(nwords[-2]))
  70. state = "ROUND1"
  71. if(len(epoch_time)!=0):
  72. route_time = []
  73. for i in range(len(epoch_time)):
  74. route_time.append(epoch_time[i] - storage_time[i])
  75. epoch_mean = np.mean(epoch_time)
  76. route_mean = np.mean(route_time)
  77. storage_mean = np.mean(storage_time)
  78. epoch_stddev = np.std(epoch_time)
  79. route_stddev = np.std(route_time)
  80. storage_stddev = np.std(storage_time)
  81. epochs = int(len(epoch_time)/M)
  82. print("Num epochs = %d" % epochs);
  83. print("Epoch time = %f +/- %f" %(epoch_mean, epoch_stddev))
  84. print("Route time = %f +/- %f" %(route_mean, route_stddev))
  85. print("Storage time = %f +/- %f" %(storage_mean, storage_stddev))
  86. # Insert it into the output csv file
  87. op_line = str(n) + ", " + str(M) + ", " + str(t) + ", " + str(b) + ", " + str(epochs) + ", "
  88. op_line+= "{:.4f}".format(epoch_mean) + (", ") + "{:.4f}".format(epoch_stddev) + ", "
  89. op_line+= "{:.4f}".format(route_mean) + (", ") + "{:.4f}".format(route_stddev) + ", "
  90. op_line+= "{:.4f}".format(storage_mean) + (", ") + "{:.4f}".format(storage_stddev) + "\n"
  91. op_file.write(op_line)
  92. else:
  93. print("No valid logs for %s" % name)