Home | History | Annotate | Download | only in tools
      1 #!/bin/bash
      2 #
      3 # Copyright 2013 the V8 project authors. All rights reserved.
      4 # Redistribution and use in source and binary forms, with or without
      5 # modification, are permitted provided that the following conditions are
      6 # met:
      7 #
      8 #     * Redistributions of source code must retain the above copyright
      9 #       notice, this list of conditions and the following disclaimer.
     10 #     * Redistributions in binary form must reproduce the above
     11 #       copyright notice, this list of conditions and the following
     12 #       disclaimer in the documentation and/or other materials provided
     13 #       with the distribution.
     14 #     * Neither the name of Google Inc. nor the names of its
     15 #       contributors may be used to endorse or promote products derived
     16 #       from this software without specific prior written permission.
     17 #
     18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29 
     30 # This script reads in CSV formatted instruction data, and draws a stacked
     31 # graph in png format.
     32 
     33 defaultfile=arm64_inst.csv
     34 defaultout=arm64_inst.png
     35 gnuplot=/usr/bin/gnuplot
     36 
     37 
     38 # File containing CSV instruction data from simulator.
     39 file=${1:-$defaultfile}
     40 
     41 # Output graph png file.
     42 out=${2:-$defaultout}
     43 
     44 # Check input file exists.
     45 if [ ! -e $file ]; then
     46   echo "Input file not found: $file."
     47   echo "Usage: draw_instruction_graph.sh <input csv> <output png>"
     48   exit 1
     49 fi
     50 
     51 # Search for an error message, and if found, exit.
     52 error=`grep -m1 '# Error:' $file`
     53 if [ -n "$error" ]; then
     54   echo "Error message in input file:"
     55   echo " $error"
     56   exit 2
     57 fi
     58 
     59 # Sample period - period over which numbers for each category of instructions is
     60 # counted.
     61 sp=`grep -m1 '# sample_period=' $file | cut -d= -f2`
     62 
     63 # Get number of counters in the CSV file.
     64 nc=`grep -m1 '# counters=' $file | cut -d= -f2`
     65 
     66 # Find the annotation arrows. They appear as comments in the CSV file, in the
     67 # format:
     68 #   # xx @ yyyyy
     69 # Where xx is a two character annotation identifier, and yyyyy is the
     70 # position in the executed instruction stream that generated the annotation.
     71 # Turn these locations into labelled arrows.
     72 arrows=`sed '/^[^#]/ d' $file | \
     73         perl -pe "s/^# .. @ (\d+)/set arrow from \1, graph 0.9 to \1, $sp/"`;
     74 labels=`sed '/^[^#]/d' $file | \
     75         sed -r 's/^# (..) @ (.+)/set label at \2, graph 0.9 "\1" \
     76                 center offset 0,0.5 font "FreeSans, 8"/'`;
     77 
     78 # Check for gnuplot, and warn if not available.
     79 if [ ! -e $gnuplot ]; then
     80   echo "Can't find gnuplot at $gnuplot."
     81   echo "Gnuplot version 4.6.3 or later required."
     82   exit 3
     83 fi
     84 
     85 # Initialise gnuplot, and give it the data to draw.
     86 echo | $gnuplot <<EOF
     87 $arrows
     88 $labels
     89 MAXCOL=$nc
     90 set term png size 1920, 800 #ffffff
     91 set output '$out'
     92 set datafile separator ','
     93 set xtics font 'FreeSans, 10'
     94 set xlabel 'Instructions' font 'FreeSans, 10'
     95 set ytics font 'FreeSans, 10'
     96 set yrange [0:*]
     97 set key outside font 'FreeSans, 8'
     98 
     99 set style line 2 lc rgb '#800000'
    100 set style line 3 lc rgb '#d00000'
    101 set style line 4 lc rgb '#ff6000'
    102 set style line 5 lc rgb '#ffc000'
    103 set style line 6 lc rgb '#ffff00'
    104 
    105 set style line 7 lc rgb '#ff00ff'
    106 set style line 8 lc rgb '#ffc0ff'
    107 
    108 set style line 9 lc rgb '#004040'
    109 set style line 10 lc rgb '#008080'
    110 set style line 11 lc rgb '#40c0c0'
    111 set style line 12 lc rgb '#c0f0f0'
    112 
    113 set style line 13 lc rgb '#004000'
    114 set style line 14 lc rgb '#008000'
    115 set style line 15 lc rgb '#40c040'
    116 set style line 16 lc rgb '#c0f0c0'
    117 
    118 set style line 17 lc rgb '#2020f0'
    119 set style line 18 lc rgb '#6060f0'
    120 set style line 19 lc rgb '#a0a0f0'
    121 
    122 set style line 20 lc rgb '#000000'
    123 set style line 21 lc rgb '#ffffff'
    124 
    125 plot for [i=2:MAXCOL] '$file' using 1:(sum [col=i:MAXCOL] column(col)) \
    126 title columnheader(i) with filledcurve y1=0 ls i
    127 EOF
    128 
    129 
    130 
    131