starpu_paje_state_stats.in 3.5 KB

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