diff --git a/bindings/python/google_benchmark/__init__.py b/bindings/python/google_benchmark/__init__.py index 44a54f516..227327131 100644 --- a/bindings/python/google_benchmark/__init__.py +++ b/bindings/python/google_benchmark/__init__.py @@ -142,4 +142,5 @@ def main(argv=None): # Methods for use with custom main function. initialize = _benchmark.Initialize run_benchmarks = _benchmark.RunSpecifiedBenchmarks +add_custom_context = _benchmark.AddCustomContext atexit.register(_benchmark.ClearRegisteredBenchmarks) diff --git a/bindings/python/google_benchmark/benchmark.cc b/bindings/python/google_benchmark/benchmark.cc index a93582253..f62ef0a4c 100644 --- a/bindings/python/google_benchmark/benchmark.cc +++ b/bindings/python/google_benchmark/benchmark.cc @@ -180,5 +180,9 @@ NB_MODULE(_benchmark, m) { m.def("RunSpecifiedBenchmarks", []() { benchmark::RunSpecifiedBenchmarks(); }); m.def("ClearRegisteredBenchmarks", benchmark::ClearRegisteredBenchmarks); + m.def("AddCustomContext", benchmark::AddCustomContext, nb::arg("key"), + nb::arg("value"), + "Add a key-value pair to output as part of the context stanza in the " + "report."); }; } // namespace diff --git a/bindings/python/google_benchmark/example.py b/bindings/python/google_benchmark/example.py index 5635c4184..49d6f8d0f 100644 --- a/bindings/python/google_benchmark/example.py +++ b/bindings/python/google_benchmark/example.py @@ -23,6 +23,7 @@ import random import time +import sys import google_benchmark as benchmark from google_benchmark import Counter @@ -137,4 +138,5 @@ def computing_complexity(state): if __name__ == "__main__": + benchmark.add_custom_context("python", sys.version) benchmark.main()