Skip to content

Commit

Permalink
opt: suppress logs in benchmarks
Browse files Browse the repository at this point in the history
As of #57134 passing `-logtostderr=false` as a `TESTFLAG` in benchmarks
errs: `flag provided but not defined: -logtostderr`. The preferred
method for suppressing logs in tests and benchmarks to is add
`defer log.Scope(t).Close(t)` to the top of the test/benchmark
(see #57979).

This commit uses this new method to suppress logs in optimizer
benchmarks.

Release note: None
  • Loading branch information
mgartner committed Jan 13, 2021
1 parent d8d4b98 commit f6cc69b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions pkg/sql/opt/bench/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ go_test(
"//pkg/testutils/serverutils",
"//pkg/testutils/skip",
"//pkg/testutils/sqlutils",
"//pkg/util/log",
"//pkg/util/randutil",
"//pkg/util/timeutil",
],
Expand Down
4 changes: 3 additions & 1 deletion pkg/sql/opt/bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
"github.com/cockroachdb/cockroach/pkg/testutils/skip"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
)
Expand Down Expand Up @@ -278,7 +279,7 @@ var profileQuery = flag.String("profile-query", "kv-read", "name of query to run
func TestCPUProfile(t *testing.T) {
skip.IgnoreLint(t,
"Remove this when profiling. Use profile flags above to configure. Sample command line: \n"+
"GOMAXPROCS=1 go test -run TestCPUProfile --logtostderr NONE && go tool pprof bench.test cpu.out",
"GOMAXPROCS=1 go test -run TestCPUProfile && go tool pprof cpu.out",
)

h := newHarness()
Expand Down Expand Up @@ -319,6 +320,7 @@ func BenchmarkPhases(b *testing.B) {

// BenchmarkEndToEnd measures the time to execute a query end-to-end.
func BenchmarkEndToEnd(b *testing.B) {
defer log.Scope(b).Close(b)
h := newHarness()
defer h.close()

Expand Down
10 changes: 5 additions & 5 deletions pkg/sql/opt/bench/fk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/testutils/serverutils"
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils"
"github.com/cockroachdb/cockroach/pkg/util/log"
)

func runFKBench(
Expand Down Expand Up @@ -53,16 +54,15 @@ func runFKBench(
}

func BenchmarkFKInsert(b *testing.B) {
defer log.Scope(b).Close(b)
const parentRows = 1000
setup := func(b *testing.B, r *sqlutils.SQLRunner, setupFKs bool) {
r.Exec(b, "CREATE TABLE child (k int primary key, p int)")
r.Exec(b, "CREATE TABLE parent (p int primary key, data int)")

r.Exec(b, "CREATE TABLE parent (p INT PRIMARY KEY, data INT)")
if setupFKs {
r.Exec(b, "ALTER TABLE child ADD CONSTRAINT fk FOREIGN KEY (p) REFERENCES parent(p)")
r.Exec(b, "CREATE TABLE child (k INT PRIMARY KEY, p INT REFERENCES parent(p))")
} else {
// Create the index on p manually so it's a more fair comparison.
r.Exec(b, "CREATE INDEX idx ON child(p)")
r.Exec(b, "CREATE TABLE child (k INT PRIMARY KEY, p INT, INDEX (p))")
}

r.Exec(b, fmt.Sprintf(
Expand Down
1 change: 0 additions & 1 deletion pkg/util/log/test_log_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ func (l *TestLogScope) Close(t tShim) {
"bug in TestLogScope - previous config:\n%s\nafter restore:\n%s",
l.previous.appliedConfig, restoredConfig)
}
// t.Logf("restored configuration:\n%s", restoredConfig)
}

// calledDuringPanic returns true if panic() is one of its callers.
Expand Down

0 comments on commit f6cc69b

Please sign in to comment.