KASKADE 7 development version
Loading...
Searching...
No Matches
Kaskade::ScopedTimingSection Class Reference

A scope guard object that automatically closes a timing section on destruction. More...

#include <timing.hh>

Public Member Functions

 ScopedTimingSection ()
 Default constructor creating a not-running unnamed section.
 ScopedTimingSection (ScopedTimingSection const &)=delete
 ScopedTimingSection (Timings_Details::SectionBeacon const &sec)
 Move constructor.
 ScopedTimingSection (std::string const &name, bool gather=true)
 Constructor using the default timer provided by Timings::instance().
 ScopedTimingSection (std::string const &name, Timings &timer, bool gather=true)
 Constructor using provided timer.
 ~ScopedTimingSection ()
 Stops the section if it is still running.
void restart (std::string const &name)
 Start new section.
ScopedTimingSection & operator= (Timings_Details::SectionBeacon const &sec)
 Assignment from a beacon.
void start ()
 Ensures the section is timed.
void stop ()
 Ensures the section is not timed.
bool isRunning () const
 Reports whether the section is currently timed.
Timings & timer ()
 Returns the used timer.

Detailed Description

A scope guard object that automatically closes a timing section on destruction.

This closes timing sections in case an exception is thrown.

Example:

{
ScopedTimingSection tsec("my expensive calculation");
f(); // f may throw an exception, timing will be stopped
}
ScopedTimingSection()
Default constructor creating a not-running unnamed section.
See also
Timings

Definition at line 180 of file timing.hh.

Constructor & Destructor Documentation

◆ ScopedTimingSection() [1/5]

Kaskade::ScopedTimingSection::ScopedTimingSection ( )

Default constructor creating a not-running unnamed section.

Referenced by operator=(), and ScopedTimingSection().

◆ ScopedTimingSection() [2/5]

Kaskade::ScopedTimingSection::ScopedTimingSection ( ScopedTimingSection const & )
delete

◆ ScopedTimingSection() [3/5]

Kaskade::ScopedTimingSection::ScopedTimingSection ( Timings_Details::SectionBeacon const & sec)

Move constructor.

This moves the given section to the created one, leaving the given section with empty name, not running, not gathering.

◆ ScopedTimingSection() [4/5]

Kaskade::ScopedTimingSection::ScopedTimingSection ( std::string const & name,
bool gather = true )

Constructor using the default timer provided by Timings::instance().

Parameters
namethe name of the section to be timed.
gatherif false, do not gather any timings. This can be used to switch off timing collection in potentially multithreaded environments, while at the same time use ScopedTimingSection guards. The timer is started immediately.

◆ ScopedTimingSection() [5/5]

Kaskade::ScopedTimingSection::ScopedTimingSection ( std::string const & name,
Timings & timer,
bool gather = true )

Constructor using provided timer.

Parameters
timera timer. This has to exist during the lifetime of the scoped timing section.

The timer is started immediately.

◆ ~ScopedTimingSection()

Kaskade::ScopedTimingSection::~ScopedTimingSection ( )

Stops the section if it is still running.

In normal use the section is running here, so no exception is thrown. If, however, the timer's currently running section is a different one (e.g. because another section was started without being closed), Timings::stop throws. Since the destructor is implicitly noexcept, that exception terminates the program: such a mismatch is a genuine logic error, and aborting (with the exception's diagnostic on stderr) is intended.

Member Function Documentation

◆ isRunning()

bool Kaskade::ScopedTimingSection::isRunning ( ) const

Reports whether the section is currently timed.

◆ operator=()

ScopedTimingSection & Kaskade::ScopedTimingSection::operator= ( Timings_Details::SectionBeacon const & sec)

Assignment from a beacon.

If the section is running, it is implicitly stopped by the assignment.

◆ restart()

void Kaskade::ScopedTimingSection::restart ( std::string const & name)

Start new section.

If the section is running, it is implicitly stopped before the newly named section is started.

Referenced by Kaskade::VTKReader::createGrid().

◆ start()

void Kaskade::ScopedTimingSection::start ( )

Ensures the section is timed.

If the timer is not running, it is started (unless gather is set to false). Otherwise nothing is done. A running section is stopped if assigned to.

◆ stop()

void Kaskade::ScopedTimingSection::stop ( )

Ensures the section is not timed.

If the timer is running, it is stopped. Otherwise nothing is done.

◆ timer()

Timings & Kaskade::ScopedTimingSection::timer ( )

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