From 738175218ba2bc66ed4d4efeaa9ec3e829676511 Mon Sep 17 00:00:00 2001 From: Quentin Deslandes Date: Thu, 28 May 2026 12:32:41 +0200 Subject: [PATCH] tests: benchmarks: add hostname to benchmark metadata The hostname is now recorded as custom context in the JSON output alongside gitrev, gitdate, and other run metadata. This makes it possible to correlate results with the machine that produced them, which matters when benchmarks are run on different hosts. --- tests/benchmarks/benchmark.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/benchmarks/benchmark.cpp b/tests/benchmarks/benchmark.cpp index 427267c2..61feacc3 100644 --- a/tests/benchmarks/benchmark.cpp +++ b/tests/benchmarks/benchmark.cpp @@ -241,6 +241,18 @@ static std::string which(const std::string &cmd) return {}; } +std::string hostname() +{ + std::array buf {}; + if (gethostname(buf.data(), buf.size()) != 0) { + return {}; + } + + buf.back() = '\0'; + + return std::string(buf.data()); +} + int setup(std::span args) { const struct argp argp = {.options = options.data(), @@ -284,6 +296,7 @@ int setup(std::span args) if (pos != ::std::string::npos) config.outfile.replace(pos, pattern.size(), config.gitrev); + ::benchmark::AddCustomContext("hostname", hostname()); ::benchmark::AddCustomContext("gitrev", config.gitrev); ::benchmark::AddCustomContext("gitdate", ::std::to_string(config.gitdate)); ::benchmark::AddCustomContext("bfcli", config.bfcli);