[RISCV][GISel] Remove unnecessary Observer notifications from legalizeVAStart.
[llvm-project.git] / third-party / benchmark / src / benchmark_runner.h
blob752eefdc26fa099203bb1d5cfceba4966a7b9c7a
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.
15 #ifndef BENCHMARK_RUNNER_H_
16 #define BENCHMARK_RUNNER_H_
18 #include <thread>
19 #include <vector>
21 #include "benchmark_api_internal.h"
22 #include "internal_macros.h"
23 #include "perf_counters.h"
24 #include "thread_manager.h"
26 namespace benchmark {
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);
34 namespace internal {
36 extern MemoryManager* memory_manager;
38 struct RunResults {
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 {
47 public:
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;
65 private:
66 RunResults run_results;
68 const benchmark::internal::BenchmarkInstance& b;
69 BenchmarkReporter::PerFamilyRunReports* reports_for_family;
71 const double min_time;
72 const int repeats;
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;
90 IterationCount iters;
91 double seconds;
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_