benchmark  1.7.1
benchmark_runner.h
1 // Copyright 2015 Google Inc. All rights reserved.
2 //
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
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
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.
14 
15 #ifndef BENCHMARK_RUNNER_H_
16 #define BENCHMARK_RUNNER_H_
17 
18 #include <thread>
19 #include <vector>
20 
21 #include "benchmark_api_internal.h"
22 #include "internal_macros.h"
23 #include "perf_counters.h"
24 #include "thread_manager.h"
25 
26 namespace benchmark {
27 
28 BM_DECLARE_double(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);
34 
35 namespace internal {
36 
37 extern MemoryManager* memory_manager;
38 
39 struct RunResults {
40  std::vector<BenchmarkReporter::Run> non_aggregates;
41  std::vector<BenchmarkReporter::Run> aggregates_only;
42 
43  bool display_report_aggregates_only = false;
44  bool file_report_aggregates_only = false;
45 };
46 
48  public:
50  BenchmarkReporter::PerFamilyRunReports* reports_for_family);
51 
52  int GetNumRepeats() const { return repeats; }
53 
54  bool HasRepeatsRemaining() const {
55  return GetNumRepeats() != num_repetitions_done;
56  }
57 
58  void DoOneRepetition();
59 
60  RunResults&& GetResults();
61 
62  BenchmarkReporter::PerFamilyRunReports* GetReportsForFamily() const {
63  return reports_for_family;
64  }
65 
66  private:
67  RunResults run_results;
68 
70  BenchmarkReporter::PerFamilyRunReports* reports_for_family;
71 
72  const double min_time;
73  const double min_warmup_time;
74  bool warmup_done;
75  const int repeats;
76  const bool has_explicit_iteration_count;
77 
78  int num_repetitions_done = 0;
79 
80  std::vector<std::thread> pool;
81 
82  std::vector<MemoryManager::Result> memory_results;
83 
84  IterationCount iters; // preserved between repetitions!
85  // So only the first repetition has to find/calculate it,
86  // the other repetitions will just use that precomputed iteration count.
87 
88  PerfCountersMeasurement perf_counters_measurement;
89  PerfCountersMeasurement* const perf_counters_measurement_ptr;
90 
91  struct IterationResults {
93  IterationCount iters;
94  double seconds;
95  };
96  IterationResults DoNIterations();
97 
98  IterationCount PredictNumItersNeeded(const IterationResults& i) const;
99 
100  bool ShouldReportIterationResults(const IterationResults& i) const;
101 
102  double GetMinTimeToApply() const;
103 
104  void FinishWarmUp(const IterationCount& i);
105 
106  void RunWarmUp();
107 };
108 
109 } // namespace internal
110 
111 } // end namespace benchmark
112 
113 #endif // BENCHMARK_RUNNER_H_
Definition: benchmark_api_internal.h:18
Definition: benchmark_runner.h:47
Definition: perf_counters.h:134
Definition: benchmark_runner.h:39
Definition: thread_manager.h:39