11cb0ef41Sopenharmony_ci#!/bin/bash 21cb0ef41Sopenharmony_ci# 31cb0ef41Sopenharmony_ci# Copyright 2013 the V8 project authors. All rights reserved. 41cb0ef41Sopenharmony_ci# Redistribution and use in source and binary forms, with or without 51cb0ef41Sopenharmony_ci# modification, are permitted provided that the following conditions are 61cb0ef41Sopenharmony_ci# met: 71cb0ef41Sopenharmony_ci# 81cb0ef41Sopenharmony_ci# * Redistributions of source code must retain the above copyright 91cb0ef41Sopenharmony_ci# notice, this list of conditions and the following disclaimer. 101cb0ef41Sopenharmony_ci# * Redistributions in binary form must reproduce the above 111cb0ef41Sopenharmony_ci# copyright notice, this list of conditions and the following 121cb0ef41Sopenharmony_ci# disclaimer in the documentation and/or other materials provided 131cb0ef41Sopenharmony_ci# with the distribution. 141cb0ef41Sopenharmony_ci# * Neither the name of Google Inc. nor the names of its 151cb0ef41Sopenharmony_ci# contributors may be used to endorse or promote products derived 161cb0ef41Sopenharmony_ci# from this software without specific prior written permission. 171cb0ef41Sopenharmony_ci# 181cb0ef41Sopenharmony_ci# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 191cb0ef41Sopenharmony_ci# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 201cb0ef41Sopenharmony_ci# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 211cb0ef41Sopenharmony_ci# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 221cb0ef41Sopenharmony_ci# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 231cb0ef41Sopenharmony_ci# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 241cb0ef41Sopenharmony_ci# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 251cb0ef41Sopenharmony_ci# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 261cb0ef41Sopenharmony_ci# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 271cb0ef41Sopenharmony_ci# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 281cb0ef41Sopenharmony_ci# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci# This script reads in CSV formatted instruction data, and draws a stacked 311cb0ef41Sopenharmony_ci# graph in png format. 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_cidefaultfile=arm64_inst.csv 341cb0ef41Sopenharmony_cidefaultout=arm64_inst.png 351cb0ef41Sopenharmony_cignuplot=/usr/bin/gnuplot 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci# File containing CSV instruction data from simulator. 391cb0ef41Sopenharmony_cifile=${1:-$defaultfile} 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci# Output graph png file. 421cb0ef41Sopenharmony_ciout=${2:-$defaultout} 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci# Check input file exists. 451cb0ef41Sopenharmony_ciif [ ! -e $file ]; then 461cb0ef41Sopenharmony_ci echo "Input file not found: $file." 471cb0ef41Sopenharmony_ci echo "Usage: draw_instruction_graph.sh <input csv> <output png>" 481cb0ef41Sopenharmony_ci exit 1 491cb0ef41Sopenharmony_cifi 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci# Search for an error message, and if found, exit. 521cb0ef41Sopenharmony_cierror=`grep -m1 '# Error:' $file` 531cb0ef41Sopenharmony_ciif [ -n "$error" ]; then 541cb0ef41Sopenharmony_ci echo "Error message in input file:" 551cb0ef41Sopenharmony_ci echo " $error" 561cb0ef41Sopenharmony_ci exit 2 571cb0ef41Sopenharmony_cifi 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci# Sample period - period over which numbers for each category of instructions is 601cb0ef41Sopenharmony_ci# counted. 611cb0ef41Sopenharmony_cisp=`grep -m1 '# sample_period=' $file | cut -d= -f2` 621cb0ef41Sopenharmony_ci 631cb0ef41Sopenharmony_ci# Get number of counters in the CSV file. 641cb0ef41Sopenharmony_cinc=`grep -m1 '# counters=' $file | cut -d= -f2` 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_ci# Find the annotation arrows. They appear as comments in the CSV file, in the 671cb0ef41Sopenharmony_ci# format: 681cb0ef41Sopenharmony_ci# # xx @ yyyyy 691cb0ef41Sopenharmony_ci# Where xx is a two character annotation identifier, and yyyyy is the 701cb0ef41Sopenharmony_ci# position in the executed instruction stream that generated the annotation. 711cb0ef41Sopenharmony_ci# Turn these locations into labelled arrows. 721cb0ef41Sopenharmony_ciarrows=`sed '/^[^#]/ d' $file | \ 731cb0ef41Sopenharmony_ci perl -pe "s/^# .. @ (\d+)/set arrow from \1, graph 0.9 to \1, $sp/"`; 741cb0ef41Sopenharmony_cilabels=`sed '/^[^#]/d' $file | \ 751cb0ef41Sopenharmony_ci sed -r 's/^# (..) @ (.+)/set label at \2, graph 0.9 "\1" \ 761cb0ef41Sopenharmony_ci center offset 0,0.5 font "FreeSans, 8"/'`; 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci# Check for gnuplot, and warn if not available. 791cb0ef41Sopenharmony_ciif [ ! -e $gnuplot ]; then 801cb0ef41Sopenharmony_ci echo "Can't find gnuplot at $gnuplot." 811cb0ef41Sopenharmony_ci echo "Gnuplot version 4.6.3 or later required." 821cb0ef41Sopenharmony_ci exit 3 831cb0ef41Sopenharmony_cifi 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci# Initialise gnuplot, and give it the data to draw. 861cb0ef41Sopenharmony_ciecho | $gnuplot <<EOF 871cb0ef41Sopenharmony_ci$arrows 881cb0ef41Sopenharmony_ci$labels 891cb0ef41Sopenharmony_ciMAXCOL=$nc 901cb0ef41Sopenharmony_ciset term png size 1920, 800 #ffffff 911cb0ef41Sopenharmony_ciset output '$out' 921cb0ef41Sopenharmony_ciset datafile separator ',' 931cb0ef41Sopenharmony_ciset xtics font 'FreeSans, 10' 941cb0ef41Sopenharmony_ciset xlabel 'Instructions' font 'FreeSans, 10' 951cb0ef41Sopenharmony_ciset ytics font 'FreeSans, 10' 961cb0ef41Sopenharmony_ciset yrange [0:*] 971cb0ef41Sopenharmony_ciset key outside font 'FreeSans, 8' 981cb0ef41Sopenharmony_ci 991cb0ef41Sopenharmony_ciset style line 2 lc rgb '#800000' 1001cb0ef41Sopenharmony_ciset style line 3 lc rgb '#d00000' 1011cb0ef41Sopenharmony_ciset style line 4 lc rgb '#ff6000' 1021cb0ef41Sopenharmony_ciset style line 5 lc rgb '#ffc000' 1031cb0ef41Sopenharmony_ciset style line 6 lc rgb '#ffff00' 1041cb0ef41Sopenharmony_ci 1051cb0ef41Sopenharmony_ciset style line 7 lc rgb '#ff00ff' 1061cb0ef41Sopenharmony_ciset style line 8 lc rgb '#ffc0ff' 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ciset style line 9 lc rgb '#004040' 1091cb0ef41Sopenharmony_ciset style line 10 lc rgb '#008080' 1101cb0ef41Sopenharmony_ciset style line 11 lc rgb '#40c0c0' 1111cb0ef41Sopenharmony_ciset style line 12 lc rgb '#c0f0f0' 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_ciset style line 13 lc rgb '#004000' 1141cb0ef41Sopenharmony_ciset style line 14 lc rgb '#008000' 1151cb0ef41Sopenharmony_ciset style line 15 lc rgb '#40c040' 1161cb0ef41Sopenharmony_ciset style line 16 lc rgb '#c0f0c0' 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_ciset style line 17 lc rgb '#2020f0' 1191cb0ef41Sopenharmony_ciset style line 18 lc rgb '#6060f0' 1201cb0ef41Sopenharmony_ciset style line 19 lc rgb '#a0a0f0' 1211cb0ef41Sopenharmony_ci 1221cb0ef41Sopenharmony_ciset style line 20 lc rgb '#000000' 1231cb0ef41Sopenharmony_ciset style line 21 lc rgb '#ffffff' 1241cb0ef41Sopenharmony_ci 1251cb0ef41Sopenharmony_ciplot for [i=2:MAXCOL] '$file' using 1:(sum [col=i:MAXCOL] column(col)) \ 1261cb0ef41Sopenharmony_cititle columnheader(i) with filledcurve y1=0 ls i 1271cb0ef41Sopenharmony_ciEOF 1281cb0ef41Sopenharmony_ci 1291cb0ef41Sopenharmony_ci 1301cb0ef41Sopenharmony_ci 131