xref: /aosp_15_r20/external/google-benchmark/src/benchmark_api_internal.h (revision dbb99499c3810fa1611fa2242a2fc446be01a57c)
1 #ifndef BENCHMARK_API_INTERNAL_H
2 #define BENCHMARK_API_INTERNAL_H
3 
4 #include <cmath>
5 #include <iosfwd>
6 #include <limits>
7 #include <memory>
8 #include <string>
9 #include <vector>
10 
11 #include "benchmark/benchmark.h"
12 #include "commandlineflags.h"
13 
14 namespace benchmark {
15 namespace internal {
16 
17 // Information kept per benchmark we may want to run
18 class BenchmarkInstance {
19  public:
20   BenchmarkInstance(Benchmark* benchmark, int family_index,
21                     int per_family_instance_index,
22                     const std::vector<int64_t>& args, int threads);
23 
name()24   const BenchmarkName& name() const { return name_; }
family_index()25   int family_index() const { return family_index_; }
per_family_instance_index()26   int per_family_instance_index() const { return per_family_instance_index_; }
aggregation_report_mode()27   AggregationReportMode aggregation_report_mode() const {
28     return aggregation_report_mode_;
29   }
time_unit()30   TimeUnit time_unit() const { return time_unit_; }
measure_process_cpu_time()31   bool measure_process_cpu_time() const { return measure_process_cpu_time_; }
use_real_time()32   bool use_real_time() const { return use_real_time_; }
use_manual_time()33   bool use_manual_time() const { return use_manual_time_; }
complexity()34   BigO complexity() const { return complexity_; }
complexity_lambda()35   BigOFunc* complexity_lambda() const { return complexity_lambda_; }
statistics()36   const std::vector<Statistics>& statistics() const { return statistics_; }
repetitions()37   int repetitions() const { return repetitions_; }
min_time()38   double min_time() const { return min_time_; }
min_warmup_time()39   double min_warmup_time() const { return min_warmup_time_; }
iterations()40   IterationCount iterations() const { return iterations_; }
threads()41   int threads() const { return threads_; }
42   void Setup() const;
43   void Teardown() const;
44 
45   State Run(IterationCount iters, int thread_id, internal::ThreadTimer* timer,
46             internal::ThreadManager* manager,
47             internal::PerfCountersMeasurement* perf_counters_measurement,
48             ProfilerManager* profiler_manager) const;
49 
50  private:
51   BenchmarkName name_;
52   Benchmark& benchmark_;
53   const int family_index_;
54   const int per_family_instance_index_;
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_;
63   UserCounters counters_;
64   const std::vector<Statistics>& statistics_;
65   int repetitions_;
66   double min_time_;
67   double min_warmup_time_;
68   IterationCount iterations_;
69   int threads_;  // Number of concurrent threads to us
70 
71   typedef void (*callback_function)(const benchmark::State&);
72   callback_function setup_ = nullptr;
73   callback_function teardown_ = nullptr;
74 };
75 
76 bool FindBenchmarksInternal(const std::string& re,
77                             std::vector<BenchmarkInstance>* benchmarks,
78                             std::ostream* Err);
79 
80 bool IsZero(double n);
81 
82 BENCHMARK_EXPORT
83 ConsoleReporter::OutputOptions GetOutputOptions(bool force_no_color = false);
84 
85 }  // end namespace internal
86 }  // end namespace benchmark
87 
88 #endif  // BENCHMARK_API_INTERNAL_H
89