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 |
11 from matplotlib import colors | 11 from matplotlib import colors |
12 from matplotlib import pyplot | 12 from matplotlib import pyplot |
13 import numpy | 13 import numpy |
14 import struct | 14 import struct |
15 | 15 |
16 | 16 |
17 __DESCRIPTION = """ | 17 __DESCRIPTION = """ |
18 Process v8.ignition_dispatches_counters.json and list top counters, | 18 Process v8.ignition_dispatches_counters.json and list top counters, |
19 or plot a dispatch heatmap. | 19 or plot a dispatch heatmap. |
20 """ | 20 """ |
21 | 21 |
22 | 22 |
23 __HELP_EPILOGUE = """ | 23 __HELP_EPILOGUE = """ |
24 examples: | 24 examples: |
25 # Print the top 10 counters, reading from default filename | 25 # Print the hottest bytecode handlers in descending order, reading from |
26 # v8.ignition_dispatches_counters.json (default mode) | 26 # default filename v8.ignition_dispatches_counters.json (default mode) |
27 $ tools/ignition/bytecode_dispatches_report.py | 27 $ tools/ignition/bytecode_dispatches_report.py |
28 | 28 |
29 # Print the top 15 counters reading from data.json | 29 # Print the top 15 dispatch counters reading from data.json |
30 $ tools/ignition/bytecode_dispatches_report.py -t 15 data.json | 30 $ tools/ignition/bytecode_dispatches_report.py -t 15 data.json |
31 | 31 |
32 # Save heatmap to default filename v8.ignition_dispatches_counters.svg | 32 # Save heatmap to default filename v8.ignition_dispatches_counters.svg |
33 $ tools/ignition/bytecode_dispatches_report.py -p | 33 $ tools/ignition/bytecode_dispatches_report.py -p |
34 | 34 |
35 # Save heatmap to filename data.svg | 35 # Save heatmap to filename data.svg |
36 $ tools/ignition/bytecode_dispatches_report.py -p -o data.svg | 36 $ tools/ignition/bytecode_dispatches_report.py -p -o data.svg |
37 | 37 |
38 # Open the heatmap in an interactive viewer | 38 # Open the heatmap in an interactive viewer |
39 $ tools/ignition/bytecode_dispatches_report.py -p -i | 39 $ tools/ignition/bytecode_dispatches_report.py -p -i |
(...skipping 21 matching lines...) Expand all Loading... | |
61 key=lambda x: x[2]) | 61 key=lambda x: x[2]) |
62 | 62 |
63 | 63 |
64 def print_top_counters(dispatches_table, top_count): | 64 def print_top_counters(dispatches_table, top_count): |
65 top_counters = find_top_counters(dispatches_table, top_count) | 65 top_counters = find_top_counters(dispatches_table, top_count) |
66 print "Top {} dispatch counters:".format(top_count) | 66 print "Top {} dispatch counters:".format(top_count) |
67 for source, destination, counter in top_counters: | 67 for source, destination, counter in top_counters: |
68 print "{:>12d}\t{} -> {}".format(counter, source, destination) | 68 print "{:>12d}\t{} -> {}".format(counter, source, destination) |
69 | 69 |
70 | 70 |
71 def find_top_bytecodes(dispatches_table): | |
72 top_bytecodes = [] | |
73 for bytecode, counters_from_bytecode in dispatches_table.items(): | |
74 top_bytecodes.append((bytecode, sum(counters_from_bytecode.values()))) | |
75 top_bytecodes.sort(key=lambda x: x[1], reverse=True) | |
76 return top_bytecodes | |
77 | |
78 | |
79 def print_top_bytecodes(dispatches_table): | |
80 top_bytecodes = find_top_bytecodes(dispatches_table) | |
81 print "Top bytecodes:" | |
82 for bytecode, counter in top_bytecodes: | |
83 print "{:>12d}\t{}".format(counter, bytecode) | |
84 | |
85 | |
71 def build_counters_matrix(dispatches_table): | 86 def build_counters_matrix(dispatches_table): |
72 labels = sorted(dispatches_table.keys()) | 87 labels = sorted(dispatches_table.keys()) |
73 | 88 |
74 counters_matrix = numpy.empty([len(labels), len(labels)], dtype=int) | 89 counters_matrix = numpy.empty([len(labels), len(labels)], dtype=int) |
75 for from_index, from_name in enumerate(labels): | 90 for from_index, from_name in enumerate(labels): |
76 current_row = dispatches_table[from_name]; | 91 current_row = dispatches_table[from_name]; |
77 for to_index, to_name in enumerate(labels): | 92 for to_index, to_name in enumerate(labels): |
78 counters_matrix[from_index, to_index] = current_row.get(to_name, 0) | 93 counters_matrix[from_index, to_index] = current_row.get(to_name, 0) |
79 | 94 |
80 # Reverse y axis for a nicer appearance | 95 # Reverse y axis for a nicer appearance |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 def parse_command_line(): | 138 def parse_command_line(): |
124 command_line_parser = argparse.ArgumentParser( | 139 command_line_parser = argparse.ArgumentParser( |
125 formatter_class=argparse.RawDescriptionHelpFormatter, | 140 formatter_class=argparse.RawDescriptionHelpFormatter, |
126 description=__DESCRIPTION, | 141 description=__DESCRIPTION, |
127 epilog=__HELP_EPILOGUE | 142 epilog=__HELP_EPILOGUE |
128 ) | 143 ) |
129 command_line_parser.add_argument( | 144 command_line_parser.add_argument( |
130 "--plot_size", "-s", | 145 "--plot_size", "-s", |
131 metavar="N", | 146 metavar="N", |
132 default=30, | 147 default=30, |
133 help="shorter side, in inches, of the output plot (default 30)" | 148 help="shorter side in inches of the output plot (default 30)" |
134 ) | 149 ) |
135 command_line_parser.add_argument( | 150 command_line_parser.add_argument( |
136 "--plot", "-p", | 151 "--plot", "-p", |
137 action="store_true", | 152 action="store_true", |
138 help="plot dispatches table heatmap" | 153 help="plot dispatches table heatmap" |
139 ) | 154 ) |
140 command_line_parser.add_argument( | 155 command_line_parser.add_argument( |
141 "--interactive", "-i", | 156 "--interactive", "-i", |
142 action="store_true", | 157 action="store_true", |
143 help="open an interactive viewer, rather than writing to file" | 158 help="open an interactive viewer, instead of writing to file" |
144 ) | 159 ) |
145 command_line_parser.add_argument( | 160 command_line_parser.add_argument( |
146 "--top_count", "-t", | 161 "--top_count", "-t", |
rmcilroy
2016/04/19 10:36:02
This should not be used to specify that you want t
Stefano Sanfilippo
2016/04/19 11:08:33
Done.
| |
147 metavar="N", | 162 metavar="N", |
148 type=int, | 163 type=int, |
149 default=10, | 164 default=0, |
150 help="print the top N counters (default 10)" | 165 help="print the top N counters (default 10)" |
151 ) | 166 ) |
152 command_line_parser.add_argument( | 167 command_line_parser.add_argument( |
153 "--output_filename", "-o", | 168 "--output_filename", "-o", |
154 metavar="<output filename>", | 169 metavar="<output filename>", |
155 default="v8.ignition_dispatches_table.svg", | 170 default="v8.ignition_dispatches_table.svg", |
156 help=("file to save the plot file to. File type is deduced from the " | 171 help=("file to save the plot file to. File type is deduced from the " |
157 "extension. PDF, SVG, PNG supported") | 172 "extension. PDF, SVG, PNG supported") |
158 ) | 173 ) |
159 command_line_parser.add_argument( | 174 command_line_parser.add_argument( |
(...skipping 18 matching lines...) Expand all Loading... | |
178 if program_options.plot: | 193 if program_options.plot: |
179 figure, axis = pyplot.subplots() | 194 figure, axis = pyplot.subplots() |
180 plot_dispatches_table(dispatches_table, figure, axis) | 195 plot_dispatches_table(dispatches_table, figure, axis) |
181 | 196 |
182 if program_options.interactive: | 197 if program_options.interactive: |
183 pyplot.show() | 198 pyplot.show() |
184 else: | 199 else: |
185 figure.set_size_inches(program_options.plot_size, | 200 figure.set_size_inches(program_options.plot_size, |
186 program_options.plot_size) | 201 program_options.plot_size) |
187 pyplot.savefig(program_options.output_filename) | 202 pyplot.savefig(program_options.output_filename) |
203 elif program_options.top_count: | |
204 print_top_counters(dispatches_table, program_options.top_count) | |
188 else: | 205 else: |
189 print_top_counters(dispatches_table, program_options.top_count) | 206 print_top_bytecodes(dispatches_table) |
190 | 207 |
191 | 208 |
192 if __name__ == "__main__": | 209 if __name__ == "__main__": |
193 main() | 210 main() |
OLD | NEW |