bb-matrix-plot.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2011, Intel Corporation.
  4. #
  5. # SPDX-License-Identifier: GPL-2.0-or-later
  6. #
  7. # DESCRIPTION
  8. # This script operates on the .dat file generated by bb-matrix.sh. It tolerates
  9. # the header by skipping the first line, but error messages and bad data records
  10. # need to be removed first. It will generate three views of the plot, and leave
  11. # an interactive view open for further analysis.
  12. #
  13. # AUTHORS
  14. # Darren Hart <dvhart@linux.intel.com>
  15. #
  16. # Setup the defaults
  17. DATFILE="bb-matrix.dat"
  18. XLABEL="BB_NUMBER_THREADS"
  19. YLABEL="PARALLEL_MAKE"
  20. FIELD=3
  21. DEF_TITLE="Elapsed Time (seconds)"
  22. PM3D_FRAGMENT="unset surface; set pm3d at s hidden3d 100"
  23. SIZE="640,480"
  24. function usage {
  25. CMD=$(basename $0)
  26. cat <<EOM
  27. Usage: $CMD [-d datfile] [-f field] [-h] [-t title] [-w]
  28. -d datfile The data file generated by bb-matrix.sh (default: $DATFILE)
  29. -f field The field index to plot as the Z axis from the data file
  30. (default: $FIELD, "$DEF_TITLE")
  31. -h Display this help message
  32. -s W,H PNG and window size in pixels (default: $SIZE)
  33. -t title The title to display, should describe the field (-f) and units
  34. (default: "$DEF_TITLE")
  35. -w Render the plot as wireframe with a 2D colormap projected on the
  36. XY plane rather than as the texture for the surface
  37. EOM
  38. }
  39. # Parse and validate arguments
  40. while getopts "d:f:hs:t:w" OPT; do
  41. case $OPT in
  42. d)
  43. DATFILE="$OPTARG"
  44. ;;
  45. f)
  46. FIELD="$OPTARG"
  47. ;;
  48. h)
  49. usage
  50. exit 0
  51. ;;
  52. s)
  53. SIZE="$OPTARG"
  54. ;;
  55. t)
  56. TITLE="$OPTARG"
  57. ;;
  58. w)
  59. PM3D_FRAGMENT="set pm3d at b"
  60. W="-w"
  61. ;;
  62. *)
  63. usage
  64. exit 1
  65. ;;
  66. esac
  67. done
  68. # Ensure the data file exists
  69. if [ ! -f "$DATFILE" ]; then
  70. echo "ERROR: $DATFILE does not exist"
  71. usage
  72. exit 1
  73. fi
  74. PLOT_BASENAME=${DATFILE%.*}-f$FIELD$W
  75. # Set a sane title
  76. # TODO: parse the header and define titles for each format parameter for TIME(1)
  77. if [ -z "$TITLE" ]; then
  78. if [ ! "$FIELD" == "3" ]; then
  79. TITLE="Field $FIELD"
  80. else
  81. TITLE="$DEF_TITLE"
  82. fi
  83. fi
  84. # Determine the dgrid3d mesh dimensions size
  85. MIN=$(tail -n +2 "$DATFILE" | cut -d ' ' -f 1 | sed 's/^0*//' | sort -n | uniq | head -n1)
  86. MAX=$(tail -n +2 "$DATFILE" | cut -d ' ' -f 1 | sed 's/^0*//' | sort -n | uniq | tail -n1)
  87. BB_CNT=$[${MAX} - $MIN + 1]
  88. MIN=$(tail -n +2 "$DATFILE" | cut -d ' ' -f 2 | sed 's/^0*//' | sort -n | uniq | head -n1)
  89. MAX=$(tail -n +2 "$DATFILE" | cut -d ' ' -f 2 | sed 's/^0*//' | sort -n | uniq | tail -n1)
  90. PM_CNT=$[${MAX} - $MIN + 1]
  91. (cat <<EOF
  92. set title "$TITLE"
  93. set xlabel "$XLABEL"
  94. set ylabel "$YLABEL"
  95. set style line 100 lt 5 lw 1.5
  96. $PM3D_FRAGMENT
  97. set dgrid3d $PM_CNT,$BB_CNT splines
  98. set ticslevel 0.2
  99. set term png size $SIZE
  100. set output "$PLOT_BASENAME.png"
  101. splot "$DATFILE" every ::1 using 1:2:$FIELD with lines ls 100
  102. set view 90,0
  103. set output "$PLOT_BASENAME-bb.png"
  104. replot
  105. set view 90,90
  106. set output "$PLOT_BASENAME-pm.png"
  107. replot
  108. set view 60,30
  109. set term wxt size $SIZE
  110. replot
  111. EOF
  112. ) | gnuplot --persist