Index: tools/ignition/bytecode_dispatches_report.py |
diff --git a/tools/ignition/bytecode_dispatches_report.py b/tools/ignition/bytecode_dispatches_report.py |
index 1c140141f0dd3904a271001627372abaf072c639..622127eee43d5ca6415517da1f861dd8d33241cf 100755 |
--- a/tools/ignition/bytecode_dispatches_report.py |
+++ b/tools/ignition/bytecode_dispatches_report.py |
@@ -12,6 +12,7 @@ from matplotlib import colors |
from matplotlib import pyplot |
import numpy |
import struct |
+import sys |
__DESCRIPTION = """ |
@@ -51,7 +52,7 @@ __COUNTER_MAX = 2**__COUNTER_BITS - 1 |
def warn_if_counter_may_have_saturated(dispatches_table): |
for source, counters_from_source in dispatches_table.items(): |
- for destination, counter in counters_from_source.items(): |
+ for destination, (counter, ratio) in counters_from_source.items(): |
if counter == __COUNTER_MAX: |
print "WARNING: {} -> {} may have saturated.".format(source, |
destination) |
@@ -60,7 +61,7 @@ def warn_if_counter_may_have_saturated(dispatches_table): |
def find_top_bytecode_dispatch_pairs(dispatches_table, top_count): |
def flattened_counters_generator(): |
for source, counters_from_source in dispatches_table.items(): |
- for destination, counter in counters_from_source.items(): |
+ for destination, (counter, ratio) in counters_from_source.items(): |
yield source, destination, counter |
return heapq.nlargest(top_count, flattened_counters_generator(), |
@@ -75,45 +76,45 @@ def print_top_bytecode_dispatch_pairs(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()))) |
+def find_top_bytecodes(dispatch_totals): |
+ top_bytecodes = list(iteritems(dispatch_totals)) |
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) |
+def print_top_bytecodes(dispatch_totals): |
+ top_bytecodes = find_top_bytecodes(dispatch_totals) |
print "Top bytecodes:" |
for bytecode, counter in top_bytecodes: |
print "{:>12d}\t{}".format(counter, bytecode) |
-def find_top_dispatch_sources(dispatches_table, destination, top_count): |
+def find_top_dispatch_sources(dispatches_table, destination, top_count, |
+ sort_source_relative): |
def source_counters_generator(): |
for source, table_row in dispatches_table.items(): |
if destination in table_row: |
yield source, table_row[destination] |
return heapq.nlargest(top_count, source_counters_generator(), |
- key=lambda x: x[1]) |
+ key=lambda x: x[1][1 if sort_source_relative else 0]) |
def print_top_dispatch_sources_and_destinations(dispatches_table, bytecode, |
- top_count): |
- top_sources = find_top_dispatch_sources(dispatches_table, bytecode, top_count) |
+ top_count, sort_relative): |
+ top_sources = find_top_dispatch_sources(dispatches_table, bytecode, |
+ top_count, sort_relative) |
top_destinations = heapq.nlargest(top_count, |
dispatches_table[bytecode].items(), |
- key=lambda x: x[1]) |
+ key=lambda x: x[1][0]) |
print "Top sources of dispatches to {}:".format(bytecode) |
- for source_name, counter in top_sources: |
- print "{:>12d}\t{}".format(counter, source_name) |
+ for source_name, (counter, ratio) in top_sources: |
+ print "{:>12d}\t{:>5.1f}%\t{}".format(counter, ratio * 100, source_name) |
print "\nTop destinations of dispatches from {}:".format(bytecode) |
- for destination_name, counter in top_destinations: |
- print "{:>12d}\t{}".format(counter, destination_name) |
+ for destination_name, (counter, ratio) in top_destinations: |
+ print "{:>12d}\t{:>5.1f}%\t{}".format(counter, ratio * 100, destination_name) |
def build_counters_matrix(dispatches_table): |
@@ -123,7 +124,7 @@ def build_counters_matrix(dispatches_table): |
for from_index, from_name in enumerate(labels): |
current_row = dispatches_table[from_name]; |
for to_index, to_name in enumerate(labels): |
- counters_matrix[from_index, to_index] = current_row.get(to_name, 0) |
+ counters_matrix[from_index, to_index] = current_row.get(to_name, (0, 0))[0] |
# Reverse y axis for a nicer appearance |
xlabels = labels |
@@ -215,6 +216,12 @@ def parse_command_line(): |
"extension. PDF, SVG, PNG supported") |
) |
command_line_parser.add_argument( |
+ "--sort-sources-relative", "-r", |
+ action="store_true", |
+ help=("print top sources in order to how often they dispatch to the " |
+ "speficied bytecode") |
rmcilroy
2016/07/19 09:23:08
fix typo
klaasb
2016/07/19 10:24:27
Done.
|
+ ) |
+ command_line_parser.add_argument( |
"input_filename", |
metavar="<input filename>", |
default="v8.ignition_dispatches_table.json", |
@@ -225,12 +232,28 @@ def parse_command_line(): |
return command_line_parser.parse_args() |
+def itervalues(d): |
+ return d.values() if sys.version_info[0] > 2 else d.itervalues() |
+ |
+ |
+def iteritems(d): |
+ return d.items() if sys.version_info[0] > 2 else d.iteritems() |
+ |
+ |
def main(): |
program_options = parse_command_line() |
with open(program_options.input_filename) as stream: |
dispatches_table = json.load(stream) |
+ dispatch_totals = {} |
+ for source, destinations in dispatches_table.items(): |
+ total = sum(itervalues(destinations)) |
+ dispatch_totals[source] = total |
+ total = float(total) |
+ for destination, count in destinations.iteritems(): |
+ destinations[destination] = (count, count / total) |
rmcilroy
2016/07/19 09:23:08
I think it would be better to do this as a process
klaasb
2016/07/19 10:24:27
Done.
|
+ |
warn_if_counter_may_have_saturated(dispatches_table) |
if program_options.plot: |
@@ -249,9 +272,9 @@ def main(): |
elif program_options.top_dispatches_for_bytecode: |
print_top_dispatch_sources_and_destinations( |
dispatches_table, program_options.top_dispatches_for_bytecode, |
- program_options.top_entries_count) |
+ program_options.top_entries_count, program_options.sort_sources_relative) |
else: |
- print_top_bytecodes(dispatches_table) |
+ print_top_bytecodes(dispatch_totals) |
if __name__ == "__main__": |