Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output library / schema versions in JSON context block #1742

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Extract version string into GetBenchmarkVersiom()
LebedevRI committed Jan 24, 2024

Verified

This commit was signed with the committer’s verified signature.
LebedevRI Roman Lebedev
commit a7a5822d658ccf5e1044af2d045dde51403bfd80
3 changes: 3 additions & 0 deletions include/benchmark/benchmark.h
Original file line number Diff line number Diff line change
@@ -302,6 +302,9 @@ class BenchmarkReporter;
// Default number of minimum benchmark running time in seconds.
const char kDefaultMinTimeStr[] = "0.5s";

// Returns the version of the library.
BENCHMARK_EXPORT std::string GetBenchmarkVersiom();

BENCHMARK_EXPORT void PrintDefaultHelp();

BENCHMARK_EXPORT void Initialize(int* argc, char** argv,
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ target_include_directories(benchmark PUBLIC
)

set_property(
SOURCE json_reporter.cc
SOURCE benchmark.cc
APPEND
PROPERTY COMPILE_DEFINITIONS
BENCHMARK_VERSION="${VERSION}"
8 changes: 8 additions & 0 deletions src/benchmark.cc
Original file line number Diff line number Diff line change
@@ -748,6 +748,14 @@ int InitializeStreams() {

} // end namespace internal

std::string GetBenchmarkVersiom() {
#if defined(BENCHMARK_VERSION)
return {BENCHMARK_VERSION};
#else
return "hello, bazel!";
#endif
}

void PrintDefaultHelp() {
fprintf(stdout,
"benchmark"
7 changes: 1 addition & 6 deletions src/json_reporter.cc
Original file line number Diff line number Diff line change
@@ -167,12 +167,7 @@ bool JSONReporter::ReportContext(const Context& context) {
}
out << "],\n";

#if defined(BENCHMARK_VERSION)
const char library_version[] = BENCHMARK_VERSION;
#else
const char library_version[] = "hello, bazel!";
#endif
out << indent << FormatKV("library_version", library_version);
out << indent << FormatKV("library_version", GetBenchmarkVersiom());
out << ",\n";

#if defined(NDEBUG)