raw_to_csv.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. from pathlib import Path
  2. standard_check_file = open("standard_check"+".csv", "w")
  3. standard_check_file.write("Percent,Bridges,RequestS,Rsstdev,RequestT,Rtstdev,ResponseS,Restdev,ResponseT,ReTstdev,ResponseHT,RHTstdev\n")
  4. for p in Path('.').glob('*.log'):
  5. print(f"Parsing: {p.name.strip('.log')}\n")
  6. with p.open() as log_file:
  7. test_file = open(p.name.strip('.log')+".csv", "w")
  8. test_file.write("Percent,Bridges,RequestS,Rsstdev,RequestT,Rtstdev,ResponseS,Restdev,ResponseT,ReTstdev,ResponseHT,RHTstdev\n")
  9. bridges = 0
  10. c=0
  11. red = 0
  12. check = 0
  13. level = 0
  14. protocol = 0
  15. num = 0
  16. req_size = 0
  17. req_size_std = 0
  18. req_time = 0
  19. req_time_std = 0
  20. resp_size = 0
  21. resp_size_std = 0
  22. resp_time = 0
  23. resp_time_std = 0
  24. resp_handle_time = 0
  25. resp_handle_std = 0
  26. endline = 0
  27. # Loop over the remaining lines in the file
  28. for line in log_file:
  29. if "***START" in line:
  30. bridges = line.split()[1].split("*")[0]
  31. if "CHECK-BLOCKAGE" in line:
  32. protocol = 1
  33. num = line.split("-")[6].strip('-')
  34. if int(bridges) == 900:
  35. check =1
  36. if not c:
  37. check_b = open("checkblockage"+str(num)+".csv", "w")
  38. check_b.write("Percent,Bridges,RequestS,Rsstdev,RequestT,Rtstdev,ResponseS,Restdev,ResponseT,ReTstdev,ResponseHT,RHTstdev\n")
  39. c=1
  40. elif "BLOCKAGE-MIGRATION" in line:
  41. protocol = 2
  42. num = line.split("-")[6].strip('-')
  43. elif "REDEEM" in line:
  44. protocol = 3
  45. if not red:
  46. redeem = open("redeem_invites.csv", "w")
  47. redeem.write("Percent,Bridges,RequestS,Rsstdev,RequestT,Rtstdev,ResponseS,Restdev,ResponseT,ReTstdev,ResponseHT,RHTstdev\n")
  48. red = 1
  49. elif "ISSUE" in line:
  50. protocol = 4
  51. elif "OPEN" in line:
  52. protocol = 5
  53. elif "TRUST-PROMOTION" in line:
  54. protocol = 6
  55. if not level:
  56. trust_promo = open("trust_promo.csv", "w")
  57. trust_promo.write("Percent,Bridges,RequestS,Rsstdev,RequestT,Rtstdev,ResponseS,Restdev,ResponseT,ReTstdev,ResponseHT,RHTstdev\n")
  58. elif "TRUST-MIGRATION" in line:
  59. protocol = 7
  60. if not level:
  61. mig_file = open("trust_mig.csv", "w")
  62. mig_file.write("Percent,Bridges,RequestS,Rsstdev,RequestT,Rtstdev,ResponseS,Restdev,ResponseT,ReTstdev,ResponseHT,RHTstdev\n")
  63. elif "LEVEL-UP-2" in line:
  64. protocol = 8
  65. if not level:
  66. level_file = open("level2.csv", "w")
  67. level_file.write("Percent,Bridges,RequestS,Rsstdev,RequestT,Rtstdev,ResponseS,Restdev,ResponseT,ReTstdev,ResponseHT,RHTstdev\n")
  68. elif "LEVEL-UP-3" in line:
  69. protocol = 9
  70. if not level:
  71. level_file_t = open("level3.csv", "w")
  72. level_file_t.write("Percent,Bridges,RequestS,Rsstdev,RequestT,Rtstdev,ResponseS,Restdev,ResponseT,ReTstdev,ResponseHT,RHTstdev\n")
  73. elif "LEVEL-UP-4" in line:
  74. protocol = 10
  75. if not level:
  76. level_file_f = open("level4.csv", "w")
  77. level_file_f.write("Percent,Bridges,RequestS,Rsstdev,RequestT,Rtstdev,ResponseS,Restdev,ResponseT,ReTstdev,ResponseHT,RHTstdev\n")
  78. level = 1
  79. elif protocol:
  80. value = line.split(" = ")
  81. if value[0].startswith("Average"):
  82. if "request" in value[0]:
  83. if "size" in value[0]:
  84. raw_size = value[1].split(" ")
  85. req_size = raw_size[0]
  86. else:
  87. if "µ" in value[1]:
  88. micro_sec = value[1].split("µ")
  89. raw_size = float(micro_sec[0])*0.001
  90. elif "m" not in value[1]:
  91. sec = value[1][:-3]
  92. raw_size = float(sec)*1000
  93. else:
  94. raw_size = value[1][:-3]
  95. req_time = raw_size
  96. else:
  97. if "size" in value[0]:
  98. raw_size = value[1].split(" ")
  99. resp_size = raw_size[0]
  100. else:
  101. if "µ" in value[1]:
  102. micro_sec = value[1].split("µ")
  103. raw_size = float(micro_sec[0])*0.001
  104. elif "m" not in value[1]:
  105. sec = value[1][:-3]
  106. raw_size = float(sec)*1000
  107. else:
  108. raw_size = value[1][:-3]
  109. if "handling" in value[0]:
  110. resp_handle_time = raw_size
  111. else:
  112. resp_time = raw_size
  113. elif value[0].startswith("Request"):
  114. if "size" in value[0]:
  115. raw_size = value[1].split(" ")
  116. req_size_std = raw_size[0]
  117. else:
  118. if "µ" in value[1]:
  119. micro_sec = value[1].split("µ")
  120. to_sec = float(micro_sec[0])*0.001
  121. else:
  122. to_sec = value[1][:-3]
  123. req_time_std = to_sec
  124. elif value[0].startswith("Response"):
  125. if "size" in value[0]:
  126. raw_size = value[1].split(" ")
  127. resp_size_std = raw_size[0]
  128. else:
  129. if "µ" in value[1]:
  130. micro_sec = value[1].split("µ")
  131. to_sec = float(micro_sec[0])*0.001
  132. else:
  133. to_sec = value[1][:-3]
  134. if "handling" in value[0]:
  135. resp_handle_time_std = to_sec
  136. endline = 1
  137. else:
  138. resp_time_std = to_sec
  139. if endline == 1:
  140. if check == 1:
  141. standard_check_file.write(str(num) + "," + str(bridges)+"," + str(req_size) + "," + str(req_size_std) + "," + str(req_time) + "," + str(req_time_std) + "," + str(resp_size) + "," + str(resp_size_std) + "," + str(resp_time) + "," + str(resp_time_std) + "," + str(resp_handle_time) + "," + str(resp_handle_time_std) + "\n")
  142. check = 0
  143. if protocol == 1:
  144. check_b.write(str(num) + "," + str(bridges)+"," + str(req_size) + "," + str(req_size_std) + "," + str(req_time) + "," + str(req_time_std) + "," + str(resp_size) + "," + str(resp_size_std) + "," + str(resp_time) + "," + str(resp_time_std) + "," + str(resp_handle_time) + "," + str(resp_handle_time_std) + "\n")
  145. elif protocol == 3:
  146. redeem.write(str(num) + "," + str(bridges)+"," + str(req_size) + "," + str(req_size_std) + "," + str(req_time) + "," + str(req_time_std) + "," + str(resp_size) + "," + str(resp_size_std) + "," + str(resp_time) + "," + str(resp_time_std) + "," + str(resp_handle_time) + "," + str(resp_handle_time_std) + "\n")
  147. elif protocol<6:
  148. test_file.write(str(num) + "," + str(bridges)+"," + str(req_size) + "," + str(req_size_std) + "," + str(req_time) + "," + str(req_time_std) + "," + str(resp_size) + "," + str(resp_size_std) + "," + str(resp_time) + "," + str(resp_time_std) + "," + str(resp_handle_time) + "," + str(resp_handle_time_std) + "\n")
  149. else:
  150. if protocol == 6:
  151. trust_promo.write(str(num) + "," + str(bridges)+"," + str(req_size) + "," + str(req_size_std) + "," + str(req_time) + "," + str(req_time_std) + "," + str(resp_size) + "," + str(resp_size_std) + "," + str(resp_time) + "," + str(resp_time_std) + "," + str(resp_handle_time) + "," + str(resp_handle_time_std) + "\n")
  152. if protocol == 7:
  153. mig_file.write(str(num) + "," + str(bridges)+"," + str(req_size) + "," + str(req_size_std) + "," + str(req_time) + "," + str(req_time_std) + "," + str(resp_size) + "," + str(resp_size_std) + "," + str(resp_time) + "," + str(resp_time_std) + "," + str(resp_handle_time) + "," + str(resp_handle_time_std) + "\n")
  154. if protocol == 8:
  155. level_file.write(str(num) + "," + str(bridges)+"," + str(req_size) + "," + str(req_size_std) + "," + str(req_time) + "," + str(req_time_std) + "," + str(resp_size) + "," + str(resp_size_std) + "," + str(resp_time) + "," + str(resp_time_std) + "," + str(resp_handle_time) + "," + str(resp_handle_time_std) + "\n")
  156. elif protocol == 9:
  157. level_file_t.write(str(num) + "," + str(bridges)+"," + str(req_size) + "," + str(req_size_std) + "," + str(req_time) + "," + str(req_time_std) + "," + str(resp_size) + "," + str(resp_size_std) + "," + str(resp_time) + "," + str(resp_time_std) + "," + str(resp_handle_time) + "," + str(resp_handle_time_std) + "\n")
  158. elif protocol == 10:
  159. level_file_f.write(str(num) + "," + str(bridges)+"," + str(req_size) + "," + str(req_size_std) + "," + str(req_time) + "," + str(req_time_std) + "," + str(resp_size) + "," + str(resp_size_std) + "," + str(resp_time) + "," + str(resp_time_std) + "," + str(resp_handle_time) + "," + str(resp_handle_time_std) + "\n")
  160. endline = 0
  161. protocol = 0
  162. if level:
  163. level_file.close()
  164. level_file_t.close()
  165. level_file_f.close()
  166. trust_promo.close()
  167. mig_file.close()
  168. if check_b:
  169. check_b.close()
  170. if red:
  171. redeem.close()
  172. test_file.close()
  173. standard_check_file.close()
  174. print("Done.")