Commit 101e076b authored by ssanfilippo's avatar ssanfilippo Committed by Commit bot

[Interpreter] List top dispatch sources and destinations for a given Ignition bytecode.

This commit introduces a new mode for bytecode_dispatches_report.py
which reports the top sources of dispatches to a given bytecode and
the top destinations of dispatches from the same bytecode.

The bytecode name is passed with --top-dispatches-for-bytecode
(short form: -f), while the number of sources and destinations to
show is controlled with -n.

BUG=v8:4899
LOG=N

Review-Url: https://codereview.chromium.org/1979233002
Cr-Commit-Position: refs/heads/master@{#36284}
parent 62b397a3
...@@ -40,6 +40,9 @@ examples: ...@@ -40,6 +40,9 @@ examples:
# Open the heatmap in an interactive viewer # Open the heatmap in an interactive viewer
$ tools/ignition/bytecode_dispatches_report.py -p -i $ tools/ignition/bytecode_dispatches_report.py -p -i
# Display the top 5 sources and destinations of dispatches to/from LdaZero
$ tools/ignition/bytecode_dispatches_report.py -f LdaZero -n 5
""" """
__COUNTER_BITS = struct.calcsize("P") * 8 # Size in bits of a pointer __COUNTER_BITS = struct.calcsize("P") * 8 # Size in bits of a pointer
...@@ -87,6 +90,32 @@ def print_top_bytecodes(dispatches_table): ...@@ -87,6 +90,32 @@ def print_top_bytecodes(dispatches_table):
print "{:>12d}\t{}".format(counter, bytecode) print "{:>12d}\t{}".format(counter, bytecode)
def find_top_dispatch_sources(dispatches_table, destination, top_count):
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])
def print_top_dispatch_sources_and_destinations(dispatches_table, bytecode,
top_count):
top_sources = find_top_dispatch_sources(dispatches_table, bytecode, top_count)
top_destinations = heapq.nlargest(top_count,
dispatches_table[bytecode].items(),
key=lambda x: x[1])
print "Top sources of dispatches to {}:".format(bytecode)
for source_name, counter in top_sources:
print "{:>12d}\t{}".format(counter, source_name)
print "\nTop destinations of dispatches from {}:".format(bytecode)
for destination_name, counter in top_destinations:
print "{:>12d}\t{}".format(counter, destination_name)
def build_counters_matrix(dispatches_table): def build_counters_matrix(dispatches_table):
labels = sorted(dispatches_table.keys()) labels = sorted(dispatches_table.keys())
...@@ -167,11 +196,16 @@ def parse_command_line(): ...@@ -167,11 +196,16 @@ def parse_command_line():
help="print the top bytecode dispatch pairs" help="print the top bytecode dispatch pairs"
) )
command_line_parser.add_argument( command_line_parser.add_argument(
"--top-bytecode-dispatch-pairs-number", "-n", "--top-entries-count", "-n",
metavar="N", metavar="N",
type=int, type=int,
default=10, default=10,
help="print N top bytecode dispatch pairs when running with -t (default 10)" help="print N top entries when running with -t or -f (default 10)"
)
command_line_parser.add_argument(
"--top-dispatches-for-bytecode", "-f",
metavar="<bytecode name>",
help="print top dispatch sources and destinations to the specified bytecode"
) )
command_line_parser.add_argument( command_line_parser.add_argument(
"--output-filename", "-o", "--output-filename", "-o",
...@@ -211,7 +245,11 @@ def main(): ...@@ -211,7 +245,11 @@ def main():
pyplot.savefig(program_options.output_filename) pyplot.savefig(program_options.output_filename)
elif program_options.top_bytecode_dispatch_pairs: elif program_options.top_bytecode_dispatch_pairs:
print_top_bytecode_dispatch_pairs( print_top_bytecode_dispatch_pairs(
dispatches_table, program_options.top_bytecode_dispatch_pairs_number) dispatches_table, program_options.top_entries_count)
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)
else: else:
print_top_bytecodes(dispatches_table) print_top_bytecodes(dispatches_table)
......
...@@ -41,3 +41,14 @@ class BytecodeDispatchesReportTest(unittest.TestCase): ...@@ -41,3 +41,14 @@ class BytecodeDispatchesReportTest(unittest.TestCase):
('a', 25), ('a', 25),
('b', 5) ('b', 5)
]) ])
def test_find_top_dispatch_sources(self):
top_dispatch_sources = bdr.find_top_dispatch_sources({
"a": {"a": 10, "b": 8, "c": 7},
"b": {"a": 1, "c": 4},
"c": {"a": 42, "b": 12, "c": 99}
}, "b", 10)
self.assertListEqual(top_dispatch_sources, [
("c", 12),
("a", 8)
])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment