turbolizer-perf.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # Copyright 2016 the V8 project authors. All rights reserved.
  2. # Use of this source code is governed by a BSD-style license that can be
  3. # found in the LICENSE file.
  4. # for py2/py3 compatibility
  5. from __future__ import print_function
  6. import os
  7. import sys
  8. import json
  9. import re
  10. import argparse
  11. sys.path.append(os.environ['PERF_EXEC_PATH'] + \
  12. '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
  13. from perf_trace_context import *
  14. from Core import *
  15. def trace_begin():
  16. json_obj['eventCounts'] = {}
  17. prog = re.compile(r'0x[0-9a-fA-F]+')
  18. for phase in reversed(json_obj['phases']):
  19. if phase['name'] == "disassembly":
  20. for line in phase['data'].splitlines():
  21. result = re.match(prog, line)
  22. if result:
  23. known_addrs.add(result.group(0))
  24. def trace_end():
  25. print(json.dumps(json_obj))
  26. def process_event(param_dict):
  27. addr = "0x%x" % int(param_dict['sample']['ip'])
  28. # Only count samples that belong to the function
  29. if addr not in known_addrs:
  30. return
  31. ev_name = param_dict['ev_name']
  32. if ev_name not in json_obj['eventCounts']:
  33. json_obj['eventCounts'][ev_name] = {}
  34. if addr not in json_obj['eventCounts'][ev_name]:
  35. json_obj['eventCounts'][ev_name][addr] = 0
  36. json_obj['eventCounts'][ev_name][addr] += 1
  37. if __name__ == "__main__":
  38. parser = argparse.ArgumentParser(
  39. description="Perf script to merge profiling data with turbofan compiler "
  40. "traces.")
  41. parser.add_argument("file_name", metavar="JSON File",
  42. help="turbo trace json file.")
  43. args = parser.parse_args()
  44. with open(args.file_name, 'r') as json_file:
  45. json_obj = json.load(json_file)
  46. known_addrs = set()