17 int BenchmarkThreads::CountLaunches()
const
22 void BenchmarkThreads::Launch(
int& current,
int total, LauncherHandler& handler)
33 _settings._params.emplace_back(-1, -1, -1);
42 ContextThreads context(threads, std::get<0>(param), std::get<1>(param), std::get<2>(param));
52 handler.onLaunching(++current, total, *
this, context, attempt);
62 Barrier barrier(threads);
65 context._current->StartCollectingMetrics();
66 context._metrics->AddOperations(1);
69 for (
int i = 0; i < threads; ++i)
71 _threads.emplace_back([
this, &barrier, &context, latency_params, latency_auto, threads, infinite, operations, duration, i]()
74 ContextThreads thread_context(context);
77 std::shared_ptr<Phase> thread_phase = context.StartPhaseThreadSafe(
"thread-" + std::to_string(i));
78 PhaseCore* thread_phase_core =
dynamic_cast<PhaseCore*
>(thread_phase.get());
81 thread_context._current = thread_phase_core;
82 thread_context._metrics = &thread_phase_core->current();
83 thread_context._metrics->AddOperations(-1);
84 thread_context._metrics->SetThreads(threads);
87 thread_context._current->InitLatencyHistogram(latency_params);
92 bool thread_infinite = infinite;
93 int64_t thread_duration = duration;
94 int64_t thread_operations = operations;
96 uint64_t timestamp = 0;
102 if (thread_duration > 0)
105 uint64_t timespan = 0;
108 for (; timespan < 1000000000; ++count)
119 thread_operations = (1000000000ull * count * thread_duration) / timespan;
122 thread_context._current->StartCollectingMetrics();
123 while (!thread_context.canceled() && (thread_infinite || (thread_operations > 0)))
126 thread_context._metrics->AddOperations(1);
140 thread_operations -= 1;
142 thread_context._current->StopCollectingMetrics();
153 for (
auto& thread : _threads)
160 context._current->StopCollectingMetrics();
166 handler.onLaunched(current, total, *
this, context, attempt);
169 context._current->MergeMetrics();
170 context._current->ResetMetrics();
Barrier synchronization primitive definition.
Threads benchmark base definition.
bool _launched
Benchmark launched flag.
Settings _settings
Benchmark settings.
static void UpdateBenchmarkNames(std::vector< std::shared_ptr< PhaseCore >> &phases)
Update benchmark names for the given benchmark phases collection.
void InitBenchmarkContext(Context &context)
Initialize benchmark context.
static void UpdateBenchmarkThreads(std::vector< std::shared_ptr< PhaseCore >> &phases)
Update benchmark threads metrics for the given benchmark phases collection.
static void UpdateBenchmarkOperations(std::vector< std::shared_ptr< PhaseCore >> &phases)
Update benchmark operations 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.
std::vector< std::shared_ptr< PhaseCore > > _phases
Benchmark phases.
virtual void RunThread(ContextThreads &context)=0
Thread run method.
virtual void Cleanup(ContextThreads &context)
Cleanup benchmark.
virtual void Initialize(ContextThreads &context)
Initialize benchmark.
virtual void InitializeThread(ContextThreads &context)
Initialize thread.
virtual void CleanupThread(ContextThreads &context)
Cleanup thread.
const std::vector< std::tuple< int, int, int > > & params() const noexcept
Get collection of independent parameters in a benchmark plan.
int attempts() const noexcept
Get count of independent benchmark attempts.
int64_t duration() const noexcept
Get benchmark duration in milliseconds.
bool infinite() const noexcept
Is benchmark running with infinite count of operations (until cancel)?
const std::tuple< int64_t, int64_t, int > & latency() const noexcept
Get latency parameters.
int64_t operations() const noexcept
Get count of operations.
bool latency_auto() const noexcept
Get automatic latency update flag.
const std::vector< int > & threads() const noexcept
Get collection of independent threads counts in a benchmark plan.
static uint64_t Timestamp()
Get the current timestamp in nanoseconds.
static int CpuPhysicalCores()
CPU physical cores count.
Launcher handler definition.
C++ Benchmark project definitions.
System management definition.