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_string(benchmark_min_time
);
29 BM_DECLARE_double(benchmark_min_warmup_time
);
30 BM_DECLARE_int32(benchmark_repetitions
);
31 BM_DECLARE_bool(benchmark_report_aggregates_only
);
32 BM_DECLARE_bool(benchmark_display_aggregates_only
);
33 BM_DECLARE_string(benchmark_perf_counters
);
37 extern MemoryManager
* memory_manager
;
40 std::vector
<BenchmarkReporter::Run
> non_aggregates
;
41 std::vector
<BenchmarkReporter::Run
> aggregates_only
;
43 bool display_report_aggregates_only
= false;
44 bool file_report_aggregates_only
= false;
47 struct BENCHMARK_EXPORT BenchTimeType
{
48 enum { ITERS
, TIME
} tag
;
56 BenchTimeType
ParseBenchMinTime(const std::string
& value
);
58 class BenchmarkRunner
{
60 BenchmarkRunner(const benchmark::internal::BenchmarkInstance
& b_
,
61 benchmark::internal::PerfCountersMeasurement
* pmc_
,
62 BenchmarkReporter::PerFamilyRunReports
* reports_for_family
);
64 int GetNumRepeats() const { return repeats
; }
66 bool HasRepeatsRemaining() const {
67 return GetNumRepeats() != num_repetitions_done
;
70 void DoOneRepetition();
72 RunResults
&& GetResults();
74 BenchmarkReporter::PerFamilyRunReports
* GetReportsForFamily() const {
75 return reports_for_family
;
78 double GetMinTime() const { return min_time
; }
80 bool HasExplicitIters() const { return has_explicit_iteration_count
; }
82 IterationCount
GetIters() const { return iters
; }
85 RunResults run_results
;
87 const benchmark::internal::BenchmarkInstance
& b
;
88 BenchmarkReporter::PerFamilyRunReports
* reports_for_family
;
90 BenchTimeType parsed_benchtime_flag
;
91 const double min_time
;
92 const double min_warmup_time
;
95 const bool has_explicit_iteration_count
;
97 int num_repetitions_done
= 0;
99 std::vector
<std::thread
> pool
;
101 std::vector
<MemoryManager::Result
> memory_results
;
103 IterationCount iters
; // preserved between repetitions!
104 // So only the first repetition has to find/calculate it,
105 // the other repetitions will just use that precomputed iteration count.
107 PerfCountersMeasurement
* const perf_counters_measurement_ptr
= nullptr;
109 struct IterationResults
{
110 internal::ThreadManager::Result results
;
111 IterationCount iters
;
114 IterationResults
DoNIterations();
116 IterationCount
PredictNumItersNeeded(const IterationResults
& i
) const;
118 bool ShouldReportIterationResults(const IterationResults
& i
) const;
120 double GetMinTimeToApply() const;
122 void FinishWarmUp(const IterationCount
& i
);
127 } // namespace internal
129 } // end namespace benchmark
131 #endif // BENCHMARK_RUNNER_H_