You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be great if the user could add custom labels relevant to the performance of their code. For example:
CPU type/Microarchitecture/CPUID bits
Software version (perhaps git tag)
Presumably many others
I have noticed that the perf.golang.org service appears to support this, but I haven't looked into exactly how. Apologies if I've overlooked some existing feature.
An option to go test seems less useful to me. This feature is more important when it comes to labels that require code to derive (such as hardware parameters).
Proposal
My concrete proposal is an additional function in the testing package.
Perhaps something like:
// SetBenchmarkLabel records a value relevant to benchmark performance. This// will be included in benchmark output ahead of individual benchmark results.// Labels "goos", "goarch" and "pkg" are set by default.SetBenchmarkLabel(key, valuestring)
Not sure about naming, but hopefully this gives the idea.
"Case Study"
I recently implmented Meow hash for Golang. This hash is designed to take advantage of hardware AES instructions, therefore the implementation dispatches to one of three backends based on CPUID flags at runtime (pure Go, AES-NI and VAES-256/512).
To provide useful context in the test/benchmark output, I have two test functions that exist
purely to dump internal parameters:
In particular these "labels" are called "Configuration Lines".
Moreover, this document makes go bench output the official format for
representing benchmark results. While it is always possible to output this
kind of metadata in a separate program, that makes it harder to integrate with
automated tooling for running and storing benchmarks.
The existing implementation (and prototype CL) print the labels inside a sync.Once. Therefore any labels added or modified after the first print would be ignored. My expectation was that this would be used in init or other setup functions. This behavior seems reasonable to me but should be documented for clarity, perhaps:
// SetBenchmarkLabel records a value relevant to benchmark performance. This// will be included in benchmark output ahead of individual benchmark results.// Any SetBenchmarkLabel calls after the first benchmark is executed will be// ignored. Labels "goos", "goarch" and "pkg" are set by default.SetBenchmarkLabel(key, valuestring)
SetBenchmarkLabel should track what it has printed (a map[string]string) and silence duplicate prints but not throw away prints that change the value associated with a given key.
SetBenchmarkLabel should track what it has printed (a map[string]string) and silence duplicate prints but not throw away prints that change the value associated with a given key.
This seems easy enough, but I'd like to understand the use case you have in mind. Are you thinking about SetBenchmarkLabel calls from inside a benchmark function?
SetBenchmarkLabel should track what it has printed (a map[string]string) and silence duplicate prints but not throw away prints that change the value associated with a given key.
I'd like to understand what @rsc is proposing here a bit better, too.
It does seem a bit odd that SetBenchmarkLabel is only meaningful before the first benchmark run, but I also don't see how it's useful to call between benchmarks (or even when you would be able to do that). If a benchmark has multiple variations, I would expect it to use sub-benchmarks and the line-oriented "BenchmarkName/k=v/..." syntax.
SetBenchmarkLabel should specify that it constrains the syntax of the key and the value to legal configuration lines according to the benchmark format spec. (We did this in #26037 for the metric names.)
I was thinking that this would be something done inside a Benchmark function, but Austin points out that at that point the "BenchmarkName " prefix has been printed, making it inconvenient to print new key:value pairs. Also, the examples in the initial request are all global to the process, so maybe it makes sense to scope down to something global to the process that gets printed before any benchmarks start.
Then the only question is how do we know benchmarks are about to start. TestMain could print them unconditionally even today. If we give TestMain more access to the list of intended tests and benchmarks (see #28592) then it could avoid the print if no benchmarks will run. But maybe the lines in question would not be so bad to print always, so maybe we don't need to do anything special at all. For that matter, func init would work too.
As far as the case study, that could be done today with:
In my opinion there's value in making this a "first class citizen". Printing works but feels hacky.
Here's a hypothetical (but I believe not far fetched) reason why this could matter down the line. Google Benchmark offers --benchmark_out_format=<json|console|csv>. What if go test wanted to offer a similar feature. (The behavior of the -json option to go test is truly perplexing to me, but that's a topic for another time.) So if we wanted to have a go test -bench . -benchfmt json option the output might look like this:
I'm not arguing for this specific feature right now. My point is just that if people are printing labels, you've lost the semantics, and are unable to manipulate the labels in any structured way.
Finally, I think adding this as a function encourages people to use it, which I think is a positive too.
The JSON output is converted by a different program by parsing the actual benchmark output. Printing will not affect that. Let's let people do print statements for now and revisit once we can see more usage.
Activity
josharian commentedon Oct 26, 2018
Dup of #26037? I’d love to see that go in for 1.12 but I don’t think either @aclements or I have the bandwidth to push it through.
josharian commentedon Oct 26, 2018
Oh, reading closer, not a dup. Sorry. At least I’ve now cc’d Austin. :)
[-]testing: custom benchmark labels[/-][+]proposal: testing: custom benchmark labels[/+]mmcloughlin commentedon Oct 26, 2018
Seemed this should have the
proposal:prefix. Regarding bandwidth, I would be happy to put together a CL if the proposal is accepted.ianlancetaylor commentedon Oct 31, 2018
What exactly are you proposing? Adding an option to
go testwhich prints labels? It seems that you could print those yourself just as easily.mmcloughlin commentedon Oct 31, 2018
An option to
go testseems less useful to me. This feature is more important when it comes to labels that require code to derive (such as hardware parameters).Proposal
My concrete proposal is an additional function in the
testingpackage.Perhaps something like:
Not sure about naming, but hopefully this gives the idea.
"Case Study"
I recently implmented Meow hash for Golang. This hash is designed to take advantage of hardware AES instructions, therefore the implementation dispatches to one of three backends based on CPUID flags at runtime (pure Go, AES-NI and VAES-256/512).
To provide useful context in the test/benchmark output, I have two test functions that exist
purely to dump internal parameters:
https://github.com/mmcloughlin/meow/blob/7358a9c1d22772fbddc8c47fd74cf501c0136ec1/dispatch_amd64_test.go#L10-L17
https://github.com/mmcloughlin/meow/blob/7358a9c1d22772fbddc8c47fd74cf501c0136ec1/meow_test.go#L23-L25
I would prefer to include these as "official" labels:
Comparison: Google Benchmark
Note that Google benchmark also provides context with benchmark runs. For
example:
It would be great it was also possible to add CPU/cache information in Go
benchmark output.
Benchmark Format
Note that this output has been formalized in the following document:
https://github.com/golang/proposal/blob/master/design/14313-benchmark-format.md#configuration-lines
In particular these "labels" are called "Configuration Lines".
Moreover, this document makes
go benchoutput the official format forrepresenting benchmark results. While it is always possible to output this
kind of metadata in a separate program, that makes it harder to integrate with
automated tooling for running and storing benchmarks.
gopherbot commentedon Nov 2, 2018
Change https://golang.org/cl/146897 mentions this issue:
testing: add SetBenchmarkLabelmmcloughlin commentedon Nov 2, 2018
Added a CL to concretely demonstrate the proposal (and get something on the record before the freeze).
seebs commentedon Nov 14, 2018
I'd use it if it existed, which I like to think is an argument in favor.
rsc commentedon Nov 28, 2018
Does SetBenchmarkLabel keep track of what's already been printed and not repeat prints? In theory you can change the labels between runs.
mmcloughlin commentedon Nov 28, 2018
The existing implementation (and prototype CL) print the labels inside a
sync.Once. Therefore any labels added or modified after the first print would be ignored. My expectation was that this would be used ininitor other setup functions. This behavior seems reasonable to me but should be documented for clarity, perhaps:Did you have some other behavior in mind?
rsc commentedon Dec 12, 2018
SetBenchmarkLabel should track what it has printed (a map[string]string) and silence duplicate prints but not throw away prints that change the value associated with a given key.
Otherwise this seems OK to me. @aclements?
rsc commentedon Jan 23, 2019
Ping @aclements
mmcloughlin commentedon Jan 24, 2019
Yes it would be great to get @aclements input.
This seems easy enough, but I'd like to understand the use case you have in mind. Are you thinking about
SetBenchmarkLabelcalls from inside a benchmark function?ianlancetaylor commentedon Mar 20, 2019
Is this addressed by the recent fix for #26037?
CC @aclements
josharian commentedon Mar 20, 2019
Nope, this is not a dup of #26037. That was my initial reaction as well though. :) See the beginning of the thread.
This is about the labels that are printed prior to the benchmark lines, not the information that is included in the benchmark lines.
andybons commentedon Mar 27, 2019
Adding to the ping party for @aclements
aclements commentedon Mar 27, 2019
I'd like to understand what @rsc is proposing here a bit better, too.
It does seem a bit odd that
SetBenchmarkLabelis only meaningful before the first benchmark run, but I also don't see how it's useful to call between benchmarks (or even when you would be able to do that). If a benchmark has multiple variations, I would expect it to use sub-benchmarks and the line-oriented "BenchmarkName/k=v/..." syntax.SetBenchmarkLabelshould specify that it constrains the syntax of the key and the value to legal configuration lines according to the benchmark format spec. (We did this in #26037 for the metric names.)rsc commentedon May 28, 2019
I was thinking that this would be something done inside a Benchmark function, but Austin points out that at that point the "BenchmarkName " prefix has been printed, making it inconvenient to print new key:value pairs. Also, the examples in the initial request are all global to the process, so maybe it makes sense to scope down to something global to the process that gets printed before any benchmarks start.
Then the only question is how do we know benchmarks are about to start. TestMain could print them unconditionally even today. If we give TestMain more access to the list of intended tests and benchmarks (see #28592) then it could avoid the print if no benchmarks will run. But maybe the lines in question would not be so bad to print always, so maybe we don't need to do anything special at all. For that matter,
func initwould work too.As far as the case study, that could be done today with:
rsc commentedon Jun 4, 2019
Based on my comment from last week, I'm leaning toward declining this proposal. The answer to the original question is just "print statements".
mmcloughlin commentedon Jun 4, 2019
In my opinion there's value in making this a "first class citizen". Printing works but feels hacky.
Here's a hypothetical (but I believe not far fetched) reason why this could matter down the line. Google Benchmark offers
--benchmark_out_format=<json|console|csv>. What ifgo testwanted to offer a similar feature. (The behavior of the-jsonoption togo testis truly perplexing to me, but that's a topic for another time.) So if we wanted to have ago test -bench . -benchfmt jsonoption the output might look like this:Now my print statements give me:
I'm not arguing for this specific feature right now. My point is just that if people are printing labels, you've lost the semantics, and are unable to manipulate the labels in any structured way.
Finally, I think adding this as a function encourages people to use it, which I think is a positive too.
rsc commentedon Jun 25, 2019
The JSON output is converted by a different program by parsing the actual benchmark output. Printing will not affect that. Let's let people do print statements for now and revisit once we can see more usage.