Chromium Code Reviews| Index: tools/ignition/bytecode_dispatches_report.py |
| diff --git a/tools/ignition/bytecode_dispatches_report.py b/tools/ignition/bytecode_dispatches_report.py |
| index 2c04bef600e0336e9cb84f21d928b20eb3eb61eb..8b701fd2107b35fd1482addde7df0a24b9d2831d 100755 |
| --- a/tools/ignition/bytecode_dispatches_report.py |
| +++ b/tools/ignition/bytecode_dispatches_report.py |
| @@ -17,17 +17,20 @@ import struct |
| __DESCRIPTION = """ |
| Process v8.ignition_dispatches_counters.json and list top counters, |
| or plot a dispatch heatmap. |
| + |
| +Please note that those handlers that may or will never dispatch |
| +(e.g. Return or Throw) do not show up in the results. |
| """ |
| __HELP_EPILOGUE = """ |
| examples: |
| - # Print the top 10 counters, reading from default filename |
| - # v8.ignition_dispatches_counters.json (default mode) |
| + # Print the hottest dispatch counters in descending order, reading from |
| + # default filename v8.ignition_dispatches_counters.json (default mode) |
| $ tools/ignition/bytecode_dispatches_report.py |
| - # Print the top 15 counters reading from data.json |
| - $ tools/ignition/bytecode_dispatches_report.py -t 15 data.json |
| + # Print the hottest 15 bytecode handlers reading from data.json |
| + $ tools/ignition/bytecode_dispatches_report.py -t -n 15 data.json |
| # Save heatmap to default filename v8.ignition_dispatches_counters.svg |
| $ tools/ignition/bytecode_dispatches_report.py -p |
| @@ -68,6 +71,21 @@ def print_top_counters(dispatches_table, top_count): |
| print "{:>12d}\t{} -> {}".format(counter, source, destination) |
| +def find_top_bytecodes(dispatches_table): |
| + top_bytecodes = [] |
| + for bytecode, counters_from_bytecode in dispatches_table.items(): |
| + top_bytecodes.append((bytecode, sum(counters_from_bytecode.values()))) |
| + top_bytecodes.sort(key=lambda x: x[1], reverse=True) |
| + return top_bytecodes |
| + |
| + |
| +def print_top_bytecodes(dispatches_table): |
| + top_bytecodes = find_top_bytecodes(dispatches_table) |
| + print "Top bytecodes:" |
| + for bytecode, counter in top_bytecodes: |
| + print "{:>12d}\t{}".format(counter, bytecode) |
| + |
| + |
| def build_counters_matrix(dispatches_table): |
| labels = sorted(dispatches_table.keys()) |
| @@ -127,10 +145,10 @@ def parse_command_line(): |
| epilog=__HELP_EPILOGUE |
| ) |
| command_line_parser.add_argument( |
| - "--plot_size", "-s", |
| + "--plot-size", "-s", |
| metavar="N", |
| default=30, |
| - help="shorter side, in inches, of the output plot (default 30)" |
| + help="shorter side in inches of the output plot (default 30)" |
| ) |
| command_line_parser.add_argument( |
| "--plot", "-p", |
| @@ -140,17 +158,22 @@ def parse_command_line(): |
| command_line_parser.add_argument( |
| "--interactive", "-i", |
| action="store_true", |
| - help="open an interactive viewer, rather than writing to file" |
| + help="open an interactive viewer, instead of writing to file" |
| + ) |
| + command_line_parser.add_argument( |
| + "--top-counters", "-t", |
|
rmcilroy
2016/04/19 11:18:19
This is still not a good name - what do counters m
Stefano Sanfilippo
2016/04/19 13:10:33
Done.
|
| + action="store_true", |
| + help="print the top counters" |
| ) |
| command_line_parser.add_argument( |
| - "--top_count", "-t", |
| + "--top-counters-number", "-n", |
| metavar="N", |
| type=int, |
| default=10, |
| - help="print the top N counters (default 10)" |
| + help="print N top counters when running with -t (default 10)" |
| ) |
| command_line_parser.add_argument( |
| - "--output_filename", "-o", |
| + "--output-filename", "-o", |
| metavar="<output filename>", |
| default="v8.ignition_dispatches_table.svg", |
| help=("file to save the plot file to. File type is deduced from the " |
| @@ -185,8 +208,10 @@ def main(): |
| figure.set_size_inches(program_options.plot_size, |
| program_options.plot_size) |
| pyplot.savefig(program_options.output_filename) |
| + elif program_options.top_counters: |
| + print_top_counters(dispatches_table, program_options.top_counters_number) |
| else: |
| - print_top_counters(dispatches_table, program_options.top_count) |
| + print_top_bytecodes(dispatches_table) |
| if __name__ == "__main__": |