Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright 2012 the V8 project authors. All rights reserved. |
| 4 | # Redistribution and use in source and binary forms, with or without |
| 5 | # modification, are permitted provided that the following conditions are |
| 6 | # met: |
| 7 | # |
| 8 | # * Redistributions of source code must retain the above copyright |
| 9 | # notice, this list of conditions and the following disclaimer. |
| 10 | # * Redistributions in binary form must reproduce the above |
| 11 | # copyright notice, this list of conditions and the following |
| 12 | # disclaimer in the documentation and/or other materials provided |
| 13 | # with the distribution. |
| 14 | # * Neither the name of Google Inc. nor the names of its |
| 15 | # contributors may be used to endorse or promote products derived |
| 16 | # from this software without specific prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | ########## Global variable definitions |
| 31 | |
| 32 | # Ensure that <your CPU clock> / $SAMPLE_EVERY_N_CYCLES < $MAXIMUM_SAMPLE_RATE. |
| 33 | MAXIMUM_SAMPLE_RATE=10000000 |
| 34 | SAMPLE_EVERY_N_CYCLES=10000 |
| 35 | SAMPLE_RATE_CONFIG_FILE="/proc/sys/kernel/perf_event_max_sample_rate" |
| 36 | KERNEL_MAP_CONFIG_FILE="/proc/sys/kernel/kptr_restrict" |
| 37 | |
| 38 | ########## Usage |
| 39 | |
| 40 | usage() { |
| 41 | cat << EOF |
| 42 | usage: $0 <benchmark_command> |
| 43 | |
| 44 | Executes <benchmark_command> under observation by the kernel's "perf" \ |
| 45 | framework, then calls the low level tick processor to analyze the results. |
| 46 | EOF |
| 47 | } |
| 48 | |
| 49 | if [ $# -eq 0 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ] ; then |
| 50 | usage |
| 51 | exit 1 |
| 52 | fi |
| 53 | |
| 54 | ########## Actual script execution |
| 55 | |
| 56 | ACTUAL_SAMPLE_RATE=$(cat $SAMPLE_RATE_CONFIG_FILE) |
| 57 | if [ "$ACTUAL_SAMPLE_RATE" -lt "$MAXIMUM_SAMPLE_RATE" ] ; then |
| 58 | echo "Setting appropriate maximum sample rate..." |
| 59 | echo $MAXIMUM_SAMPLE_RATE | sudo tee $SAMPLE_RATE_CONFIG_FILE |
| 60 | fi |
| 61 | |
| 62 | ACTUAL_KERNEL_MAP_RESTRICTION=$(cat $KERNEL_MAP_CONFIG_FILE) |
| 63 | if [ "$ACTUAL_KERNEL_MAP_RESTRICTION" -ne "0" ] ; then |
| 64 | echo "Disabling kernel address map restriction..." |
| 65 | echo 0 | sudo tee $KERNEL_MAP_CONFIG_FILE |
| 66 | fi |
| 67 | |
| 68 | echo "Running benchmark..." |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 69 | perf record -R -e cycles -c $SAMPLE_EVERY_N_CYCLES -i $@ --ll-prof |