cpufreq-bench_plot.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #!/bin/bash
  2. # This program is free software: you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 2, or (at your option)
  5. # any later version.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program; if not, write to the Free Software
  12. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  13. # 02110-1301, USA.
  14. # Author/Copyright(c): 2009, Thomas Renninger <trenn@suse.de>, Novell Inc.
  15. # Helper script to easily create nice plots of your cpufreq-bench results
  16. dir=`mktemp -d`
  17. output_file="cpufreq-bench.png"
  18. global_title="cpufreq-bench plot"
  19. picture_type="jpeg"
  20. file[0]=""
  21. function usage()
  22. {
  23. echo "cpufreq-bench_plot.sh [OPTIONS] logfile [measure_title] [logfile [measure_title]] ...]"
  24. echo
  25. echo "Options"
  26. echo " -o output_file"
  27. echo " -t global_title"
  28. echo " -p picture_type [jpeg|gif|png|postscript|...]"
  29. exit 1
  30. }
  31. if [ $# -eq 0 ];then
  32. echo "No benchmark results file provided"
  33. echo
  34. usage
  35. fi
  36. while getopts o:t:p: name ; do
  37. case $name in
  38. o)
  39. output_file="$OPTARG".$picture_type
  40. ;;
  41. t)
  42. global_title="$OPTARG"
  43. ;;
  44. p)
  45. picture_type="$OPTARG"
  46. ;;
  47. ?)
  48. usage
  49. ;;
  50. esac
  51. done
  52. shift $(($OPTIND -1))
  53. plots=0
  54. while [ "$1" ];do
  55. if [ ! -f "$1" ];then
  56. echo "File $1 does not exist"
  57. usage
  58. fi
  59. file[$plots]="$1"
  60. title[$plots]="$2"
  61. # echo "File: ${file[$plots]} - ${title[plots]}"
  62. shift;shift
  63. plots=$((plots + 1))
  64. done
  65. echo "set terminal $picture_type" >> $dir/plot_script.gpl
  66. echo "set output \"$output_file\"" >> $dir/plot_script.gpl
  67. echo "set title \"$global_title\"" >> $dir/plot_script.gpl
  68. echo "set xlabel \"sleep/load time\"" >> $dir/plot_script.gpl
  69. echo "set ylabel \"Performance (%)\"" >> $dir/plot_script.gpl
  70. for((plot=0;plot<$plots;plot++));do
  71. # Sanity check
  72. ###### I am to dump to get this redirected to stderr/stdout in one awk call... #####
  73. cat ${file[$plot]} |grep -v "^#" |awk '{if ($2 != $3) printf("Error in measure %d:Load time %s does not equal sleep time %s, plot will not be correct\n", $1, $2, $3); ERR=1}'
  74. ###### I am to dump to get this redirected in one awk call... #####
  75. # Parse out load time (which must be equal to sleep time for a plot), divide it by 1000
  76. # to get ms and parse out the performance in percentage and write it to a temp file for plotting
  77. cat ${file[$plot]} |grep -v "^#" |awk '{printf "%lu %.1f\n",$2/1000, $6}' >$dir/data_$plot
  78. if [ $plot -eq 0 ];then
  79. echo -n "plot " >> $dir/plot_script.gpl
  80. fi
  81. echo -n "\"$dir/data_$plot\" title \"${title[$plot]}\" with lines" >> $dir/plot_script.gpl
  82. if [ $(($plot + 1)) -ne $plots ];then
  83. echo -n ", " >> $dir/plot_script.gpl
  84. fi
  85. done
  86. echo >> $dir/plot_script.gpl
  87. gnuplot $dir/plot_script.gpl
  88. rm -r $dir