1#ifndef UTOPIA_DATAIO_MONITOR_HH
2#define UTOPIA_DATAIO_MONITOR_HH
8#include <yaml-cpp/yaml.h>
10#include "../core/string.hh"
47template <
class F,
class...
Args >
53 ->
decltype((*p)(std::declval< Args >()...),
void(), std::true_type());
56 test(...) ->
decltype(std::false_type());
68 using Clock = std::chrono::high_resolution_clock;
71 using Time = std::chrono::high_resolution_clock::time_point;
130 template <
class DurationT = DurationType >
162 using Timer = std::shared_ptr< MonitorTimer >;
216 _entries.SetStyle(YAML::EmitterStyle::Flow);
232 if (
_timer->time_has_come())
264 template <
typename Value >
267 const std::string&
key,
271 recursive_setitem(
_entries, path +
"." +
key, value,
".");
282 template <
typename Time >
303 return _timer->get_emit_interval();
367 template <
typename Func >
383 template <
typename Value >
406 template <
typename Arg >
421 std::shared_ptr< MonitorManager >
The Monitor monitors entries that are emitted if a given time has passed.
Definition monitor.hh:323
const std::string _name
The name of the monitor.
Definition monitor.hh:328
void set_by_value(const std::string key, Value const &v)
Provide a new entry to the monitor manager.
Definition monitor.hh:385
Monitor(const std::string &name, const Monitor &parent_mtr)
Construct a monitor object within a hierarchy.
Definition monitor.hh:354
std::shared_ptr< MonitorManager > _mtr_mgr
The monitor manager.
Definition monitor.hh:331
Monitor(std::shared_ptr< MonitorManager > root_mtr_mgr)
Constructs a root monitor object.
Definition monitor.hh:340
std::shared_ptr< MonitorManager > get_monitor_manager() const
Get a shared pointer to the MonitorManager.
Definition monitor.hh:422
void set_by_func(const std::string key, Func &&f)
Provide a new entry to the monitor manager.
Definition monitor.hh:369
void set_entry(const std::string key, Arg arg)
Provide a new entry to the monitor manager.
Definition monitor.hh:408
std::string get_name() const
Get the name of the monitor.
Definition monitor.hh:429
The MonitorManager manages the monitor entries and MonitorTimer.
Definition monitor.hh:159
void set_time_entries(const Time time, const Time time_max)
Set time- and progress-related top level entries.
Definition monitor.hh:284
void check_timer()
Checks with the timer whether the time to emit has come.
Definition monitor.hh:230
MonitorManager(const double emit_interval, const std::string emit_prefix="!!map ", const std::string emit_suffix="")
Constructor.
Definition monitor.hh:192
Timer _timer
The monitor timer.
Definition monitor.hh:166
std::shared_ptr< MonitorTimer > Timer
Type of the timer.
Definition monitor.hh:162
YAML::Node & get_entries()
Get the reference to the monitor entries object.
Definition monitor.hh:315
std::size_t _emit_counter
Counts the number of emit operations.
Definition monitor.hh:175
const std::string _emit_suffix
A suffix to the emitted string.
Definition monitor.hh:181
void set_entry(const std::string &path, const std::string &key, const Value value)
Set an entry in the tree of monitor entries.
Definition monitor.hh:266
auto get_emit_interval()
Return the emit interval.
Definition monitor.hh:301
bool emit_enabled() const
Returns true if the emission is enabled.
Definition monitor.hh:245
void emit_if_enabled()
Perform an emission of the data to the terminal, if the flag was set.
Definition monitor.hh:209
auto get_emit_counter()
Return the emit interval.
Definition monitor.hh:308
const std::string _emit_prefix
A prefix to the emitted string.
Definition monitor.hh:178
YAML::Node _entries
The monitor entries.
Definition monitor.hh:169
Timer & get_timer()
Get a shared pointer to the MonitorTimer object.
Definition monitor.hh:294
bool _emit_enabled
The flag that determines whether to collect data.
Definition monitor.hh:172
The MonitorTimer keeps track of the time when to emit monitor data.
Definition monitor.hh:63
const DurationType _emit_interval
The emit interval.
Definition monitor.hh:79
Time _last_emit
The time of the last emit.
Definition monitor.hh:85
const DurationT get_time_elapsed() const
Get the time elapsed since the start of this timer.
Definition monitor.hh:132
const DurationType get_emit_interval() const
Return the emit interval.
Definition monitor.hh:146
double get_time_elapsed_seconds() const
Get the time elapsed since start of this timer, converted to seconds.
Definition monitor.hh:139
bool time_has_come() const
Check for whether the time to emit has come or not.
Definition monitor.hh:113
std::chrono::high_resolution_clock::time_point Time
Data type for a time point.
Definition monitor.hh:71
const Time _start_time
The starting time of the timer.
Definition monitor.hh:82
void reset()
Reset the timer to the current time.
Definition monitor.hh:124
MonitorTimer(const double emit_interval)
Constructor.
Definition monitor.hh:97
std::chrono::duration< double > DurationType
Data type for the time unit.
Definition monitor.hh:74
std::chrono::high_resolution_clock Clock
Data type for the clock.
Definition monitor.hh:68
Check if a type T is callable, i.e., if it has.
Definition type_traits.hh:685
static constexpr bool value
Definition type_traits.hh:687
void recursive_setitem(Config &d, std::list< std::string > key_sequence, const T val)
Recursively sets an element in a configuration tree.
Definition cfg_utils.hh:422
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
Definition parallel.hh:235
static auto test(...) -> decltype(std::false_type())
static auto test(U *p) -> decltype((*p)(std::declval< Args >()...), void(), std::true_type())