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 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after 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_dispatch_sources(dispatches_table, top_count): | |
72 def dispatch_sources_counters_generator(): | |
73 for source, counters_from_source in dispatches_table.items(): | |
74 yield source, sum(counters_from_source.values()) | |
75 | |
76 return heapq.nlargest(top_count, dispatch_sources_counters_generator(), | |
rmcilroy
2016/04/13 08:45:54
I would probably default to printing all the bytec
Stefano Sanfilippo
2016/04/13 10:19:38
Done.
| |
77 key=lambda x: x[1]) | |
78 | |
79 | |
80 def print_top_dispatch_sources(dispatches_table, top_count): | |
81 top_dispatch_sources = find_top_dispatch_sources(dispatches_table, top_count) | |
82 print "Top {} dispatch sources:".format(top_count) | |
rmcilroy
2016/04/13 08:45:54
Sources is not a good name since it isn't clear wh
Stefano Sanfilippo
2016/04/13 10:19:37
Done.
| |
83 for source, counter in top_dispatch_sources: | |
84 print "{:>12d}\t{}".format(counter, source) | |
85 | |
86 | |
71 def build_counters_matrix(dispatches_table): | 87 def build_counters_matrix(dispatches_table): |
72 labels = sorted(dispatches_table.keys()) | 88 labels = sorted(dispatches_table.keys()) |
73 | 89 |
74 counters_matrix = numpy.empty([len(labels), len(labels)], dtype=int) | 90 counters_matrix = numpy.empty([len(labels), len(labels)], dtype=int) |
75 for from_index, from_name in enumerate(labels): | 91 for from_index, from_name in enumerate(labels): |
76 current_row = dispatches_table[from_name]; | 92 current_row = dispatches_table[from_name]; |
77 for to_index, to_name in enumerate(labels): | 93 for to_index, to_name in enumerate(labels): |
78 counters_matrix[from_index, to_index] = current_row.get(to_name, 0) | 94 counters_matrix[from_index, to_index] = current_row.get(to_name, 0) |
79 | 95 |
80 # Reverse y axis for a nicer appearance | 96 # Reverse y axis for a nicer appearance |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 figure, axis = pyplot.subplots() | 195 figure, axis = pyplot.subplots() |
180 plot_dispatches_table(dispatches_table, figure, axis) | 196 plot_dispatches_table(dispatches_table, figure, axis) |
181 | 197 |
182 if program_options.interactive: | 198 if program_options.interactive: |
183 pyplot.show() | 199 pyplot.show() |
184 else: | 200 else: |
185 figure.set_size_inches(program_options.plot_size, | 201 figure.set_size_inches(program_options.plot_size, |
186 program_options.plot_size) | 202 program_options.plot_size) |
187 pyplot.savefig(program_options.output_filename) | 203 pyplot.savefig(program_options.output_filename) |
188 else: | 204 else: |
205 print_top_dispatch_sources(dispatches_table, program_options.top_count) | |
rmcilroy
2016/04/13 08:45:54
Please make this a separate option (and be the def
Stefano Sanfilippo
2016/04/13 10:19:37
Done.
| |
206 print # just a blank line | |
189 print_top_counters(dispatches_table, program_options.top_count) | 207 print_top_counters(dispatches_table, program_options.top_count) |
190 | 208 |
191 | 209 |
192 if __name__ == "__main__": | 210 if __name__ == "__main__": |
193 main() | 211 main() |
OLD | NEW |