Skip to content

Commit 3a4fb75

Browse files
committed
tools: add benchmark runner to test-shared
1 parent 33f982e commit 3a4fb75

File tree

2 files changed

+153
-3
lines changed

2 files changed

+153
-3
lines changed

.github/workflows/test-shared.yml

Lines changed: 152 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This action uses the following secrets:
22
# CACHIX_AUTH_TOKEN: Write access to nodejs.cachix.org – without it, the cache is read-only.
3-
name: Test Shared libraries
3+
name: Benchmark and shared libraries
44

55
on:
66
pull_request:
@@ -59,6 +59,30 @@ on:
5959
- test/internet/**
6060
- .github/**
6161
- '!.github/workflows/test-shared.yml'
62+
workflow_dispatch:
63+
inputs:
64+
repo:
65+
type: string
66+
description: GitHub repository to fetch from (default to the current repo)
67+
pr_id:
68+
type: number
69+
required: true
70+
description: The PR to test
71+
commit:
72+
required: true
73+
type: string
74+
description: The expect HEAD of the PR
75+
category:
76+
required: true
77+
type: string
78+
description: The category (or categories) of tests to run, for example buffers, cluster etc. Maps to a folders in node/benchmark
79+
filter:
80+
type: string
81+
description: A substring to restrict the benchmarks to run in a category. e.g. `net-c2c`
82+
runs:
83+
type: number
84+
default: 30
85+
description: How many times to repeat each benchmark
6286

6387
concurrency:
6488
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -127,6 +151,22 @@ jobs:
127151
tar xzf tarballs/*.tar.gz -C "$RUNNER_TEMP"
128152
echo "TAR_DIR=$RUNNER_TEMP/$(basename tarballs/*.tar.gz .tar.gz)" >> "$GITHUB_ENV"
129153
154+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
155+
if: ${{ github.event_name == 'workflow_dispatch' }}
156+
with:
157+
repository: ${{ inputs.repo || github.repository }}
158+
ref: refs/pull/${{ inputs.pr_id }}/merge
159+
persist-credentials: false
160+
fetch-depth: 2
161+
162+
- name: Validate PR head and roll back to base commit
163+
if: ${{ github.event_name == 'workflow_dispatch' }}
164+
run: |
165+
[ "$(git rev-parse HEAD^2)" = "$EXPECTED_SHA" ]
166+
git reset HEAD^ --hard
167+
env:
168+
EXPECTED_SHA: ${{ inputs.commit }}
169+
130170
- uses: cachix/install-nix-action@456688f15bc354bef6d396e4a35f4f89d40bf2b7 # v31.8.2
131171
with:
132172
extra_nix_config: sandbox = true
@@ -152,7 +192,7 @@ jobs:
152192
mkdir tools
153193
mv "$TAR_DIR"/tools/nix tools/.
154194
155-
- name: Build Node.js and run tests
195+
- name: Build Node.js ${{ github.event_name == 'workflow_dispatch' && 'on the base commit' || 'and run tests' }}
156196
run: |
157197
nix-shell \
158198
-I nixpkgs=./tools/nix/pkgs.nix \
@@ -164,5 +204,114 @@ jobs:
164204
--arg benchmarkTools '[]' \
165205
${{ endsWith(matrix.system, '-darwin') && '--arg extraConfigFlags ''["--without-inspector"]'' \' || '\' }}
166206
--run '
167-
make -C "$TAR_DIR" run-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
207+
make ${{ github.event_name == 'workflow_dispatch' && 'build' || '-C "$TAR_DIR" run' }}-ci -j4 V=1 TEST_CI_ARGS="-p actions --measure-flakiness 9 --skip-tests=$CI_SKIP_TESTS"
208+
'
209+
210+
- name: Re-build Node.js on the merge commit
211+
# ccache is disabled here to avoid polluting the cache. Local build outputs should make this build relatively quick anyway.
212+
if: ${{ github.event_name == 'workflow_dispatch' }}
213+
run: |
214+
mv out/Release/node base_node
215+
git reset FETCH_HEAD --hard
216+
nix-shell \
217+
-I nixpkgs=./tools/nix/pkgs.nix \
218+
--pure \
219+
--arg loadJSBuiltinsDynamically false \
220+
--arg ccache 'null' \
221+
--arg devTools '[]' \
222+
--arg benchmarkTools '[]' \
223+
--run '
224+
make -j4 V=1
168225
'
226+
227+
- name: Run benchmark
228+
if: ${{ github.event_name == 'workflow_dispatch' }}
229+
run: |
230+
nix-shell \
231+
-I nixpkgs=./tools/nix/pkgs.nix \
232+
--pure --keep FILTER --keep LC_ALL --keep LANG \
233+
--arg loadJSBuiltinsDynamically false \
234+
--arg ccache 'null' \
235+
--arg icu 'null' \
236+
--arg sharedLibDeps '{}' \
237+
--arg devTools '[]' \
238+
--run '
239+
set -o pipefail
240+
./base_node benchmark/compare.js \
241+
--filter "$FILTER" \
242+
--runs ${{ inputs.runs }} \
243+
--old ./base_node --new ./node \
244+
-- ${{ inputs.category }} \
245+
| tee /dev/stderr \
246+
> ${{ matrix.system }}.csv
247+
echo "Warning: do not take GHA benchmark results as face value, always confirm them"
248+
echo "using a dedicated machine, e.g. Jenkins CI."
249+
echo
250+
echo "Benchmark results:"
251+
echo
252+
echo '"'"'```'"'"'
253+
Rscript benchmark/compare.R < ${{ matrix.system }}.csv
254+
echo '"'"'```'"'"'
255+
echo
256+
echo "Warning: do not take GHA benchmark results as face value, always confirm them"
257+
echo "using a dedicated machine, e.g. Jenkins CI."
258+
' | tee /dev/stderr >> "$GITHUB_STEP_SUMMARY"
259+
env:
260+
FILTER: ${{ inputs.filter }}
261+
262+
- name: Upload raw benchmark results
263+
if: ${{ github.event_name == 'workflow_dispatch' }}
264+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
265+
with:
266+
name: csv-${{ matrix.system }}
267+
path: ${{ matrix.system }}.csv
268+
269+
aggregate-benchmark-results:
270+
needs: build
271+
name: Aggregate benchmark results
272+
if: ${{ github.event_name == 'workflow_dispatch' }}
273+
runs-on: ubuntu-latest
274+
steps:
275+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
276+
with:
277+
persist-credentials: false
278+
sparse-checkout: |
279+
benchmark/*.R
280+
tools/nix/*.nix
281+
*.nix
282+
sparse-checkout-cone-mode: false
283+
284+
- name: Download benchmark raw results
285+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
286+
with:
287+
pattern: csv-*
288+
merge-multiple: true
289+
path: raw-results
290+
291+
- uses: cachix/install-nix-action@7be5dee1421f63d07e71ce6e0a9f8a4b07c2a487 # v31.6.1
292+
with:
293+
extra_nix_config: sandbox = true
294+
295+
- name: Benchmark results
296+
run: |
297+
nix-shell \
298+
-I nixpkgs=./tools/nix/pkgs.nix \
299+
--pure --keep LC_ALL --keep LANG \
300+
--arg loadJSBuiltinsDynamically false \
301+
--arg ccache 'null' \
302+
--arg icu 'null' \
303+
--arg sharedLibDeps '{}' \
304+
--arg devTools '[]' \
305+
--run '
306+
echo "Warning: do not take GHA benchmark results as face value, always confirm them"
307+
echo "using a dedicated machine, e.g. Jenkins CI."
308+
echo
309+
echo "Benchmark results:"
310+
echo
311+
echo '"'"'```'"'"'
312+
awk "FNR==1 && NR!=1{next;}{print}" raw-results/*.csv | Rscript benchmark/compare.R
313+
echo '"'"'```'"'"'
314+
echo
315+
echo "Warning: do not take GHA benchmark results as face value, always confirm them"
316+
echo "using a dedicated machine, e.g. Jenkins CI."
317+
' | tee /dev/stderr >> "$GITHUB_STEP_SUMMARY"

tools/nix/benchmarkTools.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
pkgs.rPackages.plyr
88
pkgs.wrk
99
]
10+
++ pkgs.lib.optional pkgs.stdenv.buildPlatform.isLinux pkgs.glibcLocales

0 commit comments

Comments
 (0)