12 #if defined(__linux__) || defined(Q_OS_ANDROID)
13 static constexpr
const char* UNIX_PROC_STAT {
"/proc/stat" };
15 #if defined(__linux__) || defined(Q_OS_ANDROID) || defined(Q_OS_MACOS)
20 #include <mach/mach_init.h>
21 #include <mach/mach_error.h>
22 #include <mach/mach_host.h>
23 #include <mach/vm_map.h>
27 : m_numCycles(ncycles), m_name(
std::move(nname))
34 #if defined(__linux__) || defined(Q_OS_ANDROID)
36 if (QFile::exists(UNIX_PROC_STAT))
41 if (!
m_cpuStat->open(QIODevice::ReadOnly))
91 auto timenow = nowAsDuration<std::chrono::microseconds>();
106 std::chrono::microseconds tottime = std::accumulate(
m_times.cbegin(),
m_times.cend(), 0us);
107 using doublemics = std::chrono::duration<double, std::micro>;
108 doublemics mean = duration_cast<doublemics>(tottime) / cycles;
111 m_lastFps = cycles * (1000000.0F / tottime.count());
114 double sum_of_squared_deviations =
116 [mean](
double sum, std::chrono::microseconds time)
117 {double delta = (mean - duration_cast<doublemics>(time)).count();
118 return sum + (delta * delta); });
121 double standard_deviation = sqrt(sum_of_squared_deviations / (cycles - 1));
123 m_lastSd = standard_deviation / mean.count();
131 LOG(VB_GENERAL, LOG_INFO,
132 m_name + QString(
"FPS: %1 Mean: %2 Std.Dev: %3 ")
133 .arg(
m_lastFps, 7,
'f', 2).arg((
int)mean.count(), 5)
134 .arg((
int)standard_deviation, 5) + extra);
146 m_starttime = nowAsDuration<std::chrono::microseconds>();
151 QString result =
"N/A";
153 #if defined(__linux__) || defined(Q_OS_ANDROID)
159 QByteArray line =
m_cpuStat->readLine(256);
167 while (!line.isEmpty() && cores <
MAX_CORES)
169 std::array<unsigned long long,9> stats {};
171 if (sscanf(line.constData(),
172 "cpu%30d %30llu %30llu %30llu %30llu %30llu "
173 "%30llu %30llu %30llu %30llu %*5000s\n",
174 &num, stats.data(), &stats[1], &stats[2], &stats[3],
175 &stats[4], &stats[5], &stats[6], &stats[7], &stats[8]) >= 4)
177 float load = stats[0] + stats[1] + stats[2] + stats[4] +
178 stats[5] + stats[6] + stats[7] + stats[8] -
183 float total = load + stats[3] -
m_lastStats[ptr + 3];
185 result += QString(
"%1% ").arg(load / total * 100, 0,
'f', 0);
196 processor_cpu_load_info_t load;
197 mach_msg_type_number_t msgcount;
198 natural_t processorcount;
200 if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &processorcount, (processor_info_array_t *)&load, &msgcount) == KERN_SUCCESS)
204 for (natural_t i = 0; i < processorcount && i <
MAX_CORES; i++)
206 std::array<unsigned long long,2> stats {};
207 stats[0] = load[i].cpu_ticks[CPU_STATE_IDLE];
208 stats[1] = load[i].cpu_ticks[CPU_STATE_IDLE] + load[i].cpu_ticks[CPU_STATE_USER] +
209 load[i].cpu_ticks[CPU_STATE_SYSTEM] + load[i].cpu_ticks[CPU_STATE_NICE];
211 double totaldelta = stats[1] -
m_lastStats[ptr + 1];
213 result += QString(
"%1% ").arg(((totaldelta - idledelta) / totaldelta) * 100.0, 0,
'f', 0);