TimerRegistrar is a singleton to keep track of and print timers. Does not manage storage.
More...
#include <timer_registrar.h>
TimerRegistrar is a singleton to keep track of and print timers. Does not manage storage.
◆ TimerRegistrar() [1/3]
◆ TimerRegistrar() [2/3]
◆ TimerRegistrar() [3/3]
| mio::timing::TimerRegistrar::TimerRegistrar |
( |
| ) |
|
|
privatedefault |
◆ ~TimerRegistrar()
| mio::timing::TimerRegistrar::~TimerRegistrar |
( |
| ) |
|
|
inlineprivate |
Specify a destructor to allow printing all timers after exit from main.
◆ add_timer()
Add a new timer to the TimerRegistrar.
Note that the TimerRegistrar does not manage any storage, it only keeps a list of the timers and their names. Therefore, if you manually call add_timer, you have to make sure that the registered timer lives long enough for e.g. the last print_timer call. You may want to disable_final_timer_summary, and look at NamedTimer as an example that does guarantee correct object lifetime.
- Parameters
-
| registration | A new registration with a name, a reference to a timer, and the thread id it is created on. |
◆ disable_final_timer_summary()
| void mio::timing::TimerRegistrar::disable_final_timer_summary |
( |
| ) |
|
|
inline |
Prevent the TimerRegistrar from calling print_timers on exit from main.
◆ gather_timers()
Gather timers from all ranks, using external_timers as temporary timer storage for gathered_register.
◆ get_instance()
Access the TimerRegistrar.
TimerRegistrar acts as a singleton, using this method to access the instance. This makes TimerRegistrar accessible everywhere, without having to manage a TimerRegistrar object or pass an instance to any class or function that uses timers. In particular, it allows e.g. NamedTimer to register itself automatically, while guaranteeing a correct destruction order.
- Returns
- A reference to the TimerRegistrar instance.
◆ get_register()
| const auto& mio::timing::TimerRegistrar::get_register |
( |
| ) |
const |
|
inline |
Returns a read only list of all TimerRegistrations. Can be used to print or evaluate timers.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ print_gathered_timers()
| void mio::timing::TimerRegistrar::print_gathered_timers |
( |
mpi::Comm |
comm, |
|
|
std::ostream & |
out = std::cout |
|
) |
| |
|
inline |
Print all timers gathered on the given MPI Comm using a Printer.
By default, uses TablePrinter to write to stdout. The printer can be changed using the set_printer member.
- Parameters
-
| comm | An MPI communicator. Make sure this method is called by all ranks on comm! |
| out | Any output stream, defaults to std::cout. |
◆ print_timers()
| void mio::timing::TimerRegistrar::print_timers |
( |
std::ostream & |
out = std::cout | ) |
const |
|
inline |
Print all timers using a Printer.
By default, uses TablePrinter to write to stdout. The printer can be changed using the set_printer member.
- Parameters
-
| out | Any output stream, defaults to std::cout. |
◆ set_printer()
| void mio::timing::TimerRegistrar::set_printer |
( |
std::unique_ptr< Printer > && |
printer | ) |
|
|
inline |
Replace the internal printer used for print_timers.
To allow making a final timer summary on exit from main, the TimerRegistrar has to take ownership of the printer. Usage may look as follows:
auto printer = std::make_unique<mio::timing::TablePrinter>();
void set_printer(std::unique_ptr< Printer > &&printer)
Replace the internal printer used for print_timers.
Definition: timer_registrar.h:140
static TimerRegistrar & get_instance()
Access the TimerRegistrar.
Definition: timer_registrar.h:56
Note that after passing the printer using std::move, it will contain a nullptr and can not be used again.
- Parameters
-
| printer | A unique pointer to something that implements Printer. |
◆ m_print_on_death
| bool mio::timing::TimerRegistrar::m_print_on_death = true |
|
private |
Whether to call m_printer during the destructor.
◆ m_printer
| std::unique_ptr<Printer> mio::timing::TimerRegistrar::m_printer = std::make_unique<TablePrinter>() |
|
private |
A printer to visualize all timers.
◆ m_register
List that allows access to timers without having their name.
◆ m_registration_lock
| std::mutex mio::timing::TimerRegistrar::m_registration_lock |
|
private |
Lock to safeguard m_register against concurrent writes.