Skip to content

Commit f17e8f1

Browse files
committed
add codspeed benchmark runner
do not build bench-tools on windows use local repository for google benchmark revert ci.bazelrc changes
1 parent 26777a8 commit f17e8f1

File tree

12 files changed

+134
-30
lines changed

12 files changed

+134
-30
lines changed

.github/workflows/codspeed.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CodSpeed
2+
3+
on:
4+
pull_request:
5+
paths-ignore:
6+
- 'docs/**'
7+
- 'justfile'
8+
- '.devcontainer'
9+
- '**/*.md'
10+
- '.gitignore'
11+
merge_group:
12+
push:
13+
branches:
14+
- main
15+
16+
concurrency:
17+
group: codspeed.yml-${{ github.event.pull_request.number || github.run_id }}
18+
cancel-in-progress: true
19+
20+
permissions:
21+
# Write cache
22+
contents: write
23+
24+
jobs:
25+
benchmarks:
26+
name: Run benchmarks
27+
runs-on: ubuntu-22.04
28+
env:
29+
BAZEL_ARGS: --config=benchmark --@codspeed//core:codspeed_mode=instrumentation --remote_cache=https://bazel:${{ secrets.BAZEL_CACHE_KEY }}@bazel-remote-cache.devprod.cloudflare.dev
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
show-progress: false
34+
35+
- name: Cache
36+
id: cache
37+
uses: actions/cache@v4
38+
with:
39+
path: ~/bazel-disk-cache
40+
key: bazel-disk-cache-benchmarks-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE') }}
41+
42+
- name: Setup Runner
43+
uses: ./.github/actions/setup-runner
44+
45+
- name: Build benchmarks
46+
run: |
47+
bazel build ${{ env.BAZEL_ARGS }} //src/workerd/tests:all_benchmarks
48+
49+
- name: Generate benchmark script
50+
run: |
51+
echo '#!/bin/bash' > run_benchmarks.sh
52+
echo 'set -e' >> run_benchmarks.sh
53+
targets=$(bazel query 'deps(//src/workerd/tests:all_benchmarks, 1)' --output=label 2>/dev/null | grep -E '^//src/workerd/tests:bench-' | grep -v '@')
54+
for target in $targets; do
55+
# Get the binary path for each benchmark target
56+
binary_path=$(bazel cquery ${{ env.BAZEL_ARGS }} --output=files "$target")
57+
echo "echo 'Running benchmark: $target'" >> run_benchmarks.sh
58+
echo "$binary_path" >> run_benchmarks.sh
59+
done
60+
chmod +x run_benchmarks.sh
61+
62+
- name: Run benchmarks
63+
uses: CodSpeedHQ/action@v3
64+
with:
65+
run: ./run_benchmarks.sh
66+
67+
- name: Bazel shutdown
68+
run: bazel shutdown

WORKSPACE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,24 @@ new_local_repository(
232232
path = "empty",
233233
)
234234

235+
# Tell workerd code where to find google-benchmark with CodSpeed.
236+
#
237+
# We indirect through `@workerd-google-benchmark` to allow dependents to override how and where
238+
# google-benchmark is built, similar to the v8 setup above.
239+
new_local_repository(
240+
name = "workerd-google-benchmark",
241+
build_file_content = """cc_library(
242+
name = "benchmark",
243+
deps = [ "@codspeed//google_benchmark:benchmark" ],
244+
visibility = ["//visibility:public"])
245+
246+
cc_library(
247+
name = "benchmark_main",
248+
deps = [ "@codspeed//google_benchmark:benchmark_main" ],
249+
visibility = ["//visibility:public"])""",
250+
path = "empty",
251+
)
252+
235253
# rust-based lolhtml dependency, including the API header.
236254
# Presented as a separate repository to allow overrides.
237255
new_local_repository(

build/ci.bazelrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ build:ci-test --config=v8-codegen-opt
4343
# LLVM produces a bit more debug info on macOS by default to facilitate debugging with
4444
# LLDB. This is not needed for this use case, so disable it using -fno-standalone-debug –
4545
# this is already the default for Linux/Windows.
46-
build:ci-limit-storage --build_tag_filters=-off-by-default,-benchmark
46+
build:ci-limit-storage --build_tag_filters=-off-by-default,-workerd-benchmark
4747
build:ci-limit-storage --copt="-g1"
4848
build:ci-limit-storage --copt="-fno-standalone-debug"
4949

build/deps/build_deps.jsonc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@
125125
// microbenchmark
126126
{
127127
"type": "github_release",
128-
"name": "com_google_benchmark",
129-
"owner": "google",
130-
"repo": "benchmark"
128+
"name": "codspeed",
129+
"owner": "CodSpeedHQ",
130+
"repo": "codspeed-cpp"
131131
}
132132
]
133133
}

build/deps/gen/build_deps.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ load("@//build/deps:gen/dep_cargo_bazel_win_x64.bzl", "dep_cargo_bazel_win_x64")
1111
load("@//build/deps:gen/dep_clang_format_darwin_arm64.bzl", "dep_clang_format_darwin_arm64")
1212
load("@//build/deps:gen/dep_clang_format_linux_amd64.bzl", "dep_clang_format_linux_amd64")
1313
load("@//build/deps:gen/dep_clang_format_linux_arm64.bzl", "dep_clang_format_linux_arm64")
14-
load("@//build/deps:gen/dep_com_google_benchmark.bzl", "dep_com_google_benchmark")
14+
load("@//build/deps:gen/dep_codspeed.bzl", "dep_codspeed")
1515
load("@//build/deps:gen/dep_rules_nodejs.bzl", "dep_rules_nodejs")
1616
load("@//build/deps:gen/dep_rules_python.bzl", "dep_rules_python")
1717
load("@//build/deps:gen/dep_rules_rust.bzl", "dep_rules_rust")
@@ -33,4 +33,4 @@ def deps_gen():
3333
dep_clang_format_linux_amd64()
3434
dep_clang_format_linux_arm64()
3535
dep_clang_format_darwin_arm64()
36-
dep_com_google_benchmark()
36+
dep_codspeed()

build/deps/gen/dep_codspeed.bzl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# WARNING: THIS FILE IS AUTOGENERATED BY update-deps.py DO NOT EDIT
2+
3+
load("@//:build/http.bzl", "http_archive")
4+
5+
TAG_NAME = "v1.2.0"
6+
URL = "https://api.github.com/repos/CodSpeedHQ/codspeed-cpp/tarball/v1.2.0"
7+
STRIP_PREFIX = "CodSpeedHQ-codspeed-cpp-719c41f"
8+
SHA256 = "1ced2c2e813313a574f41de9a218f38b53a4114cf7e72ee286801eaba6d8b240"
9+
TYPE = "tgz"
10+
11+
def dep_codspeed():
12+
http_archive(
13+
name = "codspeed",
14+
url = URL,
15+
strip_prefix = STRIP_PREFIX,
16+
type = TYPE,
17+
sha256 = SHA256,
18+
)

build/deps/gen/dep_com_google_benchmark.bzl

Lines changed: 0 additions & 18 deletions
This file was deleted.

build/wd_cc_benchmark.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def wd_cc_benchmark(
2525
}),
2626
visibility = visibility,
2727
deps = deps + [
28-
"@com_google_benchmark//:benchmark_main",
28+
"@workerd-google-benchmark//:benchmark_main",
2929
"//src/workerd/tests:bench-tools",
3030
],
3131
# use the same malloc we use for server
3232
malloc = "//src/workerd/server:malloc",
33-
tags = ["benchmark"],
33+
tags = ["workerd-benchmark"],
3434
**kwargs
3535
)
3636

@@ -40,5 +40,5 @@ def wd_cc_benchmark(
4040
outs = [name + ".benchmark.csv"],
4141
srcs = [name],
4242
cmd = "./$(location {}) --benchmark_format=csv > \"$@\"".format(name),
43-
tags = ["off-by-default", "benchmark_report"],
43+
tags = ["off-by-default", "benchmark_report", "workerd-benchmark"],
4444
)

compile_flags.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
-Iexternal/abseil-cpp/
1010
-Iexternal/simdutf/
1111
-Iexternal/nbytes/include/
12-
-Iexternal/com_google_benchmark/include/
12+
-Iexternal/codspeed/google_benchmark/include/
1313
-Iexternal/perfetto/include/
1414
-Iexternal/perfetto/include/perfetto/base/build_configs/bazel/
1515
-Iexternal/ssl/include

doxyfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ CLANG_OPTIONS = -std=c++20 \
12111211
-Wunused-lambda-capture \
12121212
-Wunused-variable \
12131213
-no-canonical-prefixes \
1214-
-Iexternal/com_google_benchmark/include/ \
1214+
-Iexternal/codspeed/google_benchmark/include/ \
12151215
-Iexternal/ada-url/ \
12161216
-Iexternal/simdutf/ \
12171217
-Iexternal/nbytes/ \

0 commit comments

Comments
 (0)