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;
65 if (itsLogLevel != -1) ss <<
" average (" << itsInterval <<
") duration ";
70 if (avgsecs > 0.0) { fps = 1.0F / float(avgsecs); ss <<
" (" << fps <<
" fps)"; }
74 case LOG_INFO:
LINFO(ss.str());
break;
75 case LOG_ERR:
LERROR(ss.str());
break;
76 case LOG_CRIT:
LFATAL(ss.str());
break;
77 case -1: itsStr = ss.str();
break;
81 if (itsLogLevel != -1)
88 rusage stoprusage; getrusage(RUSAGE_SELF, &stoprusage);
90 double const user_secs = double(stoprusage.ru_utime.tv_sec) - double(itsStartRusage.ru_utime.tv_sec) +
91 (double(stoprusage.ru_utime.tv_usec) - double(itsStartRusage.ru_utime.tv_usec)) / 1000000.0;
93 std::chrono::duration<double>
const cpudur = std::chrono::steady_clock::now() - itsStartTimeForCpu;
95 double const cpu = 100.0 * user_secs / cpudur.count();
97#ifdef JEVOIS_PLATFORM_PRO
99 static char const tempname[] =
"/sys/class/thermal/thermal_zone1/temp";
100 static char const freqname[] =
"/sys/devices/system/cpu/cpu2/cpufreq/cpuinfo_cur_freq";
103 static char const tempname[] =
"/sys/class/thermal/thermal_zone0/temp";
104 static char const freqname[] =
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq";
110 std::ifstream ifs(tempname);
113 try { std::string t; std::getline(ifs, t); temp = std::stoi(t); }
119#ifndef JEVOIS_PLATFORM_A33
124 std::ifstream ifs2(freqname);
127 try { std::string f; std::getline(ifs2, f); freq = std::stoi(f) / 1000; }
133 std::ostringstream os; os << std::fixed << std::setprecision(1) << fps <<
" fps, " << cpu <<
"% CPU, "
134 << temp <<
"C, " << freq <<
" MHz";
139 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...