Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 #! /usr/bin/python | |
| 2 # | |
| 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 | |
| 5 # found in the LICENSE file. | |
| 6 # | |
| 7 | |
|
rmcilroy
2016/04/08 11:24:44
Name should be something like plot_ignition_byteco
Stefano Sanfilippo
2016/04/08 14:42:44
Done.
| |
| 8 import argparse | |
| 9 import json | |
| 10 import matplotlib as mpl | |
| 11 #mpl.use('Agg') ## Uncomment this line if running headless | |
|
rmcilroy
2016/04/08 11:24:44
Remove?
Stefano Sanfilippo
2016/04/08 14:42:44
It might be of some use if this script is run on a
| |
| 12 import matplotlib.colors as colors | |
| 13 import matplotlib.pyplot as plt | |
| 14 import numpy as np | |
| 15 import struct | |
| 16 | |
| 17 | |
| 18 __COUNTER_BITS = struct.calcsize("P") * 8 # Size in bits of a pointer | |
| 19 __COUNTER_MAX = 2**__COUNTER_BITS - 1 | |
| 20 | |
| 21 | |
| 22 def load_counters_data(stream): | |
| 23 counters_matrix = json.load(stream) | |
| 24 raw_labels = [x[0] for x in counters_matrix] | |
| 25 raw_values = np.array([x[1] for x in counters_matrix]) | |
| 26 return raw_labels, raw_values | |
| 27 | |
| 28 | |
| 29 def check_saturated_counters(raw_labels, raw_values): | |
| 30 # np.where() returns two arrays of x and y coordinates, | |
| 31 # zip them together to get (x,y) tuples. | |
| 32 saturated_cells = zip(*np.where(raw_values == __COUNTER_MAX)) | |
| 33 for coords in saturated_cells: | |
| 34 labels_chain = " -> ".join(raw_labels[coord] for coord in coords) | |
| 35 print "WARNING: counter may have saturated: {}".format(labels_chain) | |
| 36 | |
| 37 | |
| 38 def prepare_data_for_plot(raw_labels, raw_values): | |
| 39 xlabels = raw_labels | |
| 40 ylabels = list(reversed(xlabels)) | |
| 41 values = np.flipud(raw_values) | |
| 42 return xlabels, ylabels, values | |
| 43 | |
| 44 | |
| 45 def plot_handler_to_handler_counters(values, xlabels, ylabels, figure, axis): | |
| 46 image = axis.pcolor( | |
| 47 values, | |
| 48 cmap='jet', | |
| 49 norm=colors.LogNorm(), | |
| 50 edgecolor='grey', | |
| 51 linestyle='dotted', | |
| 52 linewidth=0.5 | |
| 53 ) | |
| 54 | |
| 55 axis.xaxis.set( | |
| 56 ticks=np.arange(0.5, len(xlabels)), | |
| 57 label="From bytecode handler" | |
| 58 ) | |
| 59 axis.xaxis.tick_top() | |
| 60 axis.set_xlim(0, len(xlabels)) | |
| 61 axis.set_xticklabels(xlabels, rotation='vertical') | |
| 62 | |
| 63 axis.yaxis.set( | |
| 64 ticks=np.arange(0.5, len(ylabels)), | |
| 65 label="To bytecode handler", | |
| 66 ticklabels=ylabels | |
| 67 ) | |
| 68 axis.set_ylim(0, len(ylabels)) | |
| 69 | |
| 70 figure.colorbar( | |
| 71 image, | |
| 72 ax=axis, | |
| 73 fraction=0.01, | |
| 74 pad=0.01 | |
| 75 ) | |
| 76 | |
| 77 | |
| 78 def parse_command_line(): | |
| 79 command_line_parser = argparse.ArgumentParser( | |
| 80 description="Plot Ignition counters file.", | |
| 81 ) | |
| 82 command_line_parser.add_argument( | |
| 83 "--plot_size", "-s", | |
| 84 metavar="N", | |
| 85 default=30, | |
| 86 help="shorter side, in inches, of the output plot", | |
| 87 ) | |
| 88 command_line_parser.add_argument( | |
| 89 "--interactive", "-i", | |
| 90 action="store_true", | |
| 91 help="open an interactive viewer, rather than writing to file.", | |
| 92 ) | |
| 93 command_line_parser.add_argument( | |
| 94 "--output_filename", "-o", | |
| 95 metavar="<output filename>", | |
| 96 default="v8.ignition_dispatches_table.svg", | |
| 97 help=("file to save the plot file to. File type is deduced from the " | |
| 98 "extension. PDF, SVG, PNG supported") | |
| 99 ) | |
| 100 command_line_parser.add_argument( | |
| 101 "input_filename", | |
| 102 metavar="<input filename>", | |
| 103 default="v8.ignition_dispatches_table.json", | |
| 104 nargs='?', | |
| 105 help="Ignition counters JSON file.", | |
| 106 ) | |
| 107 | |
| 108 return command_line_parser.parse_args() | |
| 109 | |
| 110 | |
| 111 def main(): | |
| 112 program_options = parse_command_line() | |
| 113 | |
| 114 with open(program_options.input_filename) as stream: | |
| 115 raw_labels, raw_values = load_counters_data(stream) | |
| 116 | |
| 117 check_saturated_counters(raw_labels, raw_values) | |
| 118 xlabels, ylabels, values = prepare_data_for_plot(raw_labels, raw_values) | |
| 119 | |
| 120 figure, axis = plt.subplots() | |
| 121 plot_handler_to_handler_counters(values, xlabels, ylabels, figure, axis) | |
| 122 | |
| 123 if program_options.interactive: | |
| 124 plt.show() | |
| 125 else: | |
| 126 figure.set_size_inches(program_options.plot_size, program_options.plot_size) | |
| 127 plt.savefig(program_options.output_filename) | |
| 128 | |
| 129 | |
| 130 if __name__ == "__main__": | |
| 131 main() | |
| OLD | NEW |