15#include <boost/serialization/access.hpp>
16#include <boost/serialization/string.hpp>
17#include <boost/serialization/vector.hpp>
34 template<
class ECounterKey,
class ETimerKey = EDummy>
141 template<
typename Archive>
166 template<
class ECounterKey,
class ETimerKey>
173 std::stringstream msg;
174 constexpr size_t width = 24;
175 auto Cmp = [](
const std::string& l,
const std::string& r) {
return l.size() < r.size(); };
176 msg <<
"\n===== Monitor: " <<
fsName <<
"\n";
177 if constexpr (!std::is_same_v<ETimerKey, EDummy>) {
179 msg <<
"\n----- Timers:\n";
180 msg << setw(widthKeyTimer) << left <<
"Key" <<
' ';
181 msg << setw(width) << left <<
"N Calls" <<
' ';
182 msg << setw(width) << left <<
"Average [s]" <<
' ';
183 msg << setw(width) << left <<
"Min [s]" <<
' ';
184 msg << setw(width) << left <<
"Max [s]" <<
' ';
185 msg << setw(width) << left <<
"Total [s]" <<
'\n';
187 for (
int iKey = 0; iKey <
fMonitorData.GetNofTimers(); ++iKey) {
189 msg << setw(widthKeyTimer) <<
faTimerNames[iKey] <<
' ';
190 msg << setw(width) << std::fixed << std::setprecision(4) << timer.
GetNofCalls() <<
' ';
191 msg << setw(width) << std::fixed << std::setprecision(4) << timer.
GetAverage() <<
' ';
192 msg << setw(width) << std::fixed << std::setprecision(4) << timer.
GetMin() <<
' ';
193 msg << setw(width) << std::fixed << std::setprecision(4) << timer.
GetMax() <<
' ';
194 msg << setw(width) << std::fixed << std::setprecision(4) << timer.
GetTotal() <<
'\n';
198 msg <<
"\n----- Counters:\n";
200 msg << setw(widthKeyCounter) << left <<
"Key" <<
' ';
201 msg << setw(width) << left <<
"Total" <<
' ';
203 msg << setw(width) << left << std::string(
"per ") +
faCounterNames[key] <<
' ';
206 for (
int iKey = 0; iKey <
fMonitorData.GetNofCounters(); ++iKey) {
207 auto counterValue =
fMonitorData.GetCounterValue(
static_cast<ECounterKey
>(iKey));
208 msg << setw(widthKeyCounter) << left <<
faCounterNames[iKey] <<
' ';
209 msg << setw(width) << right << counterValue <<
' ';
211 auto ratio =
static_cast<double>(counterValue) /
fMonitorData.GetCounterValue(keyDen);
212 msg << setw(width) << right << ratio <<
' ';
Implementation of cbm::algo::ca::EnumArray class.
A block of data for cbm::algo::ca::Monitor.
Class of arrays, which can be accessed by an enum class entry as an index.
TimerArray< std::string > faTimerNames
Array of timer names.
Monitor()=default
Default constructor.
const std::string & GetCounterName(ECounterKey key) const
Gets counter name.
std::string ToString() const
Prints counters summary to string.
void SetMonitorData(const MonitorData< ECounterKey, ETimerKey > &data)
Sets monitor data.
void IncrementCounter(ECounterKey key, int num)
Increments key counter by a number.
void IncrementCounter(ECounterKey key)
Increments key counter by 1.
void SetName(std::string_view name)
Sets name of the monitor.
void Reset()
Resets the counters.
CounterArray< std::string > faCounterNames
Array of counter names.
void SetCounterName(ECounterKey key, std::string_view name)
Sets name of counter.
void StartTimer(ETimerKey key)
Starts timer.
Monitor(std::string_view name)
Constructor.
std::string fsName
Name of the monitor.
Monitor & operator=(Monitor &&)=delete
Move assignment operator.
EnumArray< ETimerKey, T > TimerArray
Alias to array, indexed by the timer enumeration.
Monitor(const Monitor &)=delete
Copy constructor.
Monitor & operator=(const Monitor &)=delete
Copy assignment operator.
~Monitor()=default
Destructor.
MonitorData< ECounterKey, ETimerKey > fMonitorData
Monitor data.
void StopTimer(ETimerKey key)
Stops timer.
const std::string & GetName() const
Gets name of the monitor.
std::vector< ECounterKey > fvCounterRatioKeys
List of keys, which are used as denominators in ratios.
void serialize(Archive &ar, const unsigned int)
const MonitorData< ECounterKey, ETimerKey > & GetMonitorData() const
Gets monitor data.
void SetTimerName(ETimerKey key, std::string_view name)
Sets name of the timer.
friend class boost::serialization::access
void AddMonitorData(const MonitorData< ECounterKey, ETimerKey > &data, bool parallel=false)
Adds the other monitor data to this.
int GetCounterValue(ECounterKey key) const
Gets counter value.
const Timer & GetTimer(ETimerKey key) const
Gets timer.
const std::string & GetTimerName(ETimerKey key) const
Gets timer name.
Monitor(Monitor &&)=delete
Move constructor.
EnumArray< ECounterKey, T > CounterArray
Alias to array, indexed by the monitorable enumeration.
void SetRatioKeys(const std::vector< ECounterKey > &vKeys)
Sets keys of counters, which are used as denominators for ratios.
A timer class for the monitor.
double GetTotal() const
Gets total time [s].
double GetMin() const
Gets time of the shortest call [s].
double GetAverage() const
Gets average time [s].
int GetNofCalls() const
Gets number of calls.
double GetMax() const
Gets time of the longest call [s].
TODO: SZh 8.11.2022: add selection of parameterisation.