CppBenchmark  1.0.4.0
C++ Benchmark Library
Public Member Functions | List of all members
CppBenchmark::PhaseScope Class Reference

Benchmark phase scope. More...

#include <phase_scope.h>

Inheritance diagram for CppBenchmark::PhaseScope:
CppBenchmark::Phase

Public Member Functions

 PhaseScope (const std::shared_ptr< Phase > &phase) noexcept
 Create benchmark phase scope and attach existing benchmark phase to it. More...
 
 PhaseScope (const PhaseScope &) noexcept=default
 
 PhaseScope (PhaseScope &&) noexcept=default
 
virtual ~PhaseScope ()
 Benchmark phase will be stopped on destructing. More...
 
PhaseScopeoperator= (const PhaseScope &) noexcept=default
 
PhaseScopeoperator= (PhaseScope &&) noexcept=default
 
 operator bool () const noexcept
 Is phase scope is valid? 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
 

Detailed Description

Benchmark phase scope.

Implements scope guard pattern for benchmark phase which stops attached benchmark phase on destructing instance. It also provides base Phase interface.

Definition at line 21 of file phase_scope.h.

Constructor & Destructor Documentation

◆ PhaseScope() [1/3]

CppBenchmark::PhaseScope::PhaseScope ( const std::shared_ptr< Phase > &  phase)
inlineexplicitnoexcept

Create benchmark phase scope and attach existing benchmark phase to it.

Parameters
phase- Attached benchmark phase

Definition at line 28 of file phase_scope.h.

◆ PhaseScope() [2/3]

CppBenchmark::PhaseScope::PhaseScope ( const PhaseScope )
defaultnoexcept

◆ PhaseScope() [3/3]

CppBenchmark::PhaseScope::PhaseScope ( PhaseScope &&  )
defaultnoexcept

◆ ~PhaseScope()

CppBenchmark::PhaseScope::~PhaseScope ( )
virtual

Benchmark phase will be stopped on destructing.

Definition at line 16 of file phase_scope.cpp.

Member Function Documentation

◆ metrics()

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

Get phase metrics.

Implements CppBenchmark::Phase.

Definition at line 44 of file phase_scope.h.

◆ name()

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

Get phase name.

Implements CppBenchmark::Phase.

Definition at line 42 of file phase_scope.h.

◆ operator bool()

CppBenchmark::PhaseScope::operator bool ( ) const
inlineexplicitnoexcept

Is phase scope is valid?

Definition at line 38 of file phase_scope.h.

◆ operator=() [1/2]

PhaseScope& CppBenchmark::PhaseScope::operator= ( const PhaseScope )
defaultnoexcept

◆ operator=() [2/2]

PhaseScope& CppBenchmark::PhaseScope::operator= ( PhaseScope &&  )
defaultnoexcept

◆ ScopePhase()

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

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 44 of file phase_scope.cpp.

◆ ScopePhaseThreadSafe()

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

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 49 of file phase_scope.cpp.

◆ StartPhase()

std::shared_ptr< Phase > CppBenchmark::PhaseScope::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 25 of file phase_scope.cpp.

◆ StartPhaseThreadSafe()

std::shared_ptr< Phase > CppBenchmark::PhaseScope::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 30 of file phase_scope.cpp.

◆ StopPhase()

void CppBenchmark::PhaseScope::StopPhase ( )
overridevirtual

Stop measurement of the current phase.

Implements CppBenchmark::Phase.

Definition at line 35 of file phase_scope.cpp.


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