draw_instruction_graph.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. # This script reads in CSV formatted instruction data, and draws a stacked
  30. # graph in png format.
  31. defaultfile=arm64_inst.csv
  32. defaultout=arm64_inst.png
  33. gnuplot=/usr/bin/gnuplot
  34. # File containing CSV instruction data from simulator.
  35. file=${1:-$defaultfile}
  36. # Output graph png file.
  37. out=${2:-$defaultout}
  38. # Check input file exists.
  39. if [ ! -e $file ]; then
  40. echo "Input file not found: $file."
  41. echo "Usage: draw_instruction_graph.sh <input csv> <output png>"
  42. exit 1
  43. fi
  44. # Search for an error message, and if found, exit.
  45. error=`grep -m1 '# Error:' $file`
  46. if [ -n "$error" ]; then
  47. echo "Error message in input file:"
  48. echo " $error"
  49. exit 2
  50. fi
  51. # Sample period - period over which numbers for each category of instructions is
  52. # counted.
  53. sp=`grep -m1 '# sample_period=' $file | cut -d= -f2`
  54. # Get number of counters in the CSV file.
  55. nc=`grep -m1 '# counters=' $file | cut -d= -f2`
  56. # Find the annotation arrows. They appear as comments in the CSV file, in the
  57. # format:
  58. # # xx @ yyyyy
  59. # Where xx is a two character annotation identifier, and yyyyy is the
  60. # position in the executed instruction stream that generated the annotation.
  61. # Turn these locations into labelled arrows.
  62. arrows=`sed '/^[^#]/ d' $file | \
  63. perl -pe "s/^# .. @ (\d+)/set arrow from \1, graph 0.9 to \1, $sp/"`;
  64. labels=`sed '/^[^#]/d' $file | \
  65. sed -r 's/^# (..) @ (.+)/set label at \2, graph 0.9 "\1" \
  66. center offset 0,0.5 font "FreeSans, 8"/'`;
  67. # Check for gnuplot, and warn if not available.
  68. if [ ! -e $gnuplot ]; then
  69. echo "Can't find gnuplot at $gnuplot."
  70. echo "Gnuplot version 4.6.3 or later required."
  71. exit 3
  72. fi
  73. # Initialise gnuplot, and give it the data to draw.
  74. echo | $gnuplot <<EOF
  75. $arrows
  76. $labels
  77. MAXCOL=$nc
  78. set term png size 1920, 800 #ffffff
  79. set output '$out'
  80. set datafile separator ','
  81. set xtics font 'FreeSans, 10'
  82. set xlabel 'Instructions' font 'FreeSans, 10'
  83. set ytics font 'FreeSans, 10'
  84. set yrange [0:*]
  85. set key outside font 'FreeSans, 8'
  86. set style line 2 lc rgb '#800000'
  87. set style line 3 lc rgb '#d00000'
  88. set style line 4 lc rgb '#ff6000'
  89. set style line 5 lc rgb '#ffc000'
  90. set style line 6 lc rgb '#ffff00'
  91. set style line 7 lc rgb '#ff00ff'
  92. set style line 8 lc rgb '#ffc0ff'
  93. set style line 9 lc rgb '#004040'
  94. set style line 10 lc rgb '#008080'
  95. set style line 11 lc rgb '#40c0c0'
  96. set style line 12 lc rgb '#c0f0f0'
  97. set style line 13 lc rgb '#004000'
  98. set style line 14 lc rgb '#008000'
  99. set style line 15 lc rgb '#40c040'
  100. set style line 16 lc rgb '#c0f0c0'
  101. set style line 17 lc rgb '#2020f0'
  102. set style line 18 lc rgb '#6060f0'
  103. set style line 19 lc rgb '#a0a0f0'
  104. set style line 20 lc rgb '#000000'
  105. set style line 21 lc rgb '#ffffff'
  106. plot for [i=2:MAXCOL] '$file' using 1:(sum [col=i:MAXCOL] column(col)) \
  107. title columnheader(i) with filledcurve y1=0 ls i
  108. EOF