30 itsPrefix(prefix), itsInterval(interval), itsLogLevel(loglevel), itsCount(0),
31 itsStartTime(std::chrono::steady_clock::now()), itsSecs(0.0),
32 itsMinSecs(1.0e30), itsMaxSecs(-1.0e30), itsStr(
"-- fps, --% CPU"),
33 itsStartTimeForCpu(std::chrono::steady_clock::now())
35 if (interval == 0)
LFATAL(
"Interval must be > 0");
36 getrusage(RUSAGE_SELF, &itsStartRusage);
49 std::chrono::duration<double>
const dur = std::chrono::steady_clock::now() - itsStartTime;
50 double secs = dur.count();
51 if (seconds) *seconds = secs;
54 itsSecs += secs; ++itsCount;
57 if (secs < itsMinSecs) itsMinSecs = secs;
58 if (secs > itsMaxSecs) itsMaxSecs = secs;
60 if (itsCount >= itsInterval)
62 double avgsecs = itsSecs / itsInterval;
63 std::ostringstream ss;
64 ss << itsPrefix <<
" average (" << itsInterval <<
") duration ";
jevois::secs2str(ss, avgsecs);
68 if (avgsecs > 0.0) { fps = 1.0F / float(avgsecs); ss <<
" (" << fps <<
" fps)"; }
72 case LOG_INFO:
LINFO(ss.str());
break;
73 case LOG_ERR:
LERROR(ss.str());
break;
74 case LOG_CRIT:
LFATAL(ss.str());
break;
83 rusage stoprusage; getrusage(RUSAGE_SELF, &stoprusage);
85 double const user_secs = double(stoprusage.ru_utime.tv_sec) - double(itsStartRusage.ru_utime.tv_sec) +
86 (double(stoprusage.ru_utime.tv_usec) - double(itsStartRusage.ru_utime.tv_usec)) / 1000000.0;
88 std::chrono::duration<double>
const cpudur = std::chrono::steady_clock::now() - itsStartTimeForCpu;
90 double const cpu = 100.0 * user_secs / cpudur.count();
92#ifdef JEVOIS_PLATFORM_PRO
94 static char const tempname[] =
"/sys/class/thermal/thermal_zone1/temp";
95 static char const freqname[] =
"/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_cur_freq";
98 static char const tempname[] =
"/sys/class/thermal/thermal_zone0/temp";
99 static char const freqname[] =
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq";
105 std::ifstream ifs(tempname);
108 try { std::string t; std::getline(ifs, t); temp = std::stoi(t); }
114#ifndef JEVOIS_PLATFORM_A33
119 std::ifstream ifs2(freqname);
122 try { std::string f; std::getline(ifs2, f); freq = std::stoi(f) / 1000; }
128 std::ostringstream os; os << std::fixed << std::setprecision(1) << fps <<
" fps, " << cpu <<
"% CPU, "
129 << temp <<
"C, " << freq <<
" MHz";
133 itsSecs = 0.0; itsMinSecs = 1.0e30; itsMaxSecs = -1.0e30; itsCount = 0;
std::string secs2str(double secs)
Report a duration given in seconds with variable units (ns, us, ms, or s), with precision of 2 decima...