Chromium Code Reviews| Index: tools/ignition_plot_handler_counters.py |
| diff --git a/tools/ignition_plot_handler_counters.py b/tools/ignition_plot_handler_counters.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..4b2eb0458162556b5f73928a244fe94255880d56 |
| --- /dev/null |
| +++ b/tools/ignition_plot_handler_counters.py |
| @@ -0,0 +1,131 @@ |
| +#! /usr/bin/python |
| +# |
| +# Copyright 2016 the V8 project authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| +# |
| + |
|
rmcilroy
2016/04/08 11:24:44
Name should be something like plot_ignition_byteco
Stefano Sanfilippo
2016/04/08 14:42:44
Done.
|
| +import argparse |
| +import json |
| +import matplotlib as mpl |
| +#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
|
| +import matplotlib.colors as colors |
| +import matplotlib.pyplot as plt |
| +import numpy as np |
| +import struct |
| + |
| + |
| +__COUNTER_BITS = struct.calcsize("P") * 8 # Size in bits of a pointer |
| +__COUNTER_MAX = 2**__COUNTER_BITS - 1 |
| + |
| + |
| +def load_counters_data(stream): |
| + counters_matrix = json.load(stream) |
| + raw_labels = [x[0] for x in counters_matrix] |
| + raw_values = np.array([x[1] for x in counters_matrix]) |
| + return raw_labels, raw_values |
| + |
| + |
| +def check_saturated_counters(raw_labels, raw_values): |
| + # np.where() returns two arrays of x and y coordinates, |
| + # zip them together to get (x,y) tuples. |
| + saturated_cells = zip(*np.where(raw_values == __COUNTER_MAX)) |
| + for coords in saturated_cells: |
| + labels_chain = " -> ".join(raw_labels[coord] for coord in coords) |
| + print "WARNING: counter may have saturated: {}".format(labels_chain) |
| + |
| + |
| +def prepare_data_for_plot(raw_labels, raw_values): |
| + xlabels = raw_labels |
| + ylabels = list(reversed(xlabels)) |
| + values = np.flipud(raw_values) |
| + return xlabels, ylabels, values |
| + |
| + |
| +def plot_handler_to_handler_counters(values, xlabels, ylabels, figure, axis): |
| + image = axis.pcolor( |
| + values, |
| + cmap='jet', |
| + norm=colors.LogNorm(), |
| + edgecolor='grey', |
| + linestyle='dotted', |
| + linewidth=0.5 |
| + ) |
| + |
| + axis.xaxis.set( |
| + ticks=np.arange(0.5, len(xlabels)), |
| + label="From bytecode handler" |
| + ) |
| + axis.xaxis.tick_top() |
| + axis.set_xlim(0, len(xlabels)) |
| + axis.set_xticklabels(xlabels, rotation='vertical') |
| + |
| + axis.yaxis.set( |
| + ticks=np.arange(0.5, len(ylabels)), |
| + label="To bytecode handler", |
| + ticklabels=ylabels |
| + ) |
| + axis.set_ylim(0, len(ylabels)) |
| + |
| + figure.colorbar( |
| + image, |
| + ax=axis, |
| + fraction=0.01, |
| + pad=0.01 |
| + ) |
| + |
| + |
| +def parse_command_line(): |
| + command_line_parser = argparse.ArgumentParser( |
| + description="Plot Ignition counters file.", |
| + ) |
| + command_line_parser.add_argument( |
| + "--plot_size", "-s", |
| + metavar="N", |
| + default=30, |
| + help="shorter side, in inches, of the output plot", |
| + ) |
| + command_line_parser.add_argument( |
| + "--interactive", "-i", |
| + action="store_true", |
| + help="open an interactive viewer, rather than writing to file.", |
| + ) |
| + command_line_parser.add_argument( |
| + "--output_filename", "-o", |
| + metavar="<output filename>", |
| + default="v8.ignition_dispatches_table.svg", |
| + help=("file to save the plot file to. File type is deduced from the " |
| + "extension. PDF, SVG, PNG supported") |
| + ) |
| + command_line_parser.add_argument( |
| + "input_filename", |
| + metavar="<input filename>", |
| + default="v8.ignition_dispatches_table.json", |
| + nargs='?', |
| + help="Ignition counters JSON file.", |
| + ) |
| + |
| + return command_line_parser.parse_args() |
| + |
| + |
| +def main(): |
| + program_options = parse_command_line() |
| + |
| + with open(program_options.input_filename) as stream: |
| + raw_labels, raw_values = load_counters_data(stream) |
| + |
| + check_saturated_counters(raw_labels, raw_values) |
| + xlabels, ylabels, values = prepare_data_for_plot(raw_labels, raw_values) |
| + |
| + figure, axis = plt.subplots() |
| + plot_handler_to_handler_counters(values, xlabels, ylabels, figure, axis) |
| + |
| + if program_options.interactive: |
| + plt.show() |
| + else: |
| + figure.set_size_inches(program_options.plot_size, program_options.plot_size) |
| + plt.savefig(program_options.output_filename) |
| + |
| + |
| +if __name__ == "__main__": |
| + main() |