7 #ifndef swcdb_common_sys_Resources_CPU_h
8 #define swcdb_common_sys_Resources_CPU_h
11 #if defined(__MINGW64__) || defined(_WIN32)
12 #include <processthreadsapi.h>
14 #include <sys/sysinfo.h>
20 namespace SWC {
namespace System {
45 uint64_t
check(uint64_t ts) noexcept {
56 void print(std::ostream& out)
const {
59 <<
" usage=" <<
usage <<
"%m"
60 <<
" threads=" <<
threads <<
')';
75 uint64_t utime = 0, stime = 0, _nthreads = 0;
77 #if defined(__MINGW64__) || defined(_WIN32)
78 FILETIME sysIdle, sysKernel, sysUser;
79 if(!GetSystemTimes(&sysIdle, &sysKernel, &sysUser))
83 t.HighPart = sysKernel.dwHighDateTime;
84 t.LowPart = sysKernel.dwLowDateTime;
86 t.HighPart = sysIdle.dwHighDateTime;
87 t.LowPart = sysIdle.dwLowDateTime;
88 if(stime > t.QuadPart)
92 t.HighPart = sysUser.dwHighDateTime;
93 t.LowPart = sysUser.dwLowDateTime;
100 std::ifstream buffer(
"/proc/self/stat");
101 if(!buffer.is_open())
105 buffer >> tmp >> str_tmp >> str_tmp
109 >> tmp >> utime >> stime
127 #if defined(__MINGW64__) || defined(_WIN32)
134 utime = ((
stat_utime - utime) * 100000) / chk;
136 stime = ((
stat_stime - stime) * 100000) / chk;
147 #if defined(__MINGW64__) || defined(_WIN32)
152 std::ifstream buffer(
153 "/sys/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq");
154 if(buffer.is_open()) {
167 std::ifstream buffer(
"/proc/cpuinfo");
168 if(buffer.is_open()) {
171 size_t tmp_speed = 0;
177 buffer >> tmp >> tmp_speed;
181 }
while (!buffer.eof());
206 #endif // swcdb_common_sys_Resources_CPU_h