diff --git a/include/benchmark/benchmark.h b/include/benchmark/benchmark.h index 1eeaef64..002331c4 100644 --- a/include/benchmark/benchmark.h +++ b/include/benchmark/benchmark.h @@ -1247,7 +1247,7 @@ class BenchmarkReporter { CPUInfo const& cpu_info; // The number of chars in the longest benchmark name. size_t name_field_width; - + static const char *executable_name; Context(); }; diff --git a/src/benchmark.cc b/src/benchmark.cc index ee9ec5bf..2bfd19a7 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -661,6 +661,7 @@ void PrintUsageAndExit() { void ParseCommandLineFlags(int* argc, char** argv) { using namespace benchmark; + BenchmarkReporter::Context::executable_name = argv[0]; for (int i = 1; i < *argc; ++i) { if (ParseBoolFlag(argv[i], "benchmark_list_tests", &FLAGS_benchmark_list_tests) || diff --git a/src/json_reporter.cc b/src/json_reporter.cc index b5ae302a..254ec3ee 100644 --- a/src/json_reporter.cc +++ b/src/json_reporter.cc @@ -77,6 +77,10 @@ bool JSONReporter::ReportContext(const Context& context) { std::string walltime_value = LocalDateTimeString(); out << indent << FormatKV("date", walltime_value) << ",\n"; + if (Context::executable_name) { + out << indent << FormatKV("executable", Context::executable_name) << ",\n"; + } + CPUInfo const& info = context.cpu_info; out << indent << FormatKV("num_cpus", static_cast(info.num_cpus)) << ",\n"; diff --git a/src/reporter.cc b/src/reporter.cc index 5d2fa05a..4b40aaec 100644 --- a/src/reporter.cc +++ b/src/reporter.cc @@ -37,6 +37,9 @@ void BenchmarkReporter::PrintBasicContext(std::ostream *out, Out << LocalDateTimeString() << "\n"; + if (context.executable_name) + Out << "Running " << context.executable_name << "\n"; + const CPUInfo &info = context.cpu_info; Out << "Run on (" << info.num_cpus << " X " << (info.cycles_per_second / 1000000.0) << " MHz CPU " @@ -64,6 +67,9 @@ void BenchmarkReporter::PrintBasicContext(std::ostream *out, #endif } +// No initializer because it's already initialized to NULL. +const char* BenchmarkReporter::Context::executable_name; + BenchmarkReporter::Context::Context() : cpu_info(CPUInfo::Get()) {} double BenchmarkReporter::Run::GetAdjustedRealTime() const { diff --git a/test/reporter_output_test.cc b/test/reporter_output_test.cc index 1620b313..23eb1baf 100644 --- a/test/reporter_output_test.cc +++ b/test/reporter_output_test.cc @@ -17,11 +17,13 @@ static int AddContextCases() { AddCases(TC_ConsoleErr, { {"%int[-/]%int[-/]%int %int:%int:%int$", MR_Default}, + {"Running .*/reporter_output_test(\\.exe)?$", MR_Next}, {"Run on \\(%int X %float MHz CPU s\\)", MR_Next}, }); AddCases(TC_JSONOut, {{"^\\{", MR_Default}, {"\"context\":", MR_Next}, {"\"date\": \"", MR_Next}, + {"\"executable\": \".*/reporter_output_test(\\.exe)?\",", MR_Next}, {"\"num_cpus\": %int,$", MR_Next}, {"\"mhz_per_cpu\": %float,$", MR_Next}, {"\"cpu_scaling_enabled\": ", MR_Next},