22void BenchmarkThreads::Launch(
int& current,
int total,
LauncherHandler& handler)
25 for (
int attempt = 1; attempt <=
_settings.attempts(); ++attempt)
33 _settings._params.emplace_back(-1, -1, -1);
36 for (
const auto& threads :
_settings.threads())
39 for (
const auto& param :
_settings.params())
42 ContextThreads context(threads, std::get<0>(param), std::get<1>(param), std::get<2>(param));
48 std::tuple<int64_t, int64_t, int> latency_params(
_settings.latency());
49 bool latency_auto =
_settings.latency_auto();
52 handler.onLaunching(++current, total, *
this, context, attempt);
59 int64_t operations =
_settings.operations();
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.
static void UpdateBenchmarkThreads(std::vector< std::shared_ptr< PhaseCore > > &phases)
Update benchmark threads metrics for the given benchmark phases collection.
bool _launched
Benchmark launched flag.
virtual int CountLaunches() const
Get the count of benchmark launches.
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 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.
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.