Eric | d038472 | 2016-09-05 15:48:40 -0600 | [diff] [blame] | 1 | #ifndef BENCHMARK_API_INTERNAL_H |
| 2 | #define BENCHMARK_API_INTERNAL_H |
| 3 | |
Eric | d038472 | 2016-09-05 15:48:40 -0600 | [diff] [blame] | 4 | #include <cmath> |
| 5 | #include <iosfwd> |
Dominic Hamon | 332f677 | 2016-10-07 11:35:03 -0700 | [diff] [blame] | 6 | #include <limits> |
Dominic Hamon | edc77a3 | 2018-09-28 12:28:43 +0100 | [diff] [blame] | 7 | #include <memory> |
Dominic Hamon | 332f677 | 2016-10-07 11:35:03 -0700 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
Eric | d038472 | 2016-09-05 15:48:40 -0600 | [diff] [blame] | 10 | |
Dominic Hamon | 3b508fa | 2021-05-10 17:12:09 +0100 | [diff] [blame] | 11 | #include "benchmark/benchmark.h" |
| 12 | #include "commandlineflags.h" |
| 13 | |
Eric | d038472 | 2016-09-05 15:48:40 -0600 | [diff] [blame] | 14 | namespace benchmark { |
| 15 | namespace internal { |
| 16 | |
| 17 | // Information kept per benchmark we may want to run |
Dominic Hamon | 3b508fa | 2021-05-10 17:12:09 +0100 | [diff] [blame] | 18 | class BenchmarkInstance { |
| 19 | public: |
Roman Lebedev | 4c2e32f | 2021-06-02 18:06:45 +0300 | [diff] [blame] | 20 | BenchmarkInstance(Benchmark* benchmark, int family_index, |
Roman Lebedev | 80a6261 | 2021-06-02 23:45:41 +0300 | [diff] [blame] | 21 | int per_family_instance_index, |
Roman Lebedev | 4c2e32f | 2021-06-02 18:06:45 +0300 | [diff] [blame] | 22 | const std::vector<int64_t>& args, int threads); |
Dominic Hamon | 3b508fa | 2021-05-10 17:12:09 +0100 | [diff] [blame] | 23 | |
| 24 | const BenchmarkName& name() const { return name_; } |
Roman Lebedev | 4c2e32f | 2021-06-02 18:06:45 +0300 | [diff] [blame] | 25 | int family_index() const { return family_index_; } |
Roman Lebedev | 80a6261 | 2021-06-02 23:45:41 +0300 | [diff] [blame] | 26 | int per_family_instance_index() const { return per_family_instance_index_; } |
Dominic Hamon | 3b508fa | 2021-05-10 17:12:09 +0100 | [diff] [blame] | 27 | AggregationReportMode aggregation_report_mode() const { |
| 28 | return aggregation_report_mode_; |
| 29 | } |
| 30 | TimeUnit time_unit() const { return time_unit_; } |
| 31 | bool measure_process_cpu_time() const { return measure_process_cpu_time_; } |
| 32 | bool use_real_time() const { return use_real_time_; } |
| 33 | bool use_manual_time() const { return use_manual_time_; } |
| 34 | BigO complexity() const { return complexity_; } |
Dominic Hamon | 1fcb5c2 | 2021-07-01 09:39:09 +0100 | [diff] [blame] | 35 | BigOFunc* complexity_lambda() const { return complexity_lambda_; } |
Dominic Hamon | 3b508fa | 2021-05-10 17:12:09 +0100 | [diff] [blame] | 36 | const std::vector<Statistics>& statistics() const { return statistics_; } |
| 37 | int repetitions() const { return repetitions_; } |
Dominic Hamon | e025dd5 | 2021-06-01 16:05:50 +0100 | [diff] [blame] | 38 | double min_time() const { return min_time_; } |
Matthdonau | 7eb8c0f | 2022-05-23 14:50:17 +0200 | [diff] [blame] | 39 | double min_warmup_time() const { return min_warmup_time_; } |
Dominic Hamon | 3b508fa | 2021-05-10 17:12:09 +0100 | [diff] [blame] | 40 | IterationCount iterations() const { return iterations_; } |
| 41 | int threads() const { return threads_; } |
Vy Nguyen | b5bb9f0 | 2021-11-17 11:51:55 -0500 | [diff] [blame] | 42 | void Setup() const; |
| 43 | void Teardown() const; |
Dominic Hamon | 3b508fa | 2021-05-10 17:12:09 +0100 | [diff] [blame] | 44 | |
Roman Lebedev | f92903c | 2019-05-13 12:33:11 +0300 | [diff] [blame] | 45 | State Run(IterationCount iters, int thread_id, internal::ThreadTimer* timer, |
Mircea Trofin | 376ebc2 | 2021-04-28 01:25:29 -0700 | [diff] [blame] | 46 | internal::ThreadManager* manager, |
xdje42 | ebb5e39 | 2024-08-01 00:42:41 -0700 | [diff] [blame^] | 47 | internal::PerfCountersMeasurement* perf_counters_measurement, |
| 48 | ProfilerManager* profiler_manager) const; |
Dominic Hamon | 3b508fa | 2021-05-10 17:12:09 +0100 | [diff] [blame] | 49 | |
| 50 | private: |
| 51 | BenchmarkName name_; |
| 52 | Benchmark& benchmark_; |
Roman Lebedev | 4c2e32f | 2021-06-02 18:06:45 +0300 | [diff] [blame] | 53 | const int family_index_; |
Roman Lebedev | 80a6261 | 2021-06-02 23:45:41 +0300 | [diff] [blame] | 54 | const int per_family_instance_index_; |
Dominic Hamon | 3b508fa | 2021-05-10 17:12:09 +0100 | [diff] [blame] | 55 | AggregationReportMode aggregation_report_mode_; |
| 56 | const std::vector<int64_t>& args_; |
| 57 | TimeUnit time_unit_; |
| 58 | bool measure_process_cpu_time_; |
| 59 | bool use_real_time_; |
| 60 | bool use_manual_time_; |
| 61 | BigO complexity_; |
| 62 | BigOFunc* complexity_lambda_; |
Dominic Hamon | e025dd5 | 2021-06-01 16:05:50 +0100 | [diff] [blame] | 63 | UserCounters counters_; |
| 64 | const std::vector<Statistics>& statistics_; |
Dominic Hamon | 3b508fa | 2021-05-10 17:12:09 +0100 | [diff] [blame] | 65 | int repetitions_; |
| 66 | double min_time_; |
Matthdonau | 7eb8c0f | 2022-05-23 14:50:17 +0200 | [diff] [blame] | 67 | double min_warmup_time_; |
Dominic Hamon | 3b508fa | 2021-05-10 17:12:09 +0100 | [diff] [blame] | 68 | IterationCount iterations_; |
Dominic Hamon | e025dd5 | 2021-06-01 16:05:50 +0100 | [diff] [blame] | 69 | int threads_; // Number of concurrent threads to us |
Vy Nguyen | b5bb9f0 | 2021-11-17 11:51:55 -0500 | [diff] [blame] | 70 | |
| 71 | typedef void (*callback_function)(const benchmark::State&); |
| 72 | callback_function setup_ = nullptr; |
| 73 | callback_function teardown_ = nullptr; |
Eric | d038472 | 2016-09-05 15:48:40 -0600 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | bool FindBenchmarksInternal(const std::string& re, |
Dominic Hamon | edc77a3 | 2018-09-28 12:28:43 +0100 | [diff] [blame] | 77 | std::vector<BenchmarkInstance>* benchmarks, |
Dominic Hamon | 332f677 | 2016-10-07 11:35:03 -0700 | [diff] [blame] | 78 | std::ostream* Err); |
Eric | d038472 | 2016-09-05 15:48:40 -0600 | [diff] [blame] | 79 | |
Joao Paulo Magalhaes | ec6f035 | 2017-05-03 00:05:15 +0100 | [diff] [blame] | 80 | bool IsZero(double n); |
| 81 | |
Sergiu Deitsch | 9e47d07 | 2022-02-14 11:48:53 +0100 | [diff] [blame] | 82 | BENCHMARK_EXPORT |
Joao Paulo Magalhaes | 17a012d | 2017-05-02 20:31:54 +0100 | [diff] [blame] | 83 | ConsoleReporter::OutputOptions GetOutputOptions(bool force_no_color = false); |
| 84 | |
Dominic Hamon | 332f677 | 2016-10-07 11:35:03 -0700 | [diff] [blame] | 85 | } // end namespace internal |
| 86 | } // end namespace benchmark |
Eric | d038472 | 2016-09-05 15:48:40 -0600 | [diff] [blame] | 87 | |
Dominic Hamon | 332f677 | 2016-10-07 11:35:03 -0700 | [diff] [blame] | 88 | #endif // BENCHMARK_API_INTERNAL_H |