CppBenchmark  1.0.4.0
C++ Benchmark Library
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
CppBenchmark::PhaseCore Class Reference

Benchmark phase core. More...

#include <phase_core.h>

Inheritance diagram for CppBenchmark::PhaseCore:
CppBenchmark::Phase

Public Member Functions

 PhaseCore (const std::string &name)
 Create a new benchmark phase core with a given name. More...
 
 PhaseCore (const PhaseCore &)=delete
 
 PhaseCore (PhaseCore &&)=delete
 
virtual ~PhaseCore ()=default
 
PhaseCoreoperator= (const PhaseCore &)=delete
 
PhaseCoreoperator= (PhaseCore &&)=delete
 
PhaseMetricscurrent ()
 Current benchmark phase metrics. More...
 
const std::string & name () const noexcept override
 Get phase name. More...
 
const PhaseMetricsmetrics () const noexcept override
 Get phase metrics. More...
 
std::shared_ptr< PhaseStartPhase (const std::string &phase) override
 Start a new sub-phase with a given name in a single-thread environment. More...
 
std::shared_ptr< PhaseStartPhaseThreadSafe (const std::string &phase) override
 Start a new sub-phase with a given name in a multi-thread environment. More...
 
void StopPhase () override
 Stop measurement of the current phase. More...
 
std::shared_ptr< PhaseScopeScopePhase (const std::string &phase) override
 Start a new sub-phase with a given name in a single-thread environment and wrap it in a PhaseScope. More...
 
std::shared_ptr< PhaseScopeScopePhaseThreadSafe (const std::string &phase) override
 Start a new sub-phase with a given name in a multi-thread environment and wrap it in a PhaseScope. More...
 
- Public Member Functions inherited from CppBenchmark::Phase
 Phase () noexcept=default
 
 Phase (const Phase &)=default
 
 Phase (Phase &&) noexcept=default
 
virtual ~Phase ()=default
 
Phaseoperator= (const Phase &)=default
 
Phaseoperator= (Phase &&) noexcept=default
 

Protected Member Functions

void InitLatencyHistogram (const std::tuple< int64_t, int64_t, int > &latency) noexcept
 Initialize latency histogram for the current phase. More...
 
void PrintLatencyHistogram (FILE *file, int32_t resolution) const noexcept
 Print result latency histogram. More...
 
void StartCollectingMetrics () noexcept
 Start collecting metrics in the current phase. More...
 
void StopCollectingMetrics () noexcept
 Stop collecting metrics in the current phase. More...
 
void MergeMetrics ()
 Merge phase metrics (current to result) More...
 
void MergeMetrics (PhaseCore &phase)
 Merge metrics of the two phases. More...
 
void ResetMetrics () noexcept
 Reset current phase metrics. More...
 

Protected Attributes

std::mutex _mutex
 Synchronization mutex. More...
 
std::string _name
 Phase name. More...
 
uint64_t _thread
 Thread Id. More...
 
std::vector< std::shared_ptr< PhaseCore > > _child
 Child phases container. More...
 
PhaseMetrics _metrics_current
 Current phase metrics. More...
 
PhaseMetrics _metrics_result
 Result phase metrics. More...
 

Friends

class BenchmarkBase
 
class Benchmark
 
class BenchmarkPC
 
class BenchmarkThreads
 
class Executor
 
class Launcher
 

Detailed Description

Benchmark phase core.

Implementation of the Phase interface.

Definition at line 26 of file phase_core.h.

Constructor & Destructor Documentation

◆ PhaseCore() [1/3]

CppBenchmark::PhaseCore::PhaseCore ( const std::string &  name)
inlineexplicit

Create a new benchmark phase core with a given name.

Parameters
name- Benchmark phase name

Definition at line 40 of file phase_core.h.

◆ PhaseCore() [2/3]

CppBenchmark::PhaseCore::PhaseCore ( const PhaseCore )
delete

◆ PhaseCore() [3/3]

CppBenchmark::PhaseCore::PhaseCore ( PhaseCore &&  )
delete

◆ ~PhaseCore()

virtual CppBenchmark::PhaseCore::~PhaseCore ( )
virtualdefault

Member Function Documentation

◆ current()

PhaseMetrics& CppBenchmark::PhaseCore::current ( )
inline

Current benchmark phase metrics.

Definition at line 50 of file phase_core.h.

◆ InitLatencyHistogram()

void CppBenchmark::PhaseCore::InitLatencyHistogram ( const std::tuple< int64_t, int64_t, int > &  latency)
inlineprotectednoexcept

Initialize latency histogram for the current phase.

Parameters
latency- Latency histogram parameters

Definition at line 81 of file phase_core.h.

◆ MergeMetrics() [1/2]

void CppBenchmark::PhaseCore::MergeMetrics ( )
inlineprotected

Merge phase metrics (current to result)

Definition at line 99 of file phase_core.h.

◆ MergeMetrics() [2/2]

void CppBenchmark::PhaseCore::MergeMetrics ( PhaseCore phase)
inlineprotected

Merge metrics of the two phases.

Definition at line 102 of file phase_core.h.

◆ metrics()

const PhaseMetrics& CppBenchmark::PhaseCore::metrics ( ) const
inlineoverridevirtualnoexcept

Get phase metrics.

Implements CppBenchmark::Phase.

Definition at line 54 of file phase_core.h.

◆ name()

const std::string& CppBenchmark::PhaseCore::name ( ) const
inlineoverridevirtualnoexcept

Get phase name.

Implements CppBenchmark::Phase.

Definition at line 53 of file phase_core.h.

◆ operator=() [1/2]

PhaseCore& CppBenchmark::PhaseCore::operator= ( const PhaseCore )
delete

◆ operator=() [2/2]

PhaseCore& CppBenchmark::PhaseCore::operator= ( PhaseCore &&  )
delete

◆ PrintLatencyHistogram()

void CppBenchmark::PhaseCore::PrintLatencyHistogram ( FILE *  file,
int32_t  resolution 
) const
inlineprotectednoexcept

Print result latency histogram.

Parameters
file- File to print into
resolution- Histogram resolution

Definition at line 88 of file phase_core.h.

◆ ResetMetrics()

void CppBenchmark::PhaseCore::ResetMetrics ( )
inlineprotectednoexcept

Reset current phase metrics.

Definition at line 105 of file phase_core.h.

◆ ScopePhase()

std::shared_ptr<PhaseScope> CppBenchmark::PhaseCore::ScopePhase ( const std::string &  phase)
inlineoverridevirtual

Start a new sub-phase with a given name in a single-thread environment and wrap it in a PhaseScope.

Please note the method is not thread-safe and should not be called in multi-thread environment!

Parameters
phase- Sub-phase name
Returns
Shared pointer to the required benchmark sub-phase scope wrapper

Implements CppBenchmark::Phase.

Definition at line 58 of file phase_core.h.

◆ ScopePhaseThreadSafe()

std::shared_ptr<PhaseScope> CppBenchmark::PhaseCore::ScopePhaseThreadSafe ( const std::string &  phase)
inlineoverridevirtual

Start a new sub-phase with a given name in a multi-thread environment and wrap it in a PhaseScope.

Please note the method is thread-safe and might be called in multi-thread environment!

Parameters
phase- Sub-phase name
Returns
Shared pointer to the required thread-safe benchmark sub-phase scope wrapper

Implements CppBenchmark::Phase.

Definition at line 60 of file phase_core.h.

◆ StartCollectingMetrics()

void CppBenchmark::PhaseCore::StartCollectingMetrics ( )
inlineprotectednoexcept

Start collecting metrics in the current phase.

Definition at line 92 of file phase_core.h.

◆ StartPhase()

std::shared_ptr< Phase > CppBenchmark::PhaseCore::StartPhase ( const std::string &  phase)
overridevirtual

Start a new sub-phase with a given name in a single-thread environment.

This method will create or get existent sub-phase with a given name, start benchmark measurement and return it as a shared pointer. Please note the method is not thread-safe and should not be called in multi-thread environment!

Parameters
phase- Sub-phase name
Returns
Shared pointer to the required benchmark sub-phase

Implements CppBenchmark::Phase.

Definition at line 15 of file phase_core.cpp.

◆ StartPhaseThreadSafe()

std::shared_ptr< Phase > CppBenchmark::PhaseCore::StartPhaseThreadSafe ( const std::string &  phase)
overridevirtual

Start a new sub-phase with a given name in a multi-thread environment.

This method will create or get existent sub-phase with a given name, start benchmark measurement and return it as a shared pointer. Please note the method is thread-safe and might be called in multi-thread environment!

Parameters
phase- Sub-phase name
Returns
Shared pointer to the thread safe benchmark sub-phase

Implements CppBenchmark::Phase.

Definition at line 38 of file phase_core.cpp.

◆ StopCollectingMetrics()

void CppBenchmark::PhaseCore::StopCollectingMetrics ( )
inlineprotectednoexcept

Stop collecting metrics in the current phase.

Definition at line 95 of file phase_core.h.

◆ StopPhase()

void CppBenchmark::PhaseCore::StopPhase ( )
inlineoverridevirtual

Stop measurement of the current phase.

Implements CppBenchmark::Phase.

Definition at line 57 of file phase_core.h.

Friends And Related Function Documentation

◆ Benchmark

friend class Benchmark
friend

Definition at line 29 of file phase_core.h.

◆ BenchmarkBase

friend class BenchmarkBase
friend

Definition at line 28 of file phase_core.h.

◆ BenchmarkPC

friend class BenchmarkPC
friend

Definition at line 30 of file phase_core.h.

◆ BenchmarkThreads

friend class BenchmarkThreads
friend

Definition at line 31 of file phase_core.h.

◆ Executor

friend class Executor
friend

Definition at line 32 of file phase_core.h.

◆ Launcher

friend class Launcher
friend

Definition at line 33 of file phase_core.h.

Member Data Documentation

◆ _child

std::vector<std::shared_ptr<PhaseCore> > CppBenchmark::PhaseCore::_child
protected

Child phases container.

Definition at line 71 of file phase_core.h.

◆ _metrics_current

PhaseMetrics CppBenchmark::PhaseCore::_metrics_current
protected

Current phase metrics.

Definition at line 73 of file phase_core.h.

◆ _metrics_result

PhaseMetrics CppBenchmark::PhaseCore::_metrics_result
protected

Result phase metrics.

Definition at line 75 of file phase_core.h.

◆ _mutex

std::mutex CppBenchmark::PhaseCore::_mutex
protected

Synchronization mutex.

Definition at line 65 of file phase_core.h.

◆ _name

std::string CppBenchmark::PhaseCore::_name
protected

Phase name.

Definition at line 67 of file phase_core.h.

◆ _thread

uint64_t CppBenchmark::PhaseCore::_thread
protected

Thread Id.

Definition at line 69 of file phase_core.h.


The documentation for this class was generated from the following files: