25 itsPrefix(prefix), itsInterval(interval), itsLogLevel(loglevel),
26 itsStartTime(std::chrono::steady_clock::now())
28 itsData = {
"", 0, 0.0, 1.0e30, -1.0e30, itsStartTime };
29 if (interval == 0)
LFATAL(
"Interval must be > 0");
41 std::chrono::time_point<std::chrono::steady_clock> now = std::chrono::steady_clock::now();
44 size_t const sz = itsCheckpointData.size();
45 for (
size_t i = 0; i < sz; ++i)
47 data & cpd = itsCheckpointData[i];
51 std::chrono::duration<double> dur;
52 if (i == 0) dur = now - itsStartTime;
else dur = now - itsCheckpointData[i - 1].lasttime;
53 double const secs = dur.count();
57 if (secs < cpd.minsecs) cpd.minsecs = secs;
58 if (secs > cpd.maxsecs) cpd.maxsecs = secs;
66 std::chrono::duration<double> dur;
67 if (sz == 0) dur = now - itsStartTime;
else dur = now - itsCheckpointData[sz - 1].lasttime;
68 double secs = dur.count();
70 itsCheckpointData.push_back({ desc, 1, secs, secs, secs, now });
76 std::chrono::duration<double>
const dur = std::chrono::steady_clock::now() - itsStartTime;
77 double secs = dur.count();
80 itsData.secs += secs; ++itsData.count;
83 if (secs < itsData.minsecs) itsData.minsecs = secs;
84 if (secs > itsData.maxsecs) itsData.maxsecs = secs;
86 if (itsData.count >= itsInterval)
89 double const avgsecs = itsData.secs / itsData.count;
90 std::ostringstream ss;
91 ss << itsPrefix <<
" overall average (" << itsData.count <<
") duration ";
jevois::secs2str(ss, avgsecs);
94 if (avgsecs > 0.0) ss <<
" (" << 1.0 / avgsecs <<
" fps)";
98 case LOG_INFO:
LINFO(ss.str());
break;
99 case LOG_ERR:
LERROR(ss.str());
break;
100 case LOG_CRIT:
LFATAL(ss.str());
break;
101 default:
LDEBUG(ss.str());
105 for (data
const & cpd : itsCheckpointData)
107 double const cpavgsecs = cpd.count ? cpd.secs / cpd.count : 0.0;
108 std::ostringstream cpss;
109 cpss << itsPrefix <<
" - " << cpd.desc <<
" average (" << cpd.count <<
") delta duration ";
113 if (cpavgsecs > 0.0) cpss <<
" (" << 1.0 / cpavgsecs <<
" fps)";
117 case LOG_INFO:
LINFO(cpss.str());
break;
118 case LOG_ERR:
LERROR(cpss.str());
break;
119 case LOG_CRIT:
LFATAL(cpss.str());
break;
120 default:
LDEBUG(cpss.str());
125 itsData = {
"", 0, 0.0, 1.0e30, -1.0e30, itsStartTime };
126 itsCheckpointData.clear();
std::string secs2str(double secs)
Report a duration given in seconds with variable units (ns, us, ms, or s), with precision of 2 decima...