Skip to content

Support per-benchmark custom context in JSON output#2250

Closed
devtejasx wants to merge 1 commit into
google:mainfrom
devtejasx:per-benchmark-custom-context
Closed

Support per-benchmark custom context in JSON output#2250
devtejasx wants to merge 1 commit into
google:mainfrom
devtejasx:per-benchmark-custom-context

Conversation

@devtejasx

Copy link
Copy Markdown
Contributor

Add Benchmark::AddCustomContext(key, value) to attach string key-value pairs to a benchmark at registration time. The pairs are reported with every result of that benchmark (including aggregates) as a custom_context object in the JSON output, complementing the existing run-wide benchmark::AddCustomContext() which only goes into the top-level context. This allows tagging generated benchmark variants with structured metadata instead of encoding it into the benchmark name and parsing it back out of reports.

Fixes #1890

Add Benchmark::AddCustomContext(key, value) to attach string key-value
pairs to a benchmark at registration time. The pairs are reported with
every result of that benchmark (including aggregates) as a
custom_context object in the JSON output, complementing the existing
run-wide benchmark::AddCustomContext() which only goes into the
top-level context. This allows tagging generated benchmark variants
with structured metadata instead of encoding it into the benchmark
name and parsing it back out of reports.

Fixes google#1890
Comment thread include/benchmark/benchmark_api.h
@dmah42

dmah42 commented Jul 15, 2026

Copy link
Copy Markdown
Member

can you explain the use-case more clearly? the benchmark already supports plenty of ways to change the name, or add parameters... why do we need custom context?

@devtejasx

devtejasx commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Fair point for the metadata-tagging case I had in mind, a naming/ArgNames convention plus the existing run-wide context is enough, and it's not worth adding new API surface for. I'll close this. Thanks for taking a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Allow to add more information in the custom output for json

2 participants