• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
33defaultfile=arm64_inst.csv
34defaultout=arm64_inst.png
35gnuplot=/usr/bin/gnuplot
36
37
38# File containing CSV instruction data from simulator.
39file=${1:-$defaultfile}
40
41# Output graph png file.
42out=${2:-$defaultout}
43
44# Check input file exists.
45if [ ! -e $file ]; then
46  echo "Input file not found: $file."
47  echo "Usage: draw_instruction_graph.sh <input csv> <output png>"
48  exit 1
49fi
50
51# Search for an error message, and if found, exit.
52error=`grep -m1 '# Error:' $file`
53if [ -n "$error" ]; then
54  echo "Error message in input file:"
55  echo " $error"
56  exit 2
57fi
58
59# Sample period - period over which numbers for each category of instructions is
60# counted.
61sp=`grep -m1 '# sample_period=' $file | cut -d= -f2`
62
63# Get number of counters in the CSV file.
64nc=`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.
72arrows=`sed '/^[^#]/ d' $file | \
73        perl -pe "s/^# .. @ (\d+)/set arrow from \1, graph 0.9 to \1, $sp/"`;
74labels=`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.
79if [ ! -e $gnuplot ]; then
80  echo "Can't find gnuplot at $gnuplot."
81  echo "Gnuplot version 4.6.3 or later required."
82  exit 3
83fi
84
85# Initialise gnuplot, and give it the data to draw.
86echo | $gnuplot <<EOF
87$arrows
88$labels
89MAXCOL=$nc
90set term png size 1920, 800 #ffffff
91set output '$out'
92set datafile separator ','
93set xtics font 'FreeSans, 10'
94set xlabel 'Instructions' font 'FreeSans, 10'
95set ytics font 'FreeSans, 10'
96set yrange [0:*]
97set key outside font 'FreeSans, 8'
98
99set style line 2 lc rgb '#800000'
100set style line 3 lc rgb '#d00000'
101set style line 4 lc rgb '#ff6000'
102set style line 5 lc rgb '#ffc000'
103set style line 6 lc rgb '#ffff00'
104
105set style line 7 lc rgb '#ff00ff'
106set style line 8 lc rgb '#ffc0ff'
107
108set style line 9 lc rgb '#004040'
109set style line 10 lc rgb '#008080'
110set style line 11 lc rgb '#40c0c0'
111set style line 12 lc rgb '#c0f0f0'
112
113set style line 13 lc rgb '#004000'
114set style line 14 lc rgb '#008000'
115set style line 15 lc rgb '#40c040'
116set style line 16 lc rgb '#c0f0c0'
117
118set style line 17 lc rgb '#2020f0'
119set style line 18 lc rgb '#6060f0'
120set style line 19 lc rgb '#a0a0f0'
121
122set style line 20 lc rgb '#000000'
123set style line 21 lc rgb '#ffffff'
124
125plot for [i=2:MAXCOL] '$file' using 1:(sum [col=i:MAXCOL] column(col)) \
126title columnheader(i) with filledcurve y1=0 ls i
127EOF
128
129
130
131