prac_parser.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import re
  2. import sys
  3. # Regular expressions to match the relevant log lines
  4. insert_stats_regex = r"===== Insert Stats =====\n(\d+) messages sent\n(\d+) message bytes sent\n(\d+) Lamport clock \(latencies\)\n(\d+) local AES operations\n(\d+) milliseconds wall clock time\n\{(\d+);(\d+);(\d+)\} nanoseconds \{real;user;system\}\nMem: (\d+) KiB"
  5. extract_stats_regex = r"===== Extract Min Stats =====\n(\d+) messages sent\n(\d+) message bytes sent\n(\d+) Lamport clock \(latencies\)\n(\d+) local AES operations\n(\d+) milliseconds wall clock time\n\{(\d+);(\d+);(\d+)\} nanoseconds \{real;user;system\}\nMem: (\d+) KiB"
  6. # Function to parse insert and extract stats
  7. def parse_logs(log_file):
  8. with open(log_file, "r") as file:
  9. log_data = file.read()
  10. insert_stats = re.findall(insert_stats_regex, log_data)
  11. extract_stats = re.findall(extract_stats_regex, log_data)
  12. return insert_stats, extract_stats
  13. # Function to print stats table
  14. def print_stats_table(stats):
  15. print("Messages Sent | Message Bytes Sent | Lamport Clock | Local AES Operations | Wall Clock Time (ms) | Real Time | User Time | System Time | Memory (KiB)")
  16. print("-" * 117)
  17. for stat in stats:
  18. print("{:14} | {:19} | {:13} | {:21} | {:21} | {:10} | {:9} | {:12} | {:12}".format(*stat))
  19. print()
  20. if len(sys.argv) != 2:
  21. print("Usage: python log_parser.py <log_file>")
  22. sys.exit(1)
  23. log_file = sys.argv[1]
  24. # Parse logs and print stats table
  25. insert_stats, extract_stats = parse_logs(log_file)
  26. print("Insert Stats:")
  27. print_stats_table(insert_stats)
  28. print("Extract Min Stats:")
  29. print_stats_table(extract_stats)