Repository navigation
430 lines (391 loc) · 20.2 KB
/
Copy pathelide-codspeed.yml
File metadata and controls
430 lines (391 loc) · 20.2 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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
name: CodSpeed benchmarks
# Steady-state wall time of the C API micro benchmarks, the pure Python meso benchmarks and
# benchmarks of real packages (pydantic, orjson, pandas, numpy, lxml) on a native standalone,
# reported to CodSpeed (https://app.codspeed.io/elide-dev/graalpython). Also some meso benchmarks
# without the JIT compiler (interp), the start-up of fresh processes (startup) and the peak RSS of
# fresh processes (memory), which CodSpeed shows as a time, 1 ms per MiB. The run's summary page has
# the peak RSS of every benchmark.
#
# Wall time needs a dedicated machine, so the measurement runs on the self-hosted benchmark runner
# linux-amd64-bench. The repository variable
# CODSPEED_WALLTIME_RUNNER selects another label; the standalone is built for linux-amd64, so it
# must be an x86_64 runner. The benchmark host is shared between repositories, so the standalone and
# the packages' wheels are built on the CI pool and the host is used only for the measurement.
#
# Pull requests are measured only when labelled "perf:bench", and never from a fork: both the build
# and the measurement run on self-hosted runners.
#
# A manual run with "diagnose" set reports nothing to CodSpeed: instead of the walltime job, the job
# diagnose runs the selected benchmarks once per interpreter option set of
# .github/elide/codspeed-diagnose.txt and keeps every iteration's duration, the GC log and the peak
# RSS as an artifact, for example
# gh workflow run elide-codspeed.yml --ref <branch> -f diagnose=true -f variants=gc-log,default
on:
push:
branches: [develop, 'elide-*.x']
pull_request:
types: [opened, synchronize, reopened, labeled]
workflow_dispatch:
inputs:
diagnose:
description: Run the diagnose job instead of the measurement; nothing is reported to CodSpeed
type: boolean
default: false
bench:
description: 'diagnose: regular expression matched against suite/name'
type: string
default: '^packages/(pydantic-json|orjson-roundtrip|pandas-csv|pandas-str|pandas-groupby-merge|lxml-xpath)$'
variants:
description: 'diagnose: comma-separated option sets of .github/elide/codspeed-diagnose.txt, or all'
type: string
default: all
iterations:
description: 'diagnose: iterations per benchmark and option set'
type: string
default: '30'
permissions:
contents: read
concurrency:
group: codspeed-${{ github.ref }}
# Every commit on a release branch is measured; a superseded pull request run is not.
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
# A release build. The standalone of the unittest workflow has assertions enabled and is built in
# quick mode (-Ob), so it cannot be measured.
build:
name: build native standalone
if: >-
github.event_name != 'pull_request' ||
(contains(github.event.pull_request.labels.*.name, 'perf:bench') &&
github.event.pull_request.head.repo.full_name == github.repository)
runs-on: ${{ vars.CODSPEED_BUILD_RUNNER || 'linux-amd64-cipool' }}
timeout-minutes: 120
steps:
# The self-hosted runners keep their workspace between jobs, and mx and the graal
# repository are cloned next to the checkout, so start from an empty workspace.
- name: Clean workspace
run: find "${GITHUB_WORKSPACE:?}" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
path: main
- name: Get mx and labsjdk
run: |
git config --global http.timeout 600
git clone https://github.com/graalvm/mx
./mx/mx fetch-jdk -A --configuration main/ci/graal/common.json --jdk-id labsjdk-ce-latest
git -C mx checkout "$(python3 -c 'import json; print(json.load(open("main/ci/graal/common.json"))["mx_version"])')"
echo "$(pwd)/mx/" >> "$GITHUB_PATH"
echo "JAVA_HOME=$HOME/.mx/jdks/labsjdk-ce-latest" >> "$GITHUB_ENV"
echo "JVMCI_VERSION_CHECK=ignore" >> "$GITHUB_ENV"
- name: Build
working-directory: main
# GITHUB_CI and BUILD_WITH_ASSERTIONS stay unset: they select the quick build mode and assertions.
run: |
mx sforceimports
mx sversions
mx python-svm
# A tar keeps the executable bits and symbolic links that artifacts drop.
- name: Pack the standalone
run: tar -C main/mxbuild/linux-amd64 -cf "$RUNNER_TEMP/graalpy-native-standalone.tar" GRAALPY_NATIVE_STANDALONE
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: codspeed-graalpy-native-standalone
path: ${{ runner.temp }}/graalpy-native-standalone.tar
retention-days: 1
if-no-files-found: error
# The packages of the suite "packages" (graalpython/com.oracle.graal.python.benchmarks/python/packages) have no wheels for this
# interpreter. Their compiled ones are built from source with the standalone just built, with
# GraalPy's patches, and every wheel is collected into one artifact that the benchmark host
# installs from without a network. Nothing is cached: the wheels depend on the interpreter build.
wheels:
name: build package wheels
needs: build
runs-on: ${{ vars.CODSPEED_BUILD_RUNNER || 'linux-amd64-cipool' }}
timeout-minutes: 90
env:
REQUIREMENTS: graalpython/com.oracle.graal.python.benchmarks/python/packages/requirements.txt
# pydantic-core and orjson are written in Rust; orjson needs at least 1.95.
RUST_VERSION: 1.100.0
steps:
- name: Clean workspace
run: find "${GITHUB_WORKSPACE:?}" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: codspeed-graalpy-native-standalone
path: ${{ runner.temp }}
# Everything the build installs or caches stays in the job's temporary directory.
- name: Install Rust
run: |
{
echo "CARGO_HOME=$RUNNER_TEMP/cargo"
echo "RUSTUP_HOME=$RUNNER_TEMP/rustup"
echo "XDG_CACHE_HOME=$RUNNER_TEMP/cache"
} >> "$GITHUB_ENV"
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs |
CARGO_HOME="$RUNNER_TEMP/cargo" RUSTUP_HOME="$RUNNER_TEMP/rustup" \
sh -s -- -y --no-modify-path --profile minimal --default-toolchain "$RUST_VERSION"
echo "$RUNNER_TEMP/cargo/bin" >> "$GITHUB_PATH"
- name: Build the wheels
env:
# Only PyPI. GraalPy's pip also looks for prebuilt wheels in GraalPy's own index otherwise.
PIP_INDEX_URL: https://pypi.org/simple
run: |
set -o pipefail
rustc --version
tar -C "$RUNNER_TEMP" -xf "$RUNNER_TEMP/graalpy-native-standalone.tar"
"$RUNNER_TEMP/GRAALPY_NATIVE_STANDALONE/bin/graalpy" -m venv "$RUNNER_TEMP/build-venv"
WHEELS="$RUNNER_TEMP/wheelhouse"
pin() { grep -E "^$1==" "$REQUIREMENTS"; }
# Builds every package even when one fails, so that one run shows all failures.
failed=""
build() {
local name=$1 start=$SECONDS status=0
shift
echo "::group::$name"
"$RUNNER_TEMP/build-venv/bin/pip" wheel --no-cache-dir --no-deps -w "$WHEELS" "$@" || status=$?
echo "::endgroup::"
echo "$name: exit status $status after $((SECONDS - start)) s"
if [ "$status" -ne 0 ]; then failed="$failed $name"; fi
}
# Without an external BLAS and LAPACK (numpy's own fallback routines), so that the benchmark
# host needs no libraries for it.
build numpy --no-binary numpy -Csetup-args=-Dblas=none -Csetup-args=-Dlapack=none "$(pin numpy)"
# Against that numpy, not one compiled again in pandas' build environment.
pin numpy > "$RUNNER_TEMP/numpy-constraint.txt"
build pandas --no-binary pandas --find-links "$WHEELS" \
--build-constraint "$RUNNER_TEMP/numpy-constraint.txt" "$(pin pandas)"
# libxml2 and libxslt linked in statically, so that the benchmark host needs no libraries for
# lxml. The versions and flags are the ones of lxml's own Linux wheels (without -flto); the
# libraries go into a shared object, so they need -fPIC. zlib.net serves only its latest
# release, so zlib comes from its release page; lxml checks the archive's hash.
export STATIC_DEPS=true ZLIB_VERSION=1.3.2 LIBICONV_VERSION=1.18 LIBXML2_VERSION=2.14.6 LIBXSLT_VERSION=1.1.43
export CFLAGS="-O3 -g1 -pipe -fPIC" LDFLAGS="-fPIC"
export DOWNLOAD_DIR="$RUNNER_TEMP/lxml-libs"
mkdir -p "$DOWNLOAD_DIR"
curl -sSfL -o "$DOWNLOAD_DIR/zlib-$ZLIB_VERSION.tar.gz" \
"https://github.com/madler/zlib/releases/download/v$ZLIB_VERSION/zlib-$ZLIB_VERSION.tar.gz"
build lxml --no-binary lxml "$(pin lxml)"
unset STATIC_DEPS ZLIB_VERSION LIBICONV_VERSION LIBXML2_VERSION LIBXSLT_VERSION DOWNLOAD_DIR CFLAGS LDFLAGS
build pydantic-core --no-binary pydantic-core "$(pin pydantic-core)"
build orjson --no-binary orjson "$(pin orjson)"
if [ -n "$failed" ]; then
ls -l "$WHEELS"
echo "::error::failed to build:$failed"
exit 1
fi
# The pure Python packages. Only these: PyPI also has prebuilt wheels of some of the compiled
# ones for GraalPy, which pip would prefer to the ones built here.
grep -v -E '^(numpy|pandas|lxml|pydantic-core|orjson)==' "$REQUIREMENTS" > "$RUNNER_TEMP/pure.txt"
"$RUNNER_TEMP/build-venv/bin/pip" wheel --no-cache-dir --no-deps --only-binary :all: -w "$WHEELS" \
-r "$RUNNER_TEMP/pure.txt"
ls -l "$WHEELS"
# One wheel per pinned package, so that the installation has no choice.
expected=$(grep -c -E '^[A-Za-z0-9_.-]+==' "$REQUIREMENTS")
found=$(find "$WHEELS" -name '*.whl' | wc -l)
if [ "$found" -ne "$expected" ]; then
echo "::error::$found wheels for $expected pinned packages"
exit 1
fi
# The pool and the benchmark host run the same system, but the host has only its base libraries.
- name: Check the libraries the wheels need
run: |
python3 - "$RUNNER_TEMP/wheelhouse" <<'EOF'
import os, re, subprocess, sys, tempfile, zipfile
system = {"libc.so.6", "libm.so.6", "libpthread.so.0", "libdl.so.2", "librt.so.1", "libutil.so.1",
"ld-linux-x86-64.so.2", "libstdc++.so.6", "libgcc_s.so.1"}
problems = []
for wheel in sorted(f for f in os.listdir(sys.argv[1]) if f.endswith(".whl")):
with zipfile.ZipFile(os.path.join(sys.argv[1], wheel)) as z, tempfile.TemporaryDirectory() as tmp:
libs = [n for n in z.namelist() if re.search(r"\.so(\.\d+)*$", n)]
shipped = {os.path.basename(n) for n in libs}
needed = set()
for name in libs:
out = subprocess.run(["readelf", "-d", z.extract(name, tmp)], capture_output=True, text=True,
check=True).stdout
for lib in re.findall(r"\(NEEDED\)\s+Shared library: \[([^\]]+)\]", out):
needed.add(lib)
if lib not in system and lib not in shipped:
problems.append("%s: %s needs %s" % (wheel, name, lib))
print("%s: %d libraries, need %s" % (wheel, len(libs), ", ".join(sorted(needed)) or "nothing"))
if problems:
sys.exit("\n".join(problems))
EOF
- uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: codspeed-package-wheels
path: ${{ runner.temp }}/wheelhouse/*.whl
retention-days: 1
if-no-files-found: error
# The C API benchmarks compile an extension when they start. Check that the standalone runs and
# that this works, and that the packages install and their benchmarks give the right results, before
# the benchmark host is occupied. No timing is taken from this job.
check:
name: check standalone
needs: [build, wheels]
runs-on: ${{ vars.CODSPEED_BUILD_RUNNER || 'linux-amd64-cipool' }}
timeout-minutes: 45
steps:
- name: Clean workspace
run: find "${GITHUB_WORKSPACE:?}" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: codspeed-graalpy-native-standalone
path: ${{ runner.temp }}
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: codspeed-package-wheels
path: ${{ runner.temp }}/wheelhouse
- name: Run three C API benchmarks
run: |
tar -C "$RUNNER_TEMP" -xf "$RUNNER_TEMP/graalpy-native-standalone.tar"
GRAALPY="$RUNNER_TEMP/GRAALPY_NATIVE_STANDALONE/bin/graalpy"
"$GRAALPY" -c 'import sys; print(sys.version)'
# The last two call C API functions that the public headers do not declare.
python3 .github/elide/codspeed-bench --python "$GRAALPY" \
--bench '^micro-native/(c-instantiate-large|c-to-c|c-call-method-obj-args)$'
# Four iterations each, so that an option the build does not know or a failing benchmark
# fails here and not on the benchmark host.
- name: Run the interpreter, start-up and memory benchmarks briefly
run: |
python3 .github/elide/codspeed-bench --python "$RUNNER_TEMP/GRAALPY_NATIVE_STANDALONE/bin/graalpy" \
--suite interp startup memory --max-iterations 4
# Four iterations each: every iteration checks its result.
- name: Run the package benchmarks briefly
run: |
.github/elide/package-venv "$RUNNER_TEMP/GRAALPY_NATIVE_STANDALONE/bin/graalpy" "$RUNNER_TEMP/venv" \
"$RUNNER_TEMP/wheelhouse"
python3 .github/elide/codspeed-bench --python "$RUNNER_TEMP/venv/bin/python" --suite packages \
--max-iterations 4
# So that an option this build does not know fails here and not on the benchmark host.
- name: Start the interpreter with each diagnose option set
if: ${{ inputs.diagnose }}
env:
VARIANTS: ${{ inputs.variants }}
BENCH: ${{ inputs.bench }}
run: |
python3 .github/elide/codspeed-diagnose --preflight --python "$RUNNER_TEMP/venv/bin/python" \
--variants "$VARIANTS" --bench "$BENCH" --output "$RUNNER_TEMP/diagnose"
walltime:
name: walltime
if: ${{ !inputs.diagnose }}
needs: [build, wheels, check]
runs-on: ${{ vars.CODSPEED_WALLTIME_RUNNER || 'linux-amd64-bench' }}
timeout-minutes: 120
permissions:
contents: read
id-token: write # CodSpeed OIDC
env:
BENCH_OUTPUT: ${{ github.workspace }}/codspeed-results
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: codspeed-graalpy-native-standalone
path: ${{ runner.temp }}
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: codspeed-package-wheels
path: ${{ runner.temp }}/wheelhouse
- name: Unpack the standalone
run: |
uname -a; cat /etc/os-release; nproc
tar -C "$RUNNER_TEMP" -xf "$RUNNER_TEMP/graalpy-native-standalone.tar"
cc --version
"$RUNNER_TEMP/GRAALPY_NATIVE_STANDALONE/bin/graalpy" -c 'import sys; print(sys.version)'
# From the wheels built on the pool only, without a network.
- name: Install the packages
run: |
.github/elide/package-venv "$RUNNER_TEMP/GRAALPY_NATIVE_STANDALONE/bin/graalpy" "$RUNNER_TEMP/venv" \
"$RUNNER_TEMP/wheelhouse"
- name: Measure
# Action and runner versions already in use on this host.
uses: CodSpeedHQ/action@b1f28b5eccf7cb5bfe6a2a89cb3053eb67f1150c # v5.8.0
env:
# The driver reports its own results and calls no CodSpeed instrumentation hooks, so the
# runner's sampling profiler has no benchmark to attach its samples to.
CODSPEED_PROFILER_ENABLED: 'false'
with:
mode: walltime
runner-version: "5.2.1"
run: >-
python3 .github/elide/codspeed-bench
--python "${{ runner.temp }}/GRAALPY_NATIVE_STANDALONE/bin/graalpy"
--suite-python packages="${{ runner.temp }}/venv/bin/python"
--suite micro-native meso packages interp startup memory
--output "${{ env.BENCH_OUTPUT }}"
--defer-failures
# CodSpeed only takes times: the peak RSS of every benchmark goes to the run's summary page.
- name: Peak RSS table
if: ${{ !cancelled() }}
run: |
if [ -f "$BENCH_OUTPUT/walltime-summary.md" ]; then
cat "$BENCH_OUTPUT/walltime-summary.md" >> "$GITHUB_STEP_SUMMARY"
fi
# A failed benchmark does not stop the others from being reported, but it fails the job.
- name: Fail on failed benchmarks
run: |
python3 - "$BENCH_OUTPUT/walltime-summary.json" <<'EOF'
import json, sys
failed = json.load(open(sys.argv[1]))["failed"]
if failed:
sys.exit("failed benchmarks: " + ", ".join(failed))
EOF
# Independent of the upload to CodSpeed.
- name: Keep the measurements
if: ${{ !cancelled() }}
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: codspeed-walltime-${{ github.run_attempt }}
path: |
${{ env.BENCH_OUTPUT }}/*.json
${{ env.BENCH_OUTPUT }}/*.md
retention-days: 14
if-no-files-found: warn
# Manual runs with "diagnose" set, see the top of the file. Same host and packages as walltime, no
# CodSpeed action and no token for it.
diagnose:
name: diagnose
if: ${{ inputs.diagnose }}
needs: [build, wheels, check]
runs-on: ${{ vars.CODSPEED_WALLTIME_RUNNER || 'linux-amd64-bench' }}
timeout-minutes: 100
env:
DIAGNOSE_OUTPUT: ${{ github.workspace }}/diagnose-results
steps:
- name: Clean workspace
run: find "${GITHUB_WORKSPACE:?}" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: codspeed-graalpy-native-standalone
path: ${{ runner.temp }}
- uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
with:
name: codspeed-package-wheels
path: ${{ runner.temp }}/wheelhouse
- name: Install the packages
run: |
uname -a; nproc; free -m
tar -C "$RUNNER_TEMP" -xf "$RUNNER_TEMP/graalpy-native-standalone.tar"
.github/elide/package-venv "$RUNNER_TEMP/GRAALPY_NATIVE_STANDALONE/bin/graalpy" "$RUNNER_TEMP/venv" \
"$RUNNER_TEMP/wheelhouse"
- name: Run the option sets
timeout-minutes: 90
env:
VARIANTS: ${{ inputs.variants }}
BENCH: ${{ inputs.bench }}
ITERATIONS: ${{ inputs.iterations }}
run: |
python3 .github/elide/codspeed-diagnose --python "$RUNNER_TEMP/venv/bin/python" \
--variants "$VARIANTS" --bench "$BENCH" --iterations "$ITERATIONS" --output "$DIAGNOSE_OUTPUT"
# Also after a timeout: the summary is written after every option set.
- name: Keep the results
if: ${{ !cancelled() }}
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: codspeed-diagnose-${{ github.run_attempt }}
path: ${{ env.DIAGNOSE_OUTPUT }}
retention-days: 14
if-no-files-found: warn