KASKADE 7 development version
Public Member Functions | Static Public Member Functions | Related Functions | List of all members
Kaskade::Timings Class Reference

Supports gathering and reporting execution times information for nested program parts. More...

#include <timing.hh>

Detailed Description

Supports gathering and reporting execution times information for nested program parts.

Entering and leaving timed regions incurs a (small but measurable) overhead. Thus, the timed regions should not be too quick. E.g., local assembly on a single cell is too fast for providing reasonably accurate timings.

While calling the methods is thread-safe, using it from within parallelized loops will lead to errors such as stopping a section that is currently not running (because in a different thread some other section has just been started). If needed, one timer per thread can be used.

Todo:
Implement merging of timer statistics

Example:

auto& timer = Timings::instance();
timer.start("my expensive calculation");
f(); // if f throws an exception, the timer will not be stopped! (Use ScopedTimingSection)
timer.stop("my expensive calculation");
static Timings & instance()
Returns a reference to a single default instance.
See also
ScopedTimingSection

Definition at line 63 of file timing.hh.

Public Member Functions

 Timings ()
 Constructor. More...
 
std::ostream & report (std::ostream &out, int maxlevel=1000) const
 Prints a timing report to the given stream. More...
 
Timings_Details::SectionBeacon startSection (std::string const &name)
 Provides a beacon to handing over to ScopedTimingSection for starting a section. More...
 
struct Times const * start (std::string const &name)
 Starts or continues the timing of given section. More...
 
void stop (std::string const &name)
 Stops the timing of given section. More...
 
void stop (struct Times const *ticket=nullptr)
 Stops the timing of given section. More...
 
void clear ()
 Resets the timer to an empty state. More...
 
 ~Timings ()
 

Static Public Member Functions

static Timingsinstance ()
 Returns a reference to a single default instance. More...
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &out, Timings const &timings)
 write a timing report to a stream More...
 

Constructor & Destructor Documentation

◆ Timings()

Kaskade::Timings::Timings ( )

Constructor.

◆ ~Timings()

Kaskade::Timings::~Timings ( )

Member Function Documentation

◆ clear()

void Kaskade::Timings::clear ( )

Resets the timer to an empty state.

◆ instance()

static Timings & Kaskade::Timings::instance ( )
static

◆ report()

std::ostream & Kaskade::Timings::report ( std::ostream &  out,
int  maxlevel = 1000 
) const

Prints a timing report to the given stream.

Parameters
maxlevelreport only timings up to a nesting level given here

◆ start()

struct Times const * Kaskade::Timings::start ( std::string const &  name)

Starts or continues the timing of given section.

If the section has not been started before, it is created.

Returns
a ticket that can be used to check on stopping that the section to be stopped is the currently running one. Using tickets instead of names for section stopping prevents run time errors due to typos in section names (and may be slightly faster).

Example:

auto& timer = Timings::instance();
auto ticket = timer.start("my expensive calculation");
f(); // if f throws an exception, the timer will not be stopped! (Use ScopedTimingSection)
timer.stop(ticket);

Referenced by Kaskade::GridManagerBase< Grd >::adapt(), Kaskade::NumaBCRSMatrix< Entry, Index >::conjugation(), Kaskade::createCuboid(), Kaskade::createGrid(), Kaskade::deformedProlongationStack(), Kaskade::MGProlongation::galerkinProjection(), Kaskade::GridManagerBase< Grd >::globalRefine(), Kaskade::MultiplicativeMultiGrid< Entry, Index, Smoother, Prolongation >::makeBlockJacobiPMultiGrid(), Kaskade::MultiplicativeMultiGrid< Entry, Index, Smoother, Prolongation >::makeJacobiMultiGrid(), Kaskade::MultiplicativeMultiGrid< Entry, Index, Smoother, Prolongation >::makeMultiplicativePMultiGrid(), Kaskade::BDDC::matrixDomainDecommposition(), Kaskade::MultiGridStack< Prolongation, Entry, Index >::MultiGridStack(), Kaskade::MultiplicativeMultiGrid< Entry, Index, Smoother, Prolongation >::MultiplicativeMultiGrid(), Kaskade::PatchDomainDecompositionPreconditioner< Space, m, StorageTag, SparseMatrixIndex >::PatchDomainDecompositionPreconditioner(), Kaskade::prolongation(), Kaskade::prolongationStack(), Kaskade::BDDC::KKTSolver< Domain >::solve(), and Kaskade::uniformEmbeddedErrorEstimation().

◆ startSection()

Timings_Details::SectionBeacon Kaskade::Timings::startSection ( std::string const &  name)

Provides a beacon to handing over to ScopedTimingSection for starting a section.

The advantage over calling start/stop manually is that ScopedTimingSection is exception and return safe. The following example works, while a start/stop approach would lead to a corrupted timing state and cause errors if the return statement is executed.

ScopedTimingSection section = timer.startSection("compute");
auto result = computeSomething();
if (result.wrong)
return false;
section = timer.startSection("output");
std::cout << result;
section.stop();
A scope guard object that automatically closes a timing section on destruction.
Definition: timing.hh:181
void stop()
Ensures the section is not timed.

◆ stop() [1/2]

void Kaskade::Timings::stop ( std::string const &  name)

◆ stop() [2/2]

void Kaskade::Timings::stop ( struct Times const *  ticket = nullptr)

Stops the timing of given section.

Parameters
ticketif the running section's ticket does not coincide with the given one, a LookupException is thrown. If no ticket is provided, no checking takes place (which can save a few CPU cycles, in case that's relevant).

Friends And Related Function Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream &  out,
Timings const &  timings 
)
related

write a timing report to a stream


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