Skip to content

Commit 9ab7185

Browse files
authored
Merge PR #152452
release-25.3: build: add crdb_bench flag
2 parents eaffef3 + 0c23ce6 commit 9ab7185

File tree

10 files changed

+78
-10
lines changed

10 files changed

+78
-10
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ startup --host_jvm_args=-DBAZEL_TRACK_SOURCE_DIRECTORIES=1
2222
build --flag_alias=bazel_code_coverage=//build/toolchains:bazel_code_coverage_flag
2323
build --flag_alias=crdb_test=//build/toolchains:crdb_test_flag
2424
build --flag_alias=crdb_test_off=//build/toolchains:crdb_test_off_flag
25+
build --flag_alias=crdb_bench=//build/toolchains:crdb_bench_flag
2526
build --flag_alias=cross=//build/toolchains:cross_flag
2627
build --flag_alias=dev=//build/toolchains:dev_flag
2728
build --flag_alias=force_build_cdeps=//build/toolchains:force_build_cdeps_flag

build/teamcity/cockroach/nightlies/microbenchmark_build_support.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ function build_and_upload_binaries() {
2424
return
2525
fi
2626

27-
config_args="--config=crosslinux --crdb_test_off"
27+
# Check if crdb_bench flag is supported, since we could be building an older
28+
# version that does not support it.
29+
if grep -q "crdb_bench" .bazelrc; then
30+
config_args="--config=crosslinux --crdb_test_off --crdb_bench"
31+
else
32+
config_args="--config=crosslinux --crdb_test_off"
33+
fi
2834
bazel clean
2935
go_test_targets=$(bazel query kind\(go_test, //$BENCH_PACKAGE:all\))
3036
bazel build $config_args $go_test_targets

build/toolchains/BUILD.bazel

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,19 @@ config_setting(
299299
},
300300
)
301301

302+
bool_flag(
303+
name = "crdb_bench_flag",
304+
build_setting_default = False,
305+
visibility = ["//visibility:public"],
306+
)
307+
308+
config_setting(
309+
name = "crdb_bench",
310+
flag_values = {
311+
":crdb_bench_flag": "true",
312+
},
313+
)
314+
302315
bool_flag(
303316
name = "dev_flag",
304317
build_setting_default = False,

dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ fi
88
set -euo pipefail
99

1010
# Bump this counter to force rebuilding `dev` on all machines.
11-
DEV_VERSION=111
11+
DEV_VERSION=112
1212

1313
THIS_DIR=$(cd "$(dirname "$0")" && pwd)
1414
BINARY_DIR=$THIS_DIR/bin/dev-versions

pkg/cmd/dev/bench.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ func (d *dev) bench(cmd *cobra.Command, commandLine []string) error {
140140
if runSepProcessTenant {
141141
args = append(args, "--test_arg", "-run-sep-process-tenant")
142142
}
143-
args = append(args, "--crdb_test_off")
143+
// The `crdb_test` flag enables metamorphic variables and various "extra" debug
144+
// checking code paths that can interfere with performance testing, hence
145+
// it should disabled for benchmarks.
146+
args = append(args, "--crdb_test_off", "--crdb_bench")
144147
if testArgs != "" {
145148
goTestArgs, err := d.getGoTestArgs(ctx, testArgs)
146149
if err != nil {

pkg/cmd/dev/testdata/datadriven/bench

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@ exec
22
dev bench pkg/spanconfig/...
33
----
44
echo $HOME/.cache
5-
bazel test pkg/spanconfig/...:all --nocache_test_results --test_arg -test.run=- --test_arg -test.bench=. --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.benchmem --crdb_test_off --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output streamed
5+
bazel test pkg/spanconfig/...:all --nocache_test_results --test_arg -test.run=- --test_arg -test.bench=. --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.benchmem --crdb_test_off --crdb_bench --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output streamed
66

77
exec
88
dev bench pkg/sql/parser --filter=BenchmarkParse
99
----
1010
echo $HOME/.cache
11-
bazel test pkg/sql/parser:all --nocache_test_results --test_arg -test.run=- --test_arg -test.bench=BenchmarkParse --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.benchmem --crdb_test_off --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output streamed
11+
bazel test pkg/sql/parser:all --nocache_test_results --test_arg -test.run=- --test_arg -test.bench=BenchmarkParse --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.benchmem --crdb_test_off --crdb_bench --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output streamed
1212

1313
exec
1414
dev bench pkg/sql/parser --filter=BenchmarkParse --stream-output=false
1515
----
1616
echo $HOME/.cache
17-
bazel test pkg/sql/parser:all --nocache_test_results --test_arg -test.run=- --test_arg -test.bench=BenchmarkParse --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.benchmem --crdb_test_off --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output errors
17+
bazel test pkg/sql/parser:all --nocache_test_results --test_arg -test.run=- --test_arg -test.bench=BenchmarkParse --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.benchmem --crdb_test_off --crdb_bench --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output errors
1818

1919
exec
2020
dev bench pkg/bench -f=BenchmarkTracing/1node/scan/trace=off --count=2 --bench-time=10x --bench-mem=false
2121
----
2222
echo $HOME/.cache
23-
bazel test pkg/bench:all --nocache_test_results --test_arg -test.run=- --test_arg -test.bench=BenchmarkTracing/1node/scan/trace=off --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.count=2 --test_arg -test.benchtime=10x --crdb_test_off --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output streamed
23+
bazel test pkg/bench:all --nocache_test_results --test_arg -test.run=- --test_arg -test.bench=BenchmarkTracing/1node/scan/trace=off --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.count=2 --test_arg -test.benchtime=10x --crdb_test_off --crdb_bench --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output streamed
2424

2525
exec
2626
dev bench pkg/spanconfig/spanconfigkvsubscriber -f=BenchmarkSpanConfigDecoder --cpus=10 --ignore-cache=false -v --timeout=50s
2727
----
2828
echo $HOME/.cache
29-
bazel test --local_cpu_resources=10 --test_timeout=50 pkg/spanconfig/spanconfigkvsubscriber:all --test_arg -test.run=- --test_arg -test.bench=BenchmarkSpanConfigDecoder --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.v --test_arg -test.benchmem --crdb_test_off --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output streamed
29+
bazel test --local_cpu_resources=10 --test_timeout=50 pkg/spanconfig/spanconfigkvsubscriber:all --test_arg -test.run=- --test_arg -test.bench=BenchmarkSpanConfigDecoder --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.v --test_arg -test.benchmem --crdb_test_off --crdb_bench --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output streamed
3030

3131
exec
3232
dev bench pkg/bench -f='BenchmarkTracing/1node/scan/trace=off' --test-args '-test.memprofile=mem.out -test.cpuprofile=cpu.out'
3333
----
3434
bazel info workspace --color=no
3535
echo $HOME/.cache
36-
bazel test pkg/bench:all --nocache_test_results --test_arg -test.run=- --test_arg -test.bench=BenchmarkTracing/1node/scan/trace=off --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.benchmem --crdb_test_off --test_arg -test.outputdir=crdb-checkout --sandbox_writable_path=crdb-checkout --test_arg -test.memprofile=mem.out --test_arg -test.cpuprofile=cpu.out --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output streamed
36+
bazel test pkg/bench:all --nocache_test_results --test_arg -test.run=- --test_arg -test.bench=BenchmarkTracing/1node/scan/trace=off --test_sharding_strategy=disabled --test_arg -test.cpu --test_arg 1 --test_arg -test.benchmem --crdb_test_off --crdb_bench --test_arg -test.outputdir=crdb-checkout --sandbox_writable_path=crdb-checkout --test_arg -test.memprofile=mem.out --test_arg -test.cpuprofile=cpu.out --test_env COCKROACH_TEST_FIXTURES_DIR=crdb-mock-test-fixtures/crdb-test-fixtures --sandbox_writable_path=crdb-mock-test-fixtures/crdb-test-fixtures --test_output streamed

pkg/sql/exec_util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ var createTableWithSchemaLockedDefault = true
769769
// TestForceDisableCreateTableWithSchemaLocked disables schema_locked create table
770770
// in entire packages.
771771
func TestForceDisableCreateTableWithSchemaLocked() {
772-
if !buildutil.CrdbTestBuild {
772+
if !buildutil.CrdbTestBuild && !buildutil.CrdbBenchBuild {
773773
panic("Testing override for schema_locked used in non-test binary.")
774774
}
775775
createTableWithSchemaLockedDefault = false

pkg/util/buildutil/BUILD.bazel

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
22

3+
# gazelle:exclude gen-crdb_bench_off.go
4+
# gazelle:exclude gen-crdb_bench_on.go
35
# gazelle:exclude gen-crdb_test_off.go
46
# gazelle:exclude gen-crdb_test_on.go
57

@@ -9,13 +11,30 @@ go_library(
911
srcs = select({
1012
"//build/toolchains:crdb_test": [":gen-crdb-test-on"],
1113
"//conditions:default": [":gen-crdb-test-off"],
14+
}) + select({
15+
"//build/toolchains:crdb_bench": [":gen-crdb-bench-on"],
16+
"//conditions:default": [":gen-crdb-bench-off"],
1217
}),
1318
importpath = "github.com/cockroachdb/cockroach/pkg/util/buildutil",
1419
visibility = ["//visibility:public"],
1520
)
1621

1722
REMOVE_GO_BUILD_CONSTRAINTS = "cat $< | grep -v '//go:build' | grep -v '// +build' > $@"
1823

24+
genrule(
25+
name = "gen-crdb-bench-on",
26+
srcs = ["crdb_bench_on.go"],
27+
outs = ["gen-crdb_bench_on.go"],
28+
cmd = REMOVE_GO_BUILD_CONSTRAINTS,
29+
)
30+
31+
genrule(
32+
name = "gen-crdb-bench-off",
33+
srcs = ["crdb_bench_off.go"],
34+
outs = ["gen-crdb_bench_off.go"],
35+
cmd = REMOVE_GO_BUILD_CONSTRAINTS,
36+
)
37+
1938
genrule(
2039
name = "gen-crdb-test-on",
2140
srcs = ["crdb_test_on.go"],
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
//go:build !crdb_bench || crdb_bench_off
7+
8+
// Package buildutil provides a constant CrdbBenchBuild.
9+
package buildutil
10+
11+
// CrdbBenchBuild is a flag that is set to true if the binary was compiled
12+
// with the 'crdb_bench' build tag (which is the case for all benchmark targets).
13+
const CrdbBenchBuild = false
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2025 The Cockroach Authors.
2+
//
3+
// Use of this software is governed by the CockroachDB Software License
4+
// included in the /LICENSE file.
5+
6+
//go:build crdb_bench && !crdb_bench_off
7+
8+
// Package buildutil provides a constant CrdbBenchBuild.
9+
package buildutil
10+
11+
// CrdbBenchBuild is a flag that is set to true if the binary was compiled
12+
// with the 'crdb_bench' build tag (which is the case for all benchmark targets).
13+
const CrdbBenchBuild = true

0 commit comments

Comments
 (0)