run-perf.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #! /bin/sh
  2. #
  3. # Copyright 2016 the V8 project authors. All rights reserved.
  4. # Use of this source code is governed by a BSD-style license that can be
  5. # found in the LICENSE file.
  6. #
  7. ########## Global variable definitions
  8. # Ensure that <your CPU clock> / $SAMPLE_EVERY_N_CYCLES < $MAXIMUM_SAMPLE_RATE.
  9. MAXIMUM_SAMPLE_RATE=10000000
  10. SAMPLE_EVERY_N_CYCLES=10000
  11. SAMPLE_RATE_CONFIG_FILE="/proc/sys/kernel/perf_event_max_sample_rate"
  12. KERNEL_MAP_CONFIG_FILE="/proc/sys/kernel/kptr_restrict"
  13. CALL_GRAPH_METHOD="fp" # dwarf does not play nice with JITted objects.
  14. EVENT_TYPE=${EVENT_TYPE:=cycles:u}
  15. ########## Usage
  16. usage() {
  17. cat << EOF
  18. usage: $0 <benchmark_command>
  19. Executes <benchmark_command> under observation by Linux perf.
  20. Sampling event is cycles in user space, call graphs are recorded.
  21. EOF
  22. }
  23. if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
  24. usage
  25. exit 1
  26. fi
  27. ########## Actual script execution
  28. ACTUAL_SAMPLE_RATE=$(cat $SAMPLE_RATE_CONFIG_FILE)
  29. if [ "$ACTUAL_SAMPLE_RATE" -lt "$MAXIMUM_SAMPLE_RATE" ] ; then
  30. echo "Setting appropriate maximum sample rate..."
  31. echo $MAXIMUM_SAMPLE_RATE | sudo tee $SAMPLE_RATE_CONFIG_FILE
  32. fi
  33. ACTUAL_KERNEL_MAP_RESTRICTION=$(cat $KERNEL_MAP_CONFIG_FILE)
  34. if [ "$ACTUAL_KERNEL_MAP_RESTRICTION" -ne "0" ] ; then
  35. echo "Disabling kernel address map restriction..."
  36. echo 0 | sudo tee $KERNEL_MAP_CONFIG_FILE
  37. fi
  38. # Extract the command being perfed, so that we can prepend arguments to the
  39. # arguments that the user supplied.
  40. COMMAND=$1
  41. shift 1
  42. echo "Running..."
  43. perf record -R \
  44. -e $EVENT_TYPE \
  45. -c $SAMPLE_EVERY_N_CYCLES \
  46. --call-graph $CALL_GRAPH_METHOD \
  47. -i "$COMMAND" --perf-basic-prof "$@"