-
Notifications
You must be signed in to change notification settings - Fork 1
/
run
201 lines (152 loc) · 4.61 KB
/
run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/bin/bash
# Help
print_help() {
cat << EOF
Usage: sh run [OPTIONS] PROGRAM
Run a performance analysis.
Options:
-h print help
-n RUNS set the number of test runs
Optional environment variables:
GRAALVM_HOME the path to a build of GraalVM
JAVA_HOME the path to a build of OpenJDK
JFR_TESTS the path to a jfr-tests Git repository
EOF
}
# Options parsing
RUNS=100
while getopts "hn:" opt; do
case "$opt" in
h) print_help
exit 0;;
n) RUNS="$OPTARG";;
esac
done
shift "$((OPTIND-1))"
# Variables
BUILD_DIR="$(pwd)/build"
mkdir -p "$BUILD_DIR"
if [[ -z "$1" ]]; then
echo "Test program must be specified."
echo
print_help
exit 1
fi
TEST_PROGRAM="$1"
if [[ -z $GRAALVM_HOME ]]; then
GRAALVM_HOME="$BUILD_DIR"/graalvm
fi
if [[ ! -d $GRAALVM_HOME ]]; then
echo "GRAALVM_HOME not found."
echo
print_help
exit 1
fi
if [[ -z $JAVA_HOME ]]; then
JAVA_HOME="$BUILD_DIR"/openjdk
fi
if [[ ! -d $JAVA_HOME ]]; then
echo "JAVA_HOME not found."
echo
print_help
exit 1
fi
if [[ -z $JFR_TESTS ]]; then
JFR_TESTS="$BUILD_DIR"/jfr-tests
fi
if [[ ! -d $JFR_TESTS ]]; then
echo "JFR_TESTS not found."
echo
print_help
exit 1
fi
JAVAC="$JAVA_HOME/bin/javac"
JAVA="$JAVA_HOME/bin/java"
# Output files
rm -rf results
mkdir -p results
OPENJDK_CPU="$(pwd)/results/OpenJDK_CPU.csv"
OPENJDK_RES="$(pwd)/results/OpenJDK_RES.csv"
OPENJDK_TIME="$(pwd)/results/OpenJDK_TIME.csv"
GRAALVM_CPU="$(pwd)/results/GraalVM_CPU.csv"
GRAALVM_RES="$(pwd)/results/GraalVM_RES.csv"
GRAALVM_TIME="$(pwd)/results/GraalVM_TIME.csv"
GRAALVM_SIZE="$(pwd)/results/GraalVM_SIZE.csv"
touch "$OPENJDK_CPU"
touch "$OPENJDK_RES"
touch "$OPENJDK_TIME"
touch "$GRAALVM_CPU"
touch "$GRAALVM_RES"
touch "$GRAALVM_TIME"
touch "$GRAALVM_SIZE"
# Compile jfr-tests
cd "$JFR_TESTS"
cp pom.xml /tmp/jfr-tests-pom.xml
sed -i "s:<executable>.*</executable>:<executable>$JAVAC</executable>:" pom.xml
mvn clean compile
cp /tmp/jfr-tests-pom.xml pom.xml
CLASSPATH="$(pwd)/target/classes"
cd -
# Build the native image
mkdir -p "$BUILD_DIR"
"$GRAALVM_HOME"/bin/gu install native-image
"$GRAALVM_HOME"/bin/native-image -H:+AllowVMInspection -cp "$CLASSPATH" "$TEST_PROGRAM" "$BUILD_DIR"/"$TEST_PROGRAM"
ls -l "$BUILD_DIR" | grep " $TEST_PROGRAM\$" | awk '{print $5;}' > "$GRAALVM_SIZE"
# Function for running a GraalVM test
# $1 = iteration number of this test
test_graalvm() {
OUTPUT_FILE="/tmp/GraalVM_$1"
top -b | grep "$BUILD_DIR" | grep -v "usr/bin/time" | grep -v "grep" > "$OUTPUT_FILE" &
sleep 0.5
LAST_GREP="$!"
/usr/bin/time -f "%e,%S,%U" -o "/tmp/time" "$BUILD_DIR"/"$TEST_PROGRAM" -XX:+FlightRecorder
killall top
wait $LAST_GREP
cat "/tmp/time" >> "$OUTPUT_FILE"
}
# Function for running an OpenJDK test
# $1 = iteration number of this test
test_openjdk() {
OUTPUT_FILE="/tmp/OpenJDK_$1"
top -b | grep "$JAVA" | grep -v "usr/bin/time" | grep -v "grep" > "$OUTPUT_FILE" &
sleep 0.5
LAST_GREP="$!"
/usr/bin/time -f "%e,%S,%U" -o "/tmp/time" "$JAVA" -cp "$CLASSPATH" "$TEST_PROGRAM"
killall top
wait $LAST_GREP
cat "/tmp/time" >> "$OUTPUT_FILE"
}
# Run the tests
# Remove recordings after to save space
for i in $(seq 1 "$RUNS"); do
test_graalvm $i
test_openjdk $i
rm /tmp/*.jfr
done
# Function for parsing the individual GraalVM output files and writing them to the final output files
# $1 = path to the individual test output file
parse_graalvm() {
OUTPUT_FILE="$1"
INTERMEDIATE="$OUTPUT_FILE"_INTERMEDIATE
tail -n 1 "$OUTPUT_FILE" >> "$GRAALVM_TIME"
head -n -1 "$OUTPUT_FILE" > "$INTERMEDIATE"
awk -i inplace '{print $(NF-1), $NF}' "$INTERMEDIATE"
awk '{printf "%s,", $1}' "$INTERMEDIATE" | awk '{print substr($0, 1, length($0)-1)}' >> "$GRAALVM_CPU"
awk '{printf "%s,", $2}' "$INTERMEDIATE" | awk '{print substr($0, 1, length($0)-1)}' >> "$GRAALVM_RES"
}
# Function for parsing the individual OpenJDK output files and writing them to the final output files
# $1 = path to the individual test output file
parse_openjdk() {
OUTPUT_FILE="$1"
INTERMEDIATE="$OUTPUT_FILE"_INTERMEDIATE
tail -n 1 "$OUTPUT_FILE" >> "$OPENJDK_TIME"
head -n -1 "$OUTPUT_FILE" > "$INTERMEDIATE"
awk -i inplace '{print $(NF-1), $NF}' "$INTERMEDIATE"
awk '{printf "%s,", $1}' "$INTERMEDIATE" | awk '{print substr($0, 1, length($0)-1)}' >> "$OPENJDK_CPU"
awk '{printf "%s,", $2}' "$INTERMEDIATE" | awk '{print substr($0, 1, length($0)-1)}' >> "$OPENJDK_RES"
}
# parse all the individual test results
for i in $(seq 1 "$RUNS"); do
parse_graalvm /tmp/GraalVM_$i
parse_openjdk /tmp/OpenJDK_$i
done