1 // Copyright 2015 Google Inc. All rights reserved.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 #ifndef BENCHMARK_RUNNER_H_
16 #define BENCHMARK_RUNNER_H_
21 #include "benchmark_api_internal.h"
22 #include "internal_macros.h"
23 #include "perf_counters.h"
24 #include "thread_manager.h"
28 BM_DECLARE_double(benchmark_min_time
);
29 BM_DECLARE_int32(benchmark_repetitions
);
30 BM_DECLARE_bool(benchmark_report_aggregates_only
);
31 BM_DECLARE_bool(benchmark_display_aggregates_only
);
32 BM_DECLARE_string(benchmark_perf_counters
);
36 extern MemoryManager
* memory_manager
;
39 std::vector
<BenchmarkReporter::Run
> non_aggregates
;
40 std::vector
<BenchmarkReporter::Run
> aggregates_only
;
42 bool display_report_aggregates_only
= false;
43 bool file_report_aggregates_only
= false;
46 class BenchmarkRunner
{
48 BenchmarkRunner(const benchmark::internal::BenchmarkInstance
& b_
,
49 BenchmarkReporter::PerFamilyRunReports
* reports_for_family
);
51 int GetNumRepeats() const { return repeats
; }
53 bool HasRepeatsRemaining() const {
54 return GetNumRepeats() != num_repetitions_done
;
57 void DoOneRepetition();
59 RunResults
&& GetResults();
61 BenchmarkReporter::PerFamilyRunReports
* GetReportsForFamily() const {
62 return reports_for_family
;
66 RunResults run_results
;
68 const benchmark::internal::BenchmarkInstance
& b
;
69 BenchmarkReporter::PerFamilyRunReports
* reports_for_family
;
71 const double min_time
;
73 const bool has_explicit_iteration_count
;
75 int num_repetitions_done
= 0;
77 std::vector
<std::thread
> pool
;
79 std::vector
<MemoryManager::Result
> memory_results
;
81 IterationCount iters
; // preserved between repetitions!
82 // So only the first repetition has to find/calculate it,
83 // the other repetitions will just use that precomputed iteration count.
85 PerfCountersMeasurement perf_counters_measurement
;
86 PerfCountersMeasurement
* const perf_counters_measurement_ptr
;
88 struct IterationResults
{
89 internal::ThreadManager::Result results
;
93 IterationResults
DoNIterations();
95 IterationCount
PredictNumItersNeeded(const IterationResults
& i
) const;
97 bool ShouldReportIterationResults(const IterationResults
& i
) const;
100 } // namespace internal
102 } // end namespace benchmark
104 #endif // BENCHMARK_RUNNER_H_