extract_data.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import re
  2. import sys
  3. def parse_stats(input_string):
  4. # Regular expressions to extract relevant stats
  5. heapsize_pattern = r'heapsize: (\d+)'
  6. insert_stats_pattern = r'===== Insert Stats =====\n([\s\S]*?)\n\n'
  7. extract_stats_pattern = r'===== Extract Min Stats =====\n([\s\S]*?)(?:\n\n|\Z)'
  8. optimized_pattern = r'is_optimized: (\d)'
  9. heapsize = re.search(heapsize_pattern, input_string).group(1)
  10. insert_stats = re.search(insert_stats_pattern, input_string).group(1)
  11. # Handling the case when "Extract Min Stats" is not present
  12. extract_stats_match = re.search(extract_stats_pattern, input_string)
  13. if extract_stats_match:
  14. extract_stats = extract_stats_match.group(1)
  15. else:
  16. extract_stats = ""
  17. optimized = re.search(optimized_pattern, input_string).group(1)
  18. # Extracting insert and extract statistics
  19. insert_stat_values = re.findall(r'(\d+) messages sent\n(\d+) message bytes sent\n(\d+) Lamport clock \(latencies\)\n(\d+) local AES operations\n(\d+) milliseconds wall clock time', insert_stats)
  20. extract_stat_values = re.findall(r'(\d+) messages sent\n(\d+) message bytes sent\n(\d+) Lamport clock \(latencies\)\n(\d+) local AES operations\n(\d+) milliseconds wall clock time', extract_stats)
  21. return {
  22. "heapsize": heapsize,
  23. "is_optimized": optimized,
  24. "insert_stats": insert_stat_values,
  25. "extract_stats": extract_stat_values
  26. }
  27. if __name__ == "__main__":
  28. if len(sys.argv) != 2:
  29. print("Usage: python extract_data.py <filename>")
  30. sys.exit(1)
  31. filename = sys.argv[1]
  32. try:
  33. with open(filename, "r") as file:
  34. input_string = file.read()
  35. except FileNotFoundError:
  36. print(f"Error: File '{filename}' not found.")
  37. sys.exit(1)
  38. parsed_data = parse_stats(input_string)
  39. insert_stats_wallclock = 0
  40. insert_stats_message_bytes = 0
  41. if parsed_data["insert_stats"]:
  42. stat = parsed_data["insert_stats"][0]
  43. insert_stats_wallclock = stat[4]
  44. insert_stats_message_bytes = stat[1]
  45. extract_stats_wallclock = 0
  46. extract_stats_message_bytes = 0
  47. if parsed_data["extract_stats"]:
  48. stat = parsed_data["extract_stats"][0]
  49. extract_stats_wallclock = stat[4]
  50. extract_stats_message_bytes = stat[1]
  51. print(parsed_data["heapsize"])
  52. print(parsed_data["is_optimized"])
  53. print(insert_stats_wallclock)
  54. print(insert_stats_message_bytes)
  55. print(extract_stats_wallclock)
  56. print(extract_stats_message_bytes)