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 widthKey = 30;
175 constexpr size_t width = 24;
176 msg <<
"\n===== Monitor: " << fsName <<
"\n";
177 if constexpr (!std::is_same_v<ETimerKey, EDummy>) {
178 msg <<
"\n----- Timers:\n";
179 msg << setw(widthKey) << left <<
"Key" <<
' ';
180 msg << setw(width) << left <<
"N Calls" <<
' ';
181 msg << setw(width) << left <<
"Average [s]" <<
' ';
182 msg << setw(width) << left <<
"Min [s]" <<
' ';
183 msg << setw(width) << left <<
"Max [s]" <<
' ';
184 msg << setw(width) << left <<
"Total [s]" <<
'\n';
186 for (
int iKey = 0; iKey < fMonitorData.GetNofTimers(); ++iKey) {
187 const Timer& timer = fMonitorData.GetTimer(
static_cast<ETimerKey
>(iKey));
188 msg << setw(widthKey) << faTimerNames[iKey] <<
' ';
190 msg << setw(width) << timer.
GetAverage() <<
' ';
191 msg << setw(width) << timer.
GetMin() <<
' ';
192 msg << setw(width) << timer.
GetMax() <<
' ';
193 msg << setw(width) << timer.
GetTotal() <<
'\n';
197 msg <<
"\n----- Counters:\n";
198 msg << setw(widthKey) << left <<
"Key" <<
' ';
199 msg << setw(width) << left <<
"Total" <<
' ';
200 for (
auto key : fvCounterRatioKeys) {
201 msg << setw(width) << left << std::string(
"per ") + faCounterNames[key] <<
' ';
204 for (
int iKey = 0; iKey < fMonitorData.GetNofCounters(); ++iKey) {
205 auto counterValue = fMonitorData.GetCounterValue(
static_cast<ECounterKey
>(iKey));
206 msg << setw(widthKey) << left << faCounterNames[iKey] <<
' ';
207 msg << setw(width) << right << counterValue <<
' ';
208 for (
auto keyDen : fvCounterRatioKeys) {
209 auto ratio =
static_cast<double>(counterValue) / fMonitorData.GetCounterValue(keyDen);
210 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.
Monitor class for the CA tracking.
TimerArray< std::string > faTimerNames
Array of timer names.
Monitor()=default
Default constructor.
const std::string & GetCounterName(ECounterKey key) const
Gets counter name.
void SetMonitorData(const MonitorData< ECounterKey, ETimerKey > &data)
Sets monitor data.
void IncrementCounter(ECounterKey key, int num)
Increments key counter by a number.
std::string ToString() const
Prints counters summary to string.
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.
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.
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.