[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}
This commit is contained in:
parent
62b397a3a7
commit
101e076b34
@ -40,6 +40,9 @@ examples:
|
||||
|
||||
# Open the heatmap in an interactive viewer
|
||||
$ 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
|
||||
@ -87,6 +90,32 @@ def print_top_bytecodes(dispatches_table):
|
||||
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):
|
||||
labels = sorted(dispatches_table.keys())
|
||||
|
||||
@ -167,11 +196,16 @@ def parse_command_line():
|
||||
help="print the top bytecode dispatch pairs"
|
||||
)
|
||||
command_line_parser.add_argument(
|
||||
"--top-bytecode-dispatch-pairs-number", "-n",
|
||||
"--top-entries-count", "-n",
|
||||
metavar="N",
|
||||
type=int,
|
||||
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(
|
||||
"--output-filename", "-o",
|
||||
@ -211,7 +245,11 @@ def main():
|
||||
pyplot.savefig(program_options.output_filename)
|
||||
elif program_options.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:
|
||||
print_top_bytecodes(dispatches_table)
|
||||
|
||||
|
@ -41,3 +41,14 @@ class BytecodeDispatchesReportTest(unittest.TestCase):
|
||||
('a', 25),
|
||||
('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)
|
||||
])
|
||||
|
Loading…
Reference in New Issue
Block a user