• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5# for py2/py3 compatibility
6from __future__ import print_function
7
8import os
9import sys
10import json
11import re
12import argparse
13
14sys.path.append(os.environ['PERF_EXEC_PATH'] + \
15  '/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
16
17from perf_trace_context import *
18from Core import *
19
20def trace_begin():
21  json_obj['eventCounts'] = {}
22  prog = re.compile(r'0x[0-9a-fA-F]+')
23  for phase in reversed(json_obj['phases']):
24    if phase['name'] == "disassembly":
25      for line in phase['data'].splitlines():
26        result = re.match(prog, line)
27        if result:
28          known_addrs.add(result.group(0))
29
30def trace_end():
31  print(json.dumps(json_obj))
32
33def process_event(param_dict):
34  addr = "0x%x" % int(param_dict['sample']['ip'])
35
36  # Only count samples that belong to the function
37  if addr not in known_addrs:
38    return
39
40  ev_name = param_dict['ev_name']
41  if ev_name not in json_obj['eventCounts']:
42    json_obj['eventCounts'][ev_name] = {}
43  if addr not in json_obj['eventCounts'][ev_name]:
44    json_obj['eventCounts'][ev_name][addr] = 0
45  json_obj['eventCounts'][ev_name][addr] += 1
46
47if __name__ == "__main__":
48  parser = argparse.ArgumentParser(
49      description="Perf script to merge profiling data with turbofan compiler "
50                  "traces.")
51  parser.add_argument("file_name", metavar="JSON File",
52      help="turbo trace json file.")
53
54  args = parser.parse_args()
55
56  with open(args.file_name, 'r') as json_file:
57    json_obj = json.load(json_file)
58
59  known_addrs = set()
60