wasm_parser 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/usr/bin/env python3
  2. # Usage: ./wasm_parser
  3. # Be sure that the uploaded_log file is in the current directory
  4. import os
  5. import re
  6. import subprocess
  7. import statistics
  8. import sys
  9. protocol = None
  10. protocol_map = {
  11. 'blockage-migration': 'Blockage Migration',
  12. 'check-blockage': 'Check Blockage',
  13. 'issue-invite': 'Issue Invite',
  14. 'level-up': 'Level Up',
  15. 'migration': 'Trust Migration',
  16. 'open-invite': 'Open Invitation',
  17. 'redeem-invite': 'Redeem Invite',
  18. 'trust-promo': 'Trust Promotion',
  19. 'update-cred': 'Update Credential',
  20. 'update-invite': 'Update Invite',
  21. }
  22. req_time = {}
  23. handle_time = {}
  24. inv = {}
  25. time = {}
  26. std = {}
  27. def parse_files(log):
  28. for line in log:
  29. if matched := re.match(r'Dump buffer:\s+\".*?(\S+) client (request|handle reply) time ([\d\.]+)\s*ms', line):
  30. protocol = protocol_map[matched.group(1)]
  31. val = matched.group(3)
  32. if matched.group(2) == "request":
  33. if protocol in req_time:
  34. req_time[protocol].append(float(val))
  35. else:
  36. req_time.setdefault(protocol, []).append(float(val))
  37. else:
  38. if protocol in handle_time:
  39. handle_time[protocol].append(float(val))
  40. else:
  41. handle_time.setdefault(protocol, []).append(float(val))
  42. for protocol in req_time:
  43. inv[protocol] = list(map(lambda x, y: x + y, handle_time[protocol], req_time[protocol]))
  44. time[protocol] = sum(inv[protocol])/len(req_time[protocol])
  45. std[protocol] = statistics.stdev(inv[protocol])
  46. with open("uploaded_log", "r") as uploaded:
  47. parse_files(uploaded)
  48. # The order in which we output the protocols
  49. protocol_list = [
  50. 'Open Invitation',
  51. 'Trust Promotion',
  52. 'Trust Migration',
  53. 'Level Up',
  54. 'Issue Invite',
  55. 'Redeem Invite',
  56. 'Check Blockage',
  57. 'Blockage Migration',
  58. 'Update Invite',
  59. 'Update Credential',
  60. ]
  61. print("\n=== Table 2 ===\n")
  62. print("protocol,client wasm ms")
  63. for p in protocol_list:
  64. print(f"{p},{time[p]:.3f} ({std[p]:.3f})")