CppBenchmark  1.0.4.0
C++ Benchmark Library
phase_scope.h
Go to the documentation of this file.
1 
9 #ifndef CPPBENCHMARK_PHASE_SCOPE_H
10 #define CPPBENCHMARK_PHASE_SCOPE_H
11 
12 #include "benchmark/phase.h"
13 
14 namespace CppBenchmark {
15 
17 
21 class PhaseScope : public Phase
22 {
23 public:
25 
28  explicit PhaseScope(const std::shared_ptr<Phase>& phase) noexcept : _phase(phase) {}
29  PhaseScope(const PhaseScope&) noexcept = default;
30  PhaseScope(PhaseScope&&) noexcept = default;
32  virtual ~PhaseScope();
33 
34  PhaseScope& operator=(const PhaseScope&) noexcept = default;
35  PhaseScope& operator=(PhaseScope&&) noexcept = default;
36 
38  explicit operator bool() const noexcept
39  { return _phase ? true : false; }
40 
41  // Implementation of Phase
42  const std::string& name() const noexcept override
43  { return _phase ? _phase->name() : EMPTY_NAME; }
44  const PhaseMetrics& metrics() const noexcept override
45  { return _phase ? _phase->metrics() : EMPTY_METRICS; }
46  std::shared_ptr<Phase> StartPhase(const std::string& phase) override;
47  std::shared_ptr<Phase> StartPhaseThreadSafe(const std::string& phase) override;
48  void StopPhase() override;
49  std::shared_ptr<PhaseScope> ScopePhase(const std::string& phase) override;
50  std::shared_ptr<PhaseScope> ScopePhaseThreadSafe(const std::string& phase) override;
51 
52 private:
53  std::shared_ptr<Phase> _phase;
54 
55  static const std::string EMPTY_NAME;
56  static const PhaseMetrics EMPTY_METRICS;
57 };
58 
59 } // namespace CppBenchmark
60 
61 #endif // CPPBENCHMARK_PHASE_SCOPE_H
Benchmark phase base class.
Definition: phase.h:26
Benchmark phase metrics.
Definition: phase_metrics.h:37
Benchmark phase scope.
Definition: phase_scope.h:22
PhaseScope(const std::shared_ptr< Phase > &phase) noexcept
Create benchmark phase scope and attach existing benchmark phase to it.
Definition: phase_scope.h:28
PhaseScope(const PhaseScope &) noexcept=default
const std::string & name() const noexcept override
Get phase name.
Definition: phase_scope.h:42
std::shared_ptr< PhaseScope > ScopePhaseThreadSafe(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.
Definition: phase_scope.cpp:49
std::shared_ptr< Phase > StartPhaseThreadSafe(const std::string &phase) override
Start a new sub-phase with a given name in a multi-thread environment.
Definition: phase_scope.cpp:30
std::shared_ptr< Phase > StartPhase(const std::string &phase) override
Start a new sub-phase with a given name in a single-thread environment.
Definition: phase_scope.cpp:25
void StopPhase() override
Stop measurement of the current phase.
Definition: phase_scope.cpp:35
const PhaseMetrics & metrics() const noexcept override
Get phase metrics.
Definition: phase_scope.h:44
PhaseScope(PhaseScope &&) noexcept=default
std::shared_ptr< PhaseScope > ScopePhase(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.
Definition: phase_scope.cpp:44
C++ Benchmark project definitions.
Definition: barrier.h:15
Benchmark phase base definition.