13#if defined(Q_OS_LINUX) || defined(Q_OS_ANDROID)
14static constexpr const char* UNIX_PROC_STAT {
"/proc/stat" };
16#if defined(Q_OS_LINUX) || defined(Q_OS_ANDROID) || defined(Q_OS_MACOS)
21#include <mach/mach_init.h>
22#include <mach/mach_error.h>
23#include <mach/mach_host.h>
24#include <mach/vm_map.h>
28 : m_numCycles(ncycles), m_name(std::move(nname))
35#if defined(Q_OS_LINUX) || defined(Q_OS_ANDROID)
42 if (!
m_cpuStat->open(QIODevice::ReadOnly))
92 auto timenow = nowAsDuration<std::chrono::microseconds>();
107 std::chrono::microseconds tottime = std::accumulate(
m_times.cbegin(),
m_times.cend(), 0us);
108 using doublemics = std::chrono::duration<double, std::micro>;
109 doublemics mean = duration_cast<doublemics>(tottime) / cycles;
112 m_lastFps = cycles * (1000000.0F / tottime.count());
115 double sum_of_squared_deviations =
117 [mean](
double sum, std::chrono::microseconds time)
118 {double delta = (mean - duration_cast<doublemics>(time)).count();
119 return sum + (delta * delta); });
122 double standard_deviation = sqrt(sum_of_squared_deviations / (cycles - 1));
124 m_lastSd = standard_deviation / mean.count();
132 LOG(VB_GENERAL, LOG_INFO,
133 m_name + QString(
"FPS: %1 Mean: %2 Std.Dev: %3 ")
134 .arg(
m_lastFps, 7,
'f', 2).arg((
int)mean.count(), 5)
135 .arg((
int)standard_deviation, 5) + extra);
147 m_starttime = nowAsDuration<std::chrono::microseconds>();
152 QString result =
"N/A";
154#if defined(Q_OS_LINUX) || defined(Q_OS_ANDROID)
160 QByteArray line =
m_cpuStat->readLine(256);
168 while (!line.isEmpty() && cores <
MAX_CORES)
170 std::array<unsigned long long,9> stats {};
172 if (sscanf(line.constData(),
173 "cpu%30d %30llu %30llu %30llu %30llu %30llu "
174 "%30llu %30llu %30llu %30llu %*5000s\n",
175 &num, stats.data(), &stats[1], &stats[2], &stats[3],
176 &stats[4], &stats[5], &stats[6], &stats[7], &stats[8]) >= 4)
178 float load = stats[0] + stats[1] + stats[2] + stats[4] +
179 stats[5] + stats[6] + stats[7] + stats[8] -
184 float total = load + stats[3] -
m_lastStats[ptr + 3];
186 result += QString(
"%1% ").arg(load / total * 100, 0,
'f', 0);
197 processor_cpu_load_info_t load =
nullptr;
198 mach_msg_type_number_t msgcount = 0;
199 natural_t processorcount = 0;
201 if (host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &processorcount, (processor_info_array_t *)&load, &msgcount) == KERN_SUCCESS)
205 for (natural_t i = 0; i < processorcount && i <
MAX_CORES; i++)
207 std::array<unsigned long long,2> stats {};
208 stats[0] = load[i].cpu_ticks[CPU_STATE_IDLE];
209 stats[1] = load[i].cpu_ticks[CPU_STATE_IDLE] + load[i].cpu_ticks[CPU_STATE_USER] +
210 load[i].cpu_ticks[CPU_STATE_SYSTEM] + load[i].cpu_ticks[CPU_STATE_NICE];
212 double totaldelta = stats[1] -
m_lastStats[ptr + 1];
214 result += QString(
"%1% ").arg(((totaldelta - idledelta) / totaldelta) * 100.0, 0,
'f', 0);
Jitterometer(QString nname, int ncycles=0)
QVector< std::chrono::microseconds > m_times
void SetNumCycles(int cycles)
std::chrono::microseconds m_starttime
unsigned long long * m_lastStats
static constexpr size_t MAX_CORES
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
MBASE_PUBLIC long long copy(QFile &dst, QFile &src, uint block_size=0)
Copies src file to dst file.