OLD | NEW |
---|---|
(Empty) | |
1 #! /bin/bash | |
Stefano Sanfilippo
2016/03/09 18:23:55
bash and not sh because of the == between strings
| |
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 | |
8 ########## Global variable definitions | |
9 | |
10 # Ensure that <your CPU clock> / $SAMPLE_EVERY_N_CYCLES < $MAXIMUM_SAMPLE_RATE. | |
11 MAXIMUM_SAMPLE_RATE=10000000 | |
12 SAMPLE_EVERY_N_CYCLES=10000 | |
13 SAMPLE_RATE_CONFIG_FILE="/proc/sys/kernel/perf_event_max_sample_rate" | |
14 KERNEL_MAP_CONFIG_FILE="/proc/sys/kernel/kptr_restrict" | |
15 CALL_GRAPH_METHOD="fp" # dwarf does not play nice with JITted objects. | |
16 | |
17 ########## Usage | |
18 | |
19 usage() { | |
20 cat << EOF | |
21 usage: $0 <benchmark_command> | |
22 | |
23 Executes <benchmark_command> under observation by Linux perf. | |
24 Sampling event is cycles in user space, call graphs are recorded. | |
25 EOF | |
26 } | |
27 | |
28 if [ $# -eq 0 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ] ; then | |
29 usage | |
30 exit 1 | |
31 fi | |
32 | |
33 ########## Actual script execution | |
34 | |
35 ACTUAL_SAMPLE_RATE=$(cat $SAMPLE_RATE_CONFIG_FILE) | |
36 if [ "$ACTUAL_SAMPLE_RATE" -lt "$MAXIMUM_SAMPLE_RATE" ] ; then | |
37 echo "Setting appropriate maximum sample rate..." | |
38 echo $MAXIMUM_SAMPLE_RATE | sudo tee $SAMPLE_RATE_CONFIG_FILE | |
39 fi | |
40 | |
41 ACTUAL_KERNEL_MAP_RESTRICTION=$(cat $KERNEL_MAP_CONFIG_FILE) | |
42 if [ "$ACTUAL_KERNEL_MAP_RESTRICTION" -ne "0" ] ; then | |
43 echo "Disabling kernel address map restriction..." | |
44 echo 0 | sudo tee $KERNEL_MAP_CONFIG_FILE | |
45 fi | |
46 | |
47 echo "Running benchmark..." | |
48 perf record -R \ | |
49 -e cycles:u \ | |
50 -c $SAMPLE_EVERY_N_CYCLES \ | |
51 --call-graph $CALL_GRAPH_METHOD \ | |
52 -i $@ --perf_basic_prof | |
OLD | NEW |