logs_to_csv.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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", "SCMT"]
  8. '''
  9. parse_output_logs is used in two ways:
  10. (i) For logs_to_csv.py script which produces the output csv given the
  11. LOGS_FOLDER with multiple experiment log folders within it. This is done when
  12. this script is run directly
  13. (ii) For run_experiments, which invokes parse_output_logs with (LOGS_FOLDER,
  14. experiment_name), takes the LOGS_FOLDER pointing to a diagnostic output
  15. folder to extract num_sizes of waksman networks, the WN precomputation time,
  16. epoch time, and send_client_mailbox time.
  17. '''
  18. def parse_output_logs(LOGS_FOLDER, experiment_name, generate_csv = False, op_file = None):
  19. params = experiment_name.split('_')
  20. print (params)
  21. n = int(params[0])
  22. M = int(params[1])
  23. t = int(params[2])
  24. b = int(params[3].strip('/'))
  25. expected_real = math.floor(n/M)
  26. epoch_time = []
  27. # scm = send_client_mailbox
  28. scm_time = []
  29. storage_time = []
  30. # pwn = precompute_Waksman_Network
  31. pwn_time = []
  32. bytes_sent = 0
  33. num_sizes = 0
  34. state = FILE_PARSE_STATE[0]
  35. for m in range(1,M+1):
  36. EOF = False
  37. f = open(os.path.join(LOGS_FOLDER, experiment_name, 's'+str(m)+'.log'),'r')
  38. print(os.path.join(LOGS_FOLDER, experiment_name, 's'+str(m)+'.log'))
  39. line_cnt = 0
  40. while(1):
  41. line = f.readline()
  42. line_cnt+=1
  43. if(line == ""):
  44. break
  45. if('end precompute Waksman Network' in line):
  46. value = line.split(' ')[1]
  47. value = value.strip('(')
  48. value = value.strip(')')
  49. pwn_time.append(float(value))
  50. if('Precompute num_sizes' in line):
  51. value = line.split(' ')[-1]
  52. num_sizes = int(value)
  53. elif(state == "ROUND1"):
  54. if("Round 1 " in line):
  55. state = "PADDING"
  56. #print("R1: " + str(line_cnt))
  57. elif(state == "ESP"):
  58. if("end storage processing" in line):
  59. value = line.split(' ')[1]
  60. value = value.strip('(')
  61. value = value.strip(')')
  62. stg_time = float(value)
  63. storage_time.append(stg_time)
  64. state = "BYTES"
  65. elif(state == "PADDING"):
  66. if('padding' in line):
  67. #print("PADDING: " + str(line_cnt))
  68. words = line.split(' ')
  69. log_real = int(words[0])
  70. if(log_real >= expected_real):
  71. state = "ESP"
  72. else:
  73. state = "ROUND1"
  74. elif(state == "BYTES"):
  75. if('bytes_sent' in line):
  76. words = line.split(' ')
  77. bytes_sent = int(words[-1])
  78. state = "EPOCH"
  79. elif(state == "EPOCH"):
  80. if('Epoch' in line and 'time' in line):
  81. #print("EPOCH: " + str(line_cnt))
  82. nwords = line.split(' ')
  83. epoch_time.append(float(nwords[-2]))
  84. state = "SCMT"
  85. elif(state == "SCMT"):
  86. if('send_client_mailbox time' in line):
  87. scm_time = float(line.split(' ')[-2])
  88. state = "ROUND1"
  89. if(len(epoch_time)!=0):
  90. route_time = []
  91. for i in range(len(epoch_time)):
  92. route_time.append(epoch_time[i] - storage_time[i])
  93. epoch_mean = np.mean(epoch_time)
  94. route_mean = np.mean(route_time)
  95. storage_mean = np.mean(storage_time)
  96. scm_mean = np.mean(scm_time)
  97. pwn_mean = np.mean(pwn_time)
  98. epoch_max = np.max(epoch_time)
  99. scm_max = np.max(scm_time)
  100. pwn_max = np.max(pwn_time)
  101. epoch_stddev = np.std(epoch_time)
  102. route_stddev = np.std(route_time)
  103. storage_stddev = np.std(storage_time)
  104. scm_stddev = np.std(scm_time)
  105. pwn_stddev = np.mean(pwn_time)
  106. epochs = int(len(epoch_time)/M)
  107. print("Num epochs = %d" % epochs);
  108. print("Route time = %f +/- %f" %(route_mean, route_stddev))
  109. print("Storage time = %f +/- %f" %(storage_mean, storage_stddev))
  110. print("Epoch time = %f +/- %f (Max epoch_time = %f)" %(epoch_mean, epoch_stddev, epoch_max))
  111. print("PWN time = %f +/- %f (Max PWN = %f)" %(pwn_mean, pwn_stddev, pwn_max))
  112. print("SCM time = %f +/- %f (Max SCM = %f)" %(scm_mean, scm_stddev, scm_max))
  113. if(generate_csv):
  114. # Insert it into the output csv file
  115. op_line = str(n) + "," + str(M) + "," + str(t) + "," + str(b) + "," + str(epochs) + ","
  116. op_line+= "{:.4f}".format(epoch_mean) + (",") + "{:.4f}".format(epoch_stddev) + ","
  117. op_line+= "{:.4f}".format(route_mean) + (",") + "{:.4f}".format(route_stddev) + ","
  118. op_line+= "{:.4f}".format(storage_mean) + (",") + "{:.4f}".format(storage_stddev) + ","
  119. op_line+= str(bytes_sent) + "\n"
  120. op_file.write(op_line)
  121. else:
  122. return(num_sizes, pwn_max, epoch_max, scm_max)
  123. else:
  124. print("No valid logs for %s" % LOGS_FOLDER)
  125. if __name__ == "__main__":
  126. if(len(sys.argv)!=3):
  127. print("Incorrect usage!\n")
  128. print("./logs_to_csv.py expects 2 parameters.")
  129. print("Usage: ./logs_to_csv.py <Path to logs folder> <output csv file name>")
  130. exit()
  131. LOGS_FOLDER = sys.argv[1]
  132. OUTPUT_FILE = sys.argv[2]
  133. op_file = open(OUTPUT_FILE, 'w+')
  134. op_file.write("N,M,T,B,E,epoch_total_time,epoch_stddev,\
  135. route_time,route_stddev,storage_time,storage_stddev,bytes_sent\n")
  136. for exp_name in os.listdir(LOGS_FOLDER):
  137. parse_output_logs(LOGS_FOLDER, exp_name, True, op_file)
  138. op_file.close()