starpu_paje_state_stats.in 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/bin/bash
  2. # StarPU --- Runtime system for heterogeneous multicore architectures.
  3. #
  4. # Copyright (C) 2014-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  5. # Copyright (C) 2014 Université Joseph Fourier
  6. #
  7. # StarPU is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation; either version 2.1 of the License, or (at
  10. # your option) any later version.
  11. #
  12. # StarPU is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. #
  16. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. #
  18. # Script for giving statistical analysis of the paje trace
  19. set -e # fail fast
  20. # File names
  21. outputfile="starpu_paje_state_stats.csv"
  22. r_script="$(dirname $(which $0))/starpu_paje_state_stats.R"
  23. r_input=""
  24. # Command line arguments
  25. range="0:-1"
  26. name="All"
  27. verbose=0
  28. inputfiles=""
  29. help_script()
  30. {
  31. cat << EOF
  32. Give statistical analysis of the paje trace
  33. $0 [ options ] paje.trace [paje.trace2 ...]
  34. Options:
  35. -r To fix range x1:x2 ("-1" for infinity)
  36. -n To choose a certain state
  37. -v Print output to command line
  38. -h Show this message
  39. Examples:
  40. $0 example.native.trace
  41. $0 -r 100:300 -n FetchingInput -v example.native.trace example.simgrid.trace
  42. Report bugs to <@PACKAGE_BUGREPORT@>
  43. EOF
  44. }
  45. if [ "$1" = "--version" ] ; then
  46. echo "$PROGNAME (@PACKAGE_NAME@) @PACKAGE_VERSION@"
  47. exit 0
  48. fi
  49. if [ "$1" = "-h" ] || [ "$1" = "--help" ] || [ "$1" = "" ] ; then
  50. help_script
  51. exit 0
  52. fi
  53. while getopts "r:n:vh" opt; do
  54. case $opt in
  55. r)
  56. range="$OPTARG"
  57. ;;
  58. n)
  59. name="$OPTARG"
  60. ;;
  61. v)
  62. verbose=1
  63. ;;
  64. h)
  65. help_script
  66. exit 4
  67. ;;
  68. \?)
  69. echo "Invalid option: -$OPTARG"
  70. help_script
  71. exit 3
  72. ;;
  73. esac
  74. done
  75. # Reading files that need to be analyzed
  76. shift $((OPTIND - 1))
  77. inputfiles=$@
  78. if [[ $# < 1 ]]; then
  79. echo "Error!"
  80. help_script
  81. exit 2
  82. fi
  83. # Getting range
  84. range1=$(eval echo $range | cut -d: -f1)
  85. range2=$(eval echo $range | cut -d: -f2)
  86. #####################################
  87. # Transforming input files into .csv
  88. for file in $inputfiles; do
  89. if [ ! -s $file ]
  90. then
  91. echo "Error: file $file does not exist!"
  92. exit 5
  93. fi
  94. dir=$(dirname $file)
  95. # Sorting traces
  96. grep -e '^\(\(%\)\|\(\(0\|1\|2\|3\|4\|5\|6\|7\)\>\)\)' $file > $dir/start.trace
  97. grep -e '^\(\(%\)\|\(\(0\|1\|2\|3\|4\|5\|6\|7\)\>\)\)' -v $file > $dir/end.trace
  98. sort -s -V --key=2,2 $dir/end.trace > $dir/endSorted.trace
  99. if grep -q start_profiling $dir/endSorted.trace
  100. then
  101. echo Using start_profiling/stop_profiling trace selection.
  102. sed -ne '/start_profiling/,/stop_profiling/p' < $dir/endSorted.trace > $dir/endSorted2.trace
  103. else
  104. cp $dir/endSorted.trace $dir/endSorted2.trace
  105. fi
  106. cat $dir/start.trace $dir/endSorted2.trace > $dir/outputSorted.trace
  107. # Transferring to .csv
  108. pj_dump -n $dir/outputSorted.trace > $file.csv
  109. perl -i -ne 'print if /^State/' $file.csv
  110. r_input=$(eval echo "$r_input $file.csv")
  111. # Cleanup: delete temporary files
  112. rm -f $dir/outputSorted.trace
  113. rm -f $dir/start.trace
  114. rm -f $dir/end.trace
  115. rm -f $dir/endSorted.trace
  116. rm -f $dir/endSorted2.trace
  117. done
  118. #####################################
  119. # Running R file to get actual results
  120. Rscript $r_script $range1 $range2 $name $outputfile $r_input
  121. # If verbose then write results to stdout
  122. if [[ $verbose == 1 ]]; then
  123. column -s, -t $outputfile
  124. fi