Skip to content

testing: Creating sub-benchmark with b.Run means that parent will not show anything from b.ReportMetric #66353

@HaraldNordgren

Description

@HaraldNordgren

Go version

go version go1.21.6 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/Harald/Library/Caches/go-build'
GOENV='/Users/Harald/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/Harald/go/pkg/mod'
GONOPROXY='github.com/dietdoctor/*'
GONOSUMDB='github.com/dietdoctor/*'
GOOS='darwin'
GOPATH='/Users/Harald/go'
GOPRIVATE='github.com/dietdoctor/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.21.6/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.21.6/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.6'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/Harald/dd/hive/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/j2/0w9hqz1x01g3j4_yz0w0sw780000gp/T/go-build4150210059=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

func BenchmarkTest(b *testing.B) {
	for _, name := range []string{"Test"} {
		b.Run(name, func(b *testing.B) {
			for _, subName := range []string{"Subtest"} {
				b.Run(subName, func(bb *testing.B) {
					bb.ReportMetric(100, "sub_test_metric")
				})
			}
			b.ReportMetric(200, "some_metric")
		})
	}
}

What did you see happen?

BenchmarkTest
BenchmarkTest/Test
BenchmarkTest/Test/Subtest
BenchmarkTest/Test/Subtest-8 	1000000000	         0.0000002 ns/op	       100.0 sub_test_metric
PASS

What did you expect to see?

I want to see some_metric be reported on the BenchmarkTest/Test benchmark.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions