-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathplot-benchmarks.sh
More file actions
executable file
·401 lines (365 loc) · 15.1 KB
/
plot-benchmarks.sh
File metadata and controls
executable file
·401 lines (365 loc) · 15.1 KB
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/bin/bash
#
# JVM Performance Benchmarks
#
# Copyright (C) 2019-2025 Ionut Balosin
# Website: www.ionutbalosin.com
# Social Media:
# LinkedIn: ionutbalosin
# Bluesky: @ionutbalosin.bsky.social
# X: @ionutbalosin
# Mastodon: [email protected]
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
check_command_line_options() {
if [ ! $# -eq 1 ] && [ ! $# -eq 2 ]; then
echo "Usage: ./plot-benchmarks.sh <jdk-version> [<arch>]"
echo ""
echo "Options:"
echo " jdk-version Java version identifier for the generated results. Supported values are {11, 17, 21}."
echo " arch Target architecture for the generated results. If not specified, it is automatically detected based on the current target architecture. Supported values are {x86_64, arm64}."
echo ""
echo "Examples:"
echo " ./plot-benchmarks.sh 11"
echo " ./plot-benchmarks.sh 11 x86_64"
echo " ./plot-benchmarks.sh 11 arm64"
echo " ./plot-benchmarks.sh 17"
echo " ./plot-benchmarks.sh 17 x86_64"
echo " ./plot-benchmarks.sh 17 arm64"
echo " ./plot-benchmarks.sh 21"
echo " ./plot-benchmarks.sh 21 x86_64"
echo " ./plot-benchmarks.sh 21 arm64"
echo ""
return 1
fi
}
load_config_properties() {
if [ -f ./settings/config.properties ]; then
source ./settings/config.properties
echo "Configuration properties have been successfully loaded from the './settings/config.properties' file."
else
echo "ERROR: File './settings/config.properties' not found. Unable to continue!"
return 1
fi
}
check_folder_exists() {
folder="$1"
if [ ! -d "$folder" ]; then
echo ""
echo "ERROR: Folder '$folder' does not exist. Unable to continue!"
return 1
fi
}
set_environment_variables() {
export JDK_VERSION="${1:-$JDK_VERSION}"
export BENCHMARKS_ARCH="${2:-$ARCH}"
export JMH_BENCHMARKS="settings/benchmarks-suite-jdk${JDK_VERSION}.json"
export JMH_OUTPUT_FOLDER="$(pwd)/results/jdk-$JDK_VERSION/$BENCHMARKS_ARCH/jmh"
export GEOMETRIC_MEAN_OUTPUT_FOLDER="$(pwd)/results/jdk-$JDK_VERSION/$BENCHMARKS_ARCH/geomean"
export PLOT_OUTPUT_FOLDER="$(pwd)/results/jdk-$JDK_VERSION/$BENCHMARKS_ARCH/plot"
if ! check_folder_exists "$JMH_OUTPUT_FOLDER"; then
return 1
fi
echo "JDK version: $JDK_VERSION"
echo "JMH benchmarks architecture: $BENCHMARKS_ARCH"
echo "JMH benchmarks suite configuration file: $JMH_BENCHMARKS"
echo "JMH output folder: $JMH_OUTPUT_FOLDER"
echo "Geometric mean output folder: $GEOMETRIC_MEAN_OUTPUT_FOLDER"
echo "Plot output folder: $PLOT_OUTPUT_FOLDER"
}
select_processing_language() {
echo "Select the processing language for benchmark analysis:"
echo "1) R"
echo "2) Python"
while true; do
read -p "Enter your choice (1 or 2): " INPUT_KEY
case $INPUT_KEY in
1)
export PROCESSING_LANGUAGE="R"
export PROCESSING_SCRIPT_DIR="./scripts/ggplot2"
export PROCESSING_EXTENSION="r"
export PROCESSING_COMMAND="R"
echo "Selected: R processing"
break
;;
2)
export PROCESSING_LANGUAGE="Python"
export PROCESSING_SCRIPT_DIR="./scripts/python"
export PROCESSING_EXTENSION="py"
export PROCESSING_COMMAND="python3"
echo "Selected: Python processing"
break
;;
*)
echo "Sorry, I don't understand. Try again!"
;;
esac
done
}
merge_split_benchmark_results() {
if [ "$PROCESSING_LANGUAGE" = "R" ]; then
if $PROCESSING_COMMAND <$PROCESSING_SCRIPT_DIR/merge-benchmark.$PROCESSING_EXTENSION --no-save \
--args $JMH_OUTPUT_FOLDER $OPENJDK_HOTSPOT_VM_IDENTIFIER $GRAAL_VM_CE_IDENTIFIER $GRAAL_VM_EE_IDENTIFIER $AZUL_PRIME_VM_IDENTIFIER &&
$PROCESSING_COMMAND <$PROCESSING_SCRIPT_DIR/split-benchmark.$PROCESSING_EXTENSION --no-save \
--args $JMH_OUTPUT_FOLDER $OPENJDK_HOTSPOT_VM_IDENTIFIER $GRAAL_VM_CE_IDENTIFIER $GRAAL_VM_EE_IDENTIFIER $AZUL_PRIME_VM_IDENTIFIER; then
echo ""
echo "Benchmark result files successfully pre-processed."
else
echo ""
echo "ERROR: An error occurred while merging or splitting benchmark result files, unable to continue!"
return 1
fi
else if [ "$PROCESSING_LANGUAGE" = "Python" ]; then
if $PROCESSING_COMMAND $PROCESSING_SCRIPT_DIR/merge_benchmark.$PROCESSING_EXTENSION \
$JMH_OUTPUT_FOLDER $OPENJDK_HOTSPOT_VM_IDENTIFIER $GRAAL_VM_CE_IDENTIFIER $GRAAL_VM_EE_IDENTIFIER $AZUL_PRIME_VM_IDENTIFIER &&
$PROCESSING_COMMAND $PROCESSING_SCRIPT_DIR/split_benchmark.$PROCESSING_EXTENSION \
$JMH_OUTPUT_FOLDER $OPENJDK_HOTSPOT_VM_IDENTIFIER $GRAAL_VM_CE_IDENTIFIER $GRAAL_VM_EE_IDENTIFIER $AZUL_PRIME_VM_IDENTIFIER; then
echo ""
echo "Benchmark result files successfully pre-processed."
else
echo ""
echo "ERROR: An error occurred while merging or splitting benchmark result files, unable to continue!"
return 1
fi
else
echo ""
echo "ERROR: An error occurred while recognising processing language!"
return 1
fi
}
preprocess_benchmark_results() {
echo "Before plotting, it is recommended to pre-process (e.g., merge, split) some of the benchmark result files."
echo "For example:"
echo " - Some benchmarks contain inter-connected results spread across multiple files, each corresponding to specific JVM flags. Merging these results will lead to a single (instead of multiple) generated plot(s), improving overall readability."
echo " - Other benchmarks have results that differ significantly between iterations, making the plotting scale too large. Splitting these results into separate files will result in multiple (instead of a single) generated plots, each with an appropriate scale, improving the overall readability."
echo "WARNING: You can skip this step if pre-processing was already triggered in a previous execution."
echo ""
while true; do
read -p "Do you want to pre-process (e.g., merge, split) some of the benchmark result files? (yes/no) " INPUT_KEY
case $INPUT_KEY in
yes)
merge_split_benchmark_results
return $?
;;
no)
break
;;
*)
echo "Sorry, I don't understand. Try again!"
;;
esac
done
}
extract_benchmark_files() {
benchmark_type="$1"
no_of_benchmarks=$(./$JQ -r ".benchmarks | length" <"$JMH_BENCHMARKS")
benchmark_source_path="$(pwd)/benchmarks/src/main/java/com/ionutbalosin/jvm/performance/benchmarks/$benchmark_type"
benchmark_files=()
for ((counter = 0; counter < no_of_benchmarks; counter++)); do
bench_name=$(./$JQ --argjson counter "$counter" -r ".benchmarks[$counter].name" <"$JMH_BENCHMARKS")
if [[ -n $(find "$benchmark_source_path" -type f -name "$bench_name.java") ]]; then
benchmark_files+=("$bench_name.csv")
fi
done
echo "${benchmark_files[@]}"
}
benchmarks_geometric_mean() {
echo "Extracting benchmark categories (may take a few seconds) ..."
api_benchmark_files=($(extract_benchmark_files "api"))
echo "Identified ${#api_benchmark_files[@]} 'api' benchmarks (possibly including duplicates)."
compiler_benchmark_files=($(extract_benchmark_files "compiler"))
echo "Identified ${#compiler_benchmark_files[@]} 'compiler' benchmarks (possibly including duplicates)."
miscellaneous_benchmark_files=($(extract_benchmark_files "miscellaneous"))
echo "Identified ${#miscellaneous_benchmark_files[@]} 'miscellaneous' benchmarks (possibly including duplicates)."
if [ "$PROCESSING_LANGUAGE" = "R" ]; then
if $PROCESSING_COMMAND <$PROCESSING_SCRIPT_DIR/geomean-benchmark.$PROCESSING_EXTENSION --no-save \
--args "$JMH_OUTPUT_FOLDER" "$GEOMETRIC_MEAN_OUTPUT_FOLDER" \
"$OPENJDK_HOTSPOT_VM_IDENTIFIER" "$GRAAL_VM_CE_IDENTIFIER" "$GRAAL_VM_EE_IDENTIFIER" "$AZUL_PRIME_VM_IDENTIFIER" \
"$OPENJDK_HOTSPOT_VM_NAME" "$GRAAL_VM_CE_NAME" "$GRAAL_VM_EE_NAME" "$AZUL_PRIME_VM_NAME" \
"$OPENJDK_HOTSPOT_VM_JIT" "$GRAAL_VM_CE_JIT" "$GRAAL_VM_EE_JIT" "$AZUL_PRIME_VM_JIT" \
"${#api_benchmark_files[@]}" "${#compiler_benchmark_files[@]}" "${#miscellaneous_benchmark_files[@]}" \
"${api_benchmark_files[@]}" "${compiler_benchmark_files[@]}" "${miscellaneous_benchmark_files[@]}"; then
echo ""
echo "Benchmarks' normalized geometric mean successfully calculated."
else
echo ""
echo "ERROR: An error occurred while calculating the normalized geometric mean of benchmarks, unable to continue!"
return 1
fi
else if [ "$PROCESSING_LANGUAGE" = "Python" ]; then
if $PROCESSING_COMMAND $PROCESSING_SCRIPT_DIR/geomean_benchmark.$PROCESSING_EXTENSION \
"$JMH_OUTPUT_FOLDER" "$GEOMETRIC_MEAN_OUTPUT_FOLDER" \
"$OPENJDK_HOTSPOT_VM_IDENTIFIER" "$GRAAL_VM_CE_IDENTIFIER" "$GRAAL_VM_EE_IDENTIFIER" "$AZUL_PRIME_VM_IDENTIFIER" \
"$OPENJDK_HOTSPOT_VM_NAME" "$GRAAL_VM_CE_NAME" "$GRAAL_VM_EE_NAME" "$AZUL_PRIME_VM_NAME" \
"$OPENJDK_HOTSPOT_VM_JIT" "$GRAAL_VM_CE_JIT" "$GRAAL_VM_EE_JIT" "$AZUL_PRIME_VM_JIT" \
"${#api_benchmark_files[@]}" "${#compiler_benchmark_files[@]}" "${#miscellaneous_benchmark_files[@]}" \
"${api_benchmark_files[@]}" "${compiler_benchmark_files[@]}" "${miscellaneous_benchmark_files[@]}"; then
echo ""
echo "Benchmarks' normalized geometric mean successfully calculated."
else
echo ""
echo "ERROR: An error occurred while calculating the normalized geometric mean of benchmarks, unable to continue!"
return 1
fi
else
echo ""
echo "ERROR: An error occurred while recognising processing language!"
return 1
fi
}
calculate_benchmarks_geometric_mean() {
echo "This will calculate the normalized geometric mean (per category) for a specific set of benchmarks."
echo "For example:"
echo " - API benchmarks' normalized geometric mean"
echo " - Compiler benchmarks' normalized geometric mean"
echo " - Miscellaneous benchmarks' normalized geometric mean"
echo "WARNING: You might skip this step if the normalized geometric mean was already calculated during a previous execution."
echo ""
while :; do
read -p "Do you want to calculate the benchmarks' normalized geometric mean? (yes/no) " INPUT_KEY
case $INPUT_KEY in
yes)
benchmarks_geometric_mean
return $?
break
;;
no)
break
;;
*)
echo "Sorry, I don't understand. Try again!"
;;
esac
done
}
plot_benchmarks() {
if [ "$PROCESSING_LANGUAGE" = "R" ]; then
if $PROCESSING_COMMAND <$PROCESSING_SCRIPT_DIR/plot-benchmark.$PROCESSING_EXTENSION --no-save \
--args "$JDK_VERSION" "$BENCHMARKS_ARCH" \
"$JMH_OUTPUT_FOLDER" "$PLOT_OUTPUT_FOLDER" \
"$OPENJDK_HOTSPOT_VM_IDENTIFIER" "$GRAAL_VM_CE_IDENTIFIER" "$GRAAL_VM_EE_IDENTIFIER" "$AZUL_PRIME_VM_IDENTIFIER" \
"$OPENJDK_HOTSPOT_VM_NAME" "$GRAAL_VM_CE_NAME" "$GRAAL_VM_EE_NAME" "$AZUL_PRIME_VM_NAME" \
"$OPENJDK_HOTSPOT_VM_COLOR_PALETTE" "$GRAAL_VM_CE_COLOR_PALETTE" "$GRAAL_VM_EE_COLOR_PALETTE" "$AZUL_PRIME_VM_COLOR_PALETTE"; then
echo ""
echo "Benchmark plots successfully generated."
else
echo ""
echo "ERROR: An error occurred while plotting benchmark results, unable to continue!"
return 1
fi
else if [ "$PROCESSING_LANGUAGE" = "Python" ]; then
if $PROCESSING_COMMAND $PROCESSING_SCRIPT_DIR/plot_benchmark.$PROCESSING_EXTENSION \
"$JDK_VERSION" "$BENCHMARKS_ARCH" \
"$JMH_OUTPUT_FOLDER" "$PLOT_OUTPUT_FOLDER" \
"$OPENJDK_HOTSPOT_VM_IDENTIFIER" "$GRAAL_VM_CE_IDENTIFIER" "$GRAAL_VM_EE_IDENTIFIER" "$AZUL_PRIME_VM_IDENTIFIER" \
"$OPENJDK_HOTSPOT_VM_NAME" "$GRAAL_VM_CE_NAME" "$GRAAL_VM_EE_NAME" "$AZUL_PRIME_VM_NAME" \
"$OPENJDK_HOTSPOT_VM_COLOR_PALETTE" "$GRAAL_VM_CE_COLOR_PALETTE" "$GRAAL_VM_EE_COLOR_PALETTE" "$AZUL_PRIME_VM_COLOR_PALETTE"; then
echo ""
echo "Benchmark plots successfully generated."
else
echo ""
echo "ERROR: An error occurred while plotting benchmark results, unable to continue!"
return 1
fi
else
echo ""
echo "ERROR: An error occurred while recognising processing language!"
return 1
fi
}
plot_benchmark_results() {
echo "This will generate benchmark plots (i.e., SVG files) based on the benchmark result files."
echo "WARNING: You might skip this step if plotting of the benchmarks was already triggered during a previous execution."
echo ""
while true; do
read -p "Do you want to plot the benchmark results? (yes/no) " INPUT_KEY
case $INPUT_KEY in
yes)
plot_benchmarks
return $?
;;
no)
break
;;
*)
echo "Sorry, I don't understand. Try again!"
;;
esac
done
}
echo ""
echo "#############################################################################"
echo "####### JVM Performance Benchmarks Results Plot Generator #######"
echo "#############################################################################"
if ! check_command_line_options "$@"; then
exit 1
fi
echo ""
echo "+================================+"
echo "| [1/9] Configuration Properties |"
echo "+================================+"
if ! load_config_properties; then
exit 1
fi
echo ""
echo "+=============================+"
echo "| [2/9] Hardware Architecture |"
echo "+=============================+"
. ./scripts/shell/configure-arch.sh
echo ""
echo "+========================+"
echo "| [3/9] OS Configuration |"
echo "+========================+"
. ./scripts/shell/configure-os.sh || exit 1
echo ""
echo "+========================+"
echo "| [4/9] JQ Configuration |"
echo "+========================+"
. ./scripts/shell/configure-jq.sh || exit 1
echo ""
echo "+=============================+"
echo "| [5/9] Environment Variables |"
echo "+=============================+"
set_environment_variables "$@" || exit 1
echo ""
echo "+===========================+"
echo "| [6/9] Processing Language |"
echo "+===========================+"
select_processing_language
echo ""
read -r -p "If the above configuration is accurate, press ENTER to proceed or CTRL+C to abort ... "
echo ""
echo "+=====================================+"
echo "| [7/9] Pre-process Benchmark Results |"
echo "+=====================================+"
if ! preprocess_benchmark_results; then
exit 1
fi
echo ""
echo "+=======================================================+"
echo "| [8/9] Calculate Benchmarks' Normalized Geometric Mean |"
echo "+=======================================================+"
if ! calculate_benchmarks_geometric_mean; then
exit 1
fi
echo ""
echo "+======================+"
echo "| [9/9] Plot Benchmark |"
echo "+======================+"
plot_benchmarks