Debian Codegraph @

testing/Scripts/test-perf

raw
1 #! /usr/bin/env bash
2 #
3 # This script imitates the behavior of the Linux "perf" command. Useful
4 # for testing purposes because this script produces consistent and
5 # predictable results.
6 #
7 # NOTE: if this script is in PATH, then it should not be named "perf", because
8 # we want to use the real perf command for some tests.
9
10 # Only "perf stat" is supported.
11 if [ "$1" != "stat" ]; then
12 exit 1
13 fi
14 shift
15
16 # Ignore all options except "-o".
17 while getopts "o:x:e:" arg; do
18 case $arg in
19 o)
20 fname=$OPTARG
21 ;;
22 *) ;;
23
24 esac
25 done
26
27 shift $((OPTIND - 1))
28
29 # Use a hard-coded message so that we get predictable results
30 msg="1000 instructions"
31
32 # Write the message to a file (if specified), or stderr
33 if [ -n "$fname" ]; then
34 echo "$msg" >"$fname"
35 else
36 echo "$msg" >&2
37 fi
38
39 # Run the specified command
40 "$@"