#!/bin/bash # # Copyright 2013 the V8 project authors. All rights reserved. # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following # disclaimer in the documentation and/or other materials provided # with the distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived # from this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # This script reads in CSV formatted instruction data, and draws a stacked # graph in png format. defaultfile=a64_inst.csv defaultout=a64_inst.png gnuplot=/usr/bin/gnuplot # File containing CSV instruction data from simulator. file=${1:-$defaultfile} # Output graph png file. out=${2:-$defaultout} # Check input file exists. if [ ! -e $file ]; then echo "Input file not found: $file." echo "Usage: draw_instruction_graph.sh " exit 1 fi # Search for an error message, and if found, exit. error=`grep -m1 '# Error:' $file` if [ -n "$error" ]; then echo "Error message in input file:" echo " $error" exit 2 fi # Sample period - period over which numbers for each category of instructions is # counted. sp=`grep -m1 '# sample_period=' $file | cut -d= -f2` # Get number of counters in the CSV file. nc=`grep -m1 '# counters=' $file | cut -d= -f2` # Find the annotation arrows. They appear as comments in the CSV file, in the # format: # # xx @ yyyyy # Where xx is a two character annotation identifier, and yyyyy is the # position in the executed instruction stream that generated the annotation. # Turn these locations into labelled arrows. arrows=`sed '/^[^#]/ d' $file | \ perl -pe "s/^# .. @ (\d+)/set arrow from \1, graph 0.9 to \1, $sp/"`; labels=`sed '/^[^#]/d' $file | \ sed -r 's/^# (..) @ (.+)/set label at \2, graph 0.9 "\1" \ center offset 0,0.5 font "FreeSans, 8"/'`; # Check for gnuplot, and warn if not available. if [ ! -e $gnuplot ]; then echo "Can't find gnuplot at $gnuplot." echo "Gnuplot version 4.6.3 or later required." exit 3 fi # Initialise gnuplot, and give it the data to draw. echo | $gnuplot <