aboutsummaryrefslogtreecommitdiff
path: root/src/benchmark.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/benchmark.cc')
-rw-r--r--src/benchmark.cc37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/benchmark.cc b/src/benchmark.cc
index 6139e59..337bb3f 100644
--- a/src/benchmark.cc
+++ b/src/benchmark.cc
@@ -152,8 +152,16 @@ BENCHMARK_EXPORT std::map<std::string, std::string>*& GetGlobalContext() {
return global_context;
}
-// FIXME: wouldn't LTO mess this up?
-void UseCharPointer(char const volatile*) {}
+static void const volatile* volatile global_force_escape_pointer;
+
+// FIXME: Verify if LTO still messes this up?
+void UseCharPointer(char const volatile* const v) {
+ // We want to escape the pointer `v` so that the compiler can not eliminate
+ // computations that produced it. To do that, we escape the pointer by storing
+ // it into a volatile variable, since generally, volatile store, is not
+ // something the compiler is allowed to elide.
+ global_force_escape_pointer = reinterpret_cast<void const volatile*>(v);
+}
} // namespace internal
@@ -399,7 +407,8 @@ void RunBenchmarks(const std::vector<BenchmarkInstance>& benchmarks,
benchmarks_with_threads += (benchmark.threads() > 1);
runners.emplace_back(benchmark, &perfcounters, reports_for_family);
int num_repeats_of_this_instance = runners.back().GetNumRepeats();
- num_repetitions_total += num_repeats_of_this_instance;
+ num_repetitions_total +=
+ static_cast<size_t>(num_repeats_of_this_instance);
if (reports_for_family)
reports_for_family->num_runs_total += num_repeats_of_this_instance;
}
@@ -577,12 +586,16 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
Err << "A custom file reporter was provided but "
"--benchmark_out=<file> was not specified."
<< std::endl;
+ Out.flush();
+ Err.flush();
std::exit(1);
}
if (!fname.empty()) {
output_file.open(fname);
if (!output_file.is_open()) {
Err << "invalid file name: '" << fname << "'" << std::endl;
+ Out.flush();
+ Err.flush();
std::exit(1);
}
if (!file_reporter) {
@@ -597,10 +610,16 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
}
std::vector<internal::BenchmarkInstance> benchmarks;
- if (!FindBenchmarksInternal(spec, &benchmarks, &Err)) return 0;
+ if (!FindBenchmarksInternal(spec, &benchmarks, &Err)) {
+ Out.flush();
+ Err.flush();
+ return 0;
+ }
if (benchmarks.empty()) {
Err << "Failed to match any benchmarks against regex: " << spec << "\n";
+ Out.flush();
+ Err.flush();
return 0;
}
@@ -611,6 +630,8 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* display_reporter,
internal::RunBenchmarks(benchmarks, display_reporter, file_reporter);
}
+ Out.flush();
+ Err.flush();
return benchmarks.size();
}
@@ -736,6 +757,14 @@ int InitializeStreams() {
} // end namespace internal
+std::string GetBenchmarkVersion() {
+#ifdef BENCHMARK_VERSION
+ return {BENCHMARK_VERSION};
+#else
+ return {""};
+#endif
+}
+
void PrintDefaultHelp() {
fprintf(stdout,
"benchmark"