22 class DynamicBenchmark :
public BenchmarkBase
26 typedef Settings TSettings;
33 explicit DynamicBenchmark(
const std::string& name,
const TSettings& settings = TSettings())
34 : BenchmarkBase(name, settings)
36 DynamicBenchmark(
const DynamicBenchmark&) =
delete;
37 DynamicBenchmark(DynamicBenchmark&&) =
delete;
38 virtual ~DynamicBenchmark() =
default;
40 DynamicBenchmark& operator=(
const DynamicBenchmark&) =
delete;
41 DynamicBenchmark& operator=(DynamicBenchmark&&) =
delete;
51 std::shared_ptr<PhaseCore> result;
55 std::scoped_lock lock(instance.
_mutex);
58 auto it = std::find_if(instance.
_benchmarks.begin(), instance.
_benchmarks.end(), [&benchmark](
const std::shared_ptr<PhaseCore>& item)
60 return ((item->name() == benchmark) && (item->_thread == System::CurrentThreadId()));
64 result = std::make_shared<PhaseCore>(benchmark);
72 result->StartCollectingMetrics();
75 result->_metrics_current.AddOperations(1);
86 std::scoped_lock lock(instance.
_mutex);
89 auto it = std::find_if(instance.
_benchmarks.begin(), instance.
_benchmarks.end(), [&benchmark](
const std::shared_ptr<PhaseCore>& item)
91 return ((item->name() == benchmark) && (item->_thread == System::CurrentThreadId()));
94 (*it)->StopCollectingMetrics();
102 std::scoped_lock lock(instance.
_mutex);
117 Internals::DynamicBenchmark result(benchmark->name(),
Settings().Attempts(1));
123 instance.ReportPhase(reporter, *benchmark, benchmark->name());
133 void Executor::ReportPhase(
Reporter& reporter,
const PhaseCore& phase,
const std::string& name)
const
138 for (
const auto& child : phase.
_child)
140 std::string child_name = name +
"." + child->name();
141 ReportPhase(reporter, *child, child_name);
static void UpdateBenchmarkThreads(std::vector< std::shared_ptr< PhaseCore >> &phases)
Update benchmark threads metrics for the given benchmark phases collection.
static void UpdateBenchmarkMetrics(std::vector< std::shared_ptr< PhaseCore >> &phases)
Update benchmark metrics for the given benchmark phases collection.
Dynamic benchmarks executor class.
std::mutex _mutex
Synchronization mutex.
static void StopBenchmark(const std::string &benchmark)
Stop dynamic benchmark with a given name.
static std::shared_ptr< Phase > StartBenchmark(const std::string &benchmark)
Start a new dynamic benchmark with a given name.
static void Report(Reporter &reporter)
Report benchmarks results using the given reporter.
std::vector< std::shared_ptr< PhaseCore > > _benchmarks
Registered benchmarks collection.
const PhaseMetrics & metrics() const noexcept override
Get phase metrics.
std::vector< std::shared_ptr< PhaseCore > > _child
Child phases container.
virtual void ReportBenchmarksFooter()
Report all benchmarks footer.
virtual void ReportPhase(const PhaseCore &phase, const PhaseMetrics &metrics)=0
Report current phase information.
virtual void ReportPhaseHeader()
Report current phase header.
virtual void ReportBenchmarkHeader()
Report current benchmark header.
virtual void ReportEnvironment()
Report environment information.
virtual void ReportHeader()
Report header.
virtual void ReportFooter()
Report footer.
virtual void ReportPhasesFooter()
Report all phases footer.
virtual void ReportBenchmarkFooter()
Report current benchmark footer.
virtual void ReportBenchmark(const BenchmarkBase &benchmark, const Settings &settings)
Report current benchmark information.
virtual void ReportBenchmarksHeader()
Report all benchmarks header.
virtual void ReportPhaseFooter()
Report current phase footer.
virtual void ReportPhasesHeader()
Report all phases header.
virtual void ReportSystem()
Report system information.
Dynamic benchmarks executor definition.
C++ Benchmark project definitions.