OLD | NEW |
1 #! /usr/bin/python | 1 #! /usr/bin/python |
2 # | 2 # |
3 # Copyright 2016 the V8 project authors. All rights reserved. | 3 # Copyright 2016 the V8 project authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 # | 6 # |
7 | 7 |
8 import argparse | 8 import argparse |
9 import heapq | 9 import heapq |
10 import json | 10 import json |
(...skipping 22 matching lines...) Expand all Loading... |
33 $ tools/ignition/bytecode_dispatches_report.py -t -n 15 data.json | 33 $ tools/ignition/bytecode_dispatches_report.py -t -n 15 data.json |
34 | 34 |
35 # Save heatmap to default filename v8.ignition_dispatches_counters.svg | 35 # Save heatmap to default filename v8.ignition_dispatches_counters.svg |
36 $ tools/ignition/bytecode_dispatches_report.py -p | 36 $ tools/ignition/bytecode_dispatches_report.py -p |
37 | 37 |
38 # Save heatmap to filename data.svg | 38 # Save heatmap to filename data.svg |
39 $ tools/ignition/bytecode_dispatches_report.py -p -o data.svg | 39 $ tools/ignition/bytecode_dispatches_report.py -p -o data.svg |
40 | 40 |
41 # Open the heatmap in an interactive viewer | 41 # Open the heatmap in an interactive viewer |
42 $ tools/ignition/bytecode_dispatches_report.py -p -i | 42 $ tools/ignition/bytecode_dispatches_report.py -p -i |
| 43 |
| 44 # Display the top 5 sources and destinations of dispatches to/from LdaZero |
| 45 $ tools/ignition/bytecode_dispatches_report.py -f LdaZero -n 5 |
43 """ | 46 """ |
44 | 47 |
45 __COUNTER_BITS = struct.calcsize("P") * 8 # Size in bits of a pointer | 48 __COUNTER_BITS = struct.calcsize("P") * 8 # Size in bits of a pointer |
46 __COUNTER_MAX = 2**__COUNTER_BITS - 1 | 49 __COUNTER_MAX = 2**__COUNTER_BITS - 1 |
47 | 50 |
48 | 51 |
49 def warn_if_counter_may_have_saturated(dispatches_table): | 52 def warn_if_counter_may_have_saturated(dispatches_table): |
50 for source, counters_from_source in dispatches_table.items(): | 53 for source, counters_from_source in dispatches_table.items(): |
51 for destination, counter in counters_from_source.items(): | 54 for destination, counter in counters_from_source.items(): |
52 if counter == __COUNTER_MAX: | 55 if counter == __COUNTER_MAX: |
(...skipping 27 matching lines...) Expand all Loading... |
80 return top_bytecodes | 83 return top_bytecodes |
81 | 84 |
82 | 85 |
83 def print_top_bytecodes(dispatches_table): | 86 def print_top_bytecodes(dispatches_table): |
84 top_bytecodes = find_top_bytecodes(dispatches_table) | 87 top_bytecodes = find_top_bytecodes(dispatches_table) |
85 print "Top bytecodes:" | 88 print "Top bytecodes:" |
86 for bytecode, counter in top_bytecodes: | 89 for bytecode, counter in top_bytecodes: |
87 print "{:>12d}\t{}".format(counter, bytecode) | 90 print "{:>12d}\t{}".format(counter, bytecode) |
88 | 91 |
89 | 92 |
| 93 def find_top_dispatch_sources(dispatches_table, destination, top_count): |
| 94 def source_counters_generator(): |
| 95 for source, table_row in dispatches_table.items(): |
| 96 if destination in table_row: |
| 97 yield source, table_row[destination] |
| 98 |
| 99 return heapq.nlargest(top_count, source_counters_generator(), |
| 100 key=lambda x: x[1]) |
| 101 |
| 102 |
| 103 def print_top_dispatch_sources_and_destinations(dispatches_table, bytecode, |
| 104 top_count): |
| 105 top_sources = find_top_dispatch_sources(dispatches_table, bytecode, top_count) |
| 106 top_destinations = heapq.nlargest(top_count, |
| 107 dispatches_table[bytecode].items(), |
| 108 key=lambda x: x[1]) |
| 109 |
| 110 print "Top sources of dispatches to {}:".format(bytecode) |
| 111 for source_name, counter in top_sources: |
| 112 print "{:>12d}\t{}".format(counter, source_name) |
| 113 |
| 114 print "\nTop destinations of dispatches from {}:".format(bytecode) |
| 115 for destination_name, counter in top_destinations: |
| 116 print "{:>12d}\t{}".format(counter, destination_name) |
| 117 |
| 118 |
90 def build_counters_matrix(dispatches_table): | 119 def build_counters_matrix(dispatches_table): |
91 labels = sorted(dispatches_table.keys()) | 120 labels = sorted(dispatches_table.keys()) |
92 | 121 |
93 counters_matrix = numpy.empty([len(labels), len(labels)], dtype=int) | 122 counters_matrix = numpy.empty([len(labels), len(labels)], dtype=int) |
94 for from_index, from_name in enumerate(labels): | 123 for from_index, from_name in enumerate(labels): |
95 current_row = dispatches_table[from_name]; | 124 current_row = dispatches_table[from_name]; |
96 for to_index, to_name in enumerate(labels): | 125 for to_index, to_name in enumerate(labels): |
97 counters_matrix[from_index, to_index] = current_row.get(to_name, 0) | 126 counters_matrix[from_index, to_index] = current_row.get(to_name, 0) |
98 | 127 |
99 # Reverse y axis for a nicer appearance | 128 # Reverse y axis for a nicer appearance |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 "--interactive", "-i", | 189 "--interactive", "-i", |
161 action="store_true", | 190 action="store_true", |
162 help="open the heatmap in an interactive viewer, instead of writing to file" | 191 help="open the heatmap in an interactive viewer, instead of writing to file" |
163 ) | 192 ) |
164 command_line_parser.add_argument( | 193 command_line_parser.add_argument( |
165 "--top-bytecode-dispatch-pairs", "-t", | 194 "--top-bytecode-dispatch-pairs", "-t", |
166 action="store_true", | 195 action="store_true", |
167 help="print the top bytecode dispatch pairs" | 196 help="print the top bytecode dispatch pairs" |
168 ) | 197 ) |
169 command_line_parser.add_argument( | 198 command_line_parser.add_argument( |
170 "--top-bytecode-dispatch-pairs-number", "-n", | 199 "--top-entries-count", "-n", |
171 metavar="N", | 200 metavar="N", |
172 type=int, | 201 type=int, |
173 default=10, | 202 default=10, |
174 help="print N top bytecode dispatch pairs when running with -t (default 10)" | 203 help="print N top entries when running with -t or -f (default 10)" |
| 204 ) |
| 205 command_line_parser.add_argument( |
| 206 "--top-dispatches-for-bytecode", "-f", |
| 207 metavar="<bytecode name>", |
| 208 help="print top dispatch sources and destinations to the specified bytecode" |
175 ) | 209 ) |
176 command_line_parser.add_argument( | 210 command_line_parser.add_argument( |
177 "--output-filename", "-o", | 211 "--output-filename", "-o", |
178 metavar="<output filename>", | 212 metavar="<output filename>", |
179 default="v8.ignition_dispatches_table.svg", | 213 default="v8.ignition_dispatches_table.svg", |
180 help=("file to save the plot file to. File type is deduced from the " | 214 help=("file to save the plot file to. File type is deduced from the " |
181 "extension. PDF, SVG, PNG supported") | 215 "extension. PDF, SVG, PNG supported") |
182 ) | 216 ) |
183 command_line_parser.add_argument( | 217 command_line_parser.add_argument( |
184 "input_filename", | 218 "input_filename", |
(...skipping 19 matching lines...) Expand all Loading... |
204 plot_dispatches_table(dispatches_table, figure, axis) | 238 plot_dispatches_table(dispatches_table, figure, axis) |
205 | 239 |
206 if program_options.interactive: | 240 if program_options.interactive: |
207 pyplot.show() | 241 pyplot.show() |
208 else: | 242 else: |
209 figure.set_size_inches(program_options.plot_size, | 243 figure.set_size_inches(program_options.plot_size, |
210 program_options.plot_size) | 244 program_options.plot_size) |
211 pyplot.savefig(program_options.output_filename) | 245 pyplot.savefig(program_options.output_filename) |
212 elif program_options.top_bytecode_dispatch_pairs: | 246 elif program_options.top_bytecode_dispatch_pairs: |
213 print_top_bytecode_dispatch_pairs( | 247 print_top_bytecode_dispatch_pairs( |
214 dispatches_table, program_options.top_bytecode_dispatch_pairs_number) | 248 dispatches_table, program_options.top_entries_count) |
| 249 elif program_options.top_dispatches_for_bytecode: |
| 250 print_top_dispatch_sources_and_destinations( |
| 251 dispatches_table, program_options.top_dispatches_for_bytecode, |
| 252 program_options.top_entries_count) |
215 else: | 253 else: |
216 print_top_bytecodes(dispatches_table) | 254 print_top_bytecodes(dispatches_table) |
217 | 255 |
218 | 256 |
219 if __name__ == "__main__": | 257 if __name__ == "__main__": |
220 main() | 258 main() |
OLD | NEW |