diff --git a/README.md b/README.md
index e8c65f8d..478ac896 100644
--- a/README.md
+++ b/README.md
@@ -273,6 +273,8 @@ too (`-lkstat`).
[Result Comparison](#result-comparison)
+[Extra Context](#extra-context)
+
### Library
[Runtime and Reporting Considerations](#runtime-and-reporting-considerations)
@@ -442,6 +444,25 @@ BM_memcpy/32k 1834 ns 1837 ns 357143
It is possible to compare the benchmarking results.
See [Additional Tooling Documentation](docs/tools.md)
+
+
+### Extra Context
+
+Sometimes it's useful to add extra context to the content printed before the
+results. By default this section includes information about the CPU on which
+the benchmarks are running. If you do want to add more context, you can use
+the `benchmark_context` command line flag:
+
+```bash
+$ ./run_benchmarks --benchmark_context=pwd=`pwd`
+Run on (1 x 2300 MHz CPU)
+pwd: /home/user/benchmark/
+Benchmark Time CPU Iterations
+----------------------------------------------------
+BM_memcpy/32 11 ns 11 ns 79545455
+BM_memcpy/32k 2181 ns 2185 ns 324074
+```
+
### Runtime and Reporting Considerations
diff --git a/src/benchmark.cc b/src/benchmark.cc
index 1fea654c..930a7567 100644
--- a/src/benchmark.cc
+++ b/src/benchmark.cc
@@ -13,6 +13,7 @@
// limitations under the License.
#include "benchmark/benchmark.h"
+
#include "benchmark_api_internal.h"
#include "benchmark_runner.h"
#include "internal_macros.h"
@@ -104,6 +105,10 @@ DEFINE_string(benchmark_color, "auto");
// Valid values: 'true'/'yes'/1, 'false'/'no'/0. Defaults to false.
DEFINE_bool(benchmark_counters_tabular, false);
+// Extra context to include in the output formatted as comma-separated key-value
+// pairs.
+DEFINE_kvpairs(benchmark_context, {});
+
// The level of verbose logging to output
DEFINE_int32(v, 0);
@@ -446,6 +451,7 @@ void PrintUsageAndExit() {
" [--benchmark_out_format=]\n"
" [--benchmark_color={auto|true|false}]\n"
" [--benchmark_counters_tabular={true|false}]\n"
+ " [--benchmark_context==,...]\n"
" [--v=]\n");
exit(0);
}
@@ -476,9 +482,11 @@ void ParseCommandLineFlags(int* argc, char** argv) {
ParseStringFlag(argv[i], "color_print", &FLAGS_benchmark_color) ||
ParseBoolFlag(argv[i], "benchmark_counters_tabular",
&FLAGS_benchmark_counters_tabular) ||
- ParseInt32Flag(argv[i], "v", &FLAGS_v) ||
ParseStringFlag(argv[i], "benchmark_perf_counters",
- &FLAGS_benchmark_perf_counters)) {
+ &FLAGS_benchmark_perf_counters) ||
+ ParseKeyValueFlag(argv[i], "benchmark_context",
+ &FLAGS_benchmark_context) ||
+ ParseInt32Flag(argv[i], "v", &FLAGS_v)) {
for (int j = i; j != *argc - 1; ++j) argv[j] = argv[j + 1];
--(*argc);
diff --git a/src/commandlineflags.cc b/src/commandlineflags.cc
index 0648fe3a..5724aaa2 100644
--- a/src/commandlineflags.cc
+++ b/src/commandlineflags.cc
@@ -20,6 +20,10 @@
#include
#include
#include
+#include