summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2022-07-29 22:28:17 +0800
committerruki <[email protected]>2022-07-29 22:28:17 +0800
commitc7d8940dbe8c82b5690c60136a251c30e6214c66 (patch)
treec4e951991b4d82b800cca6afd3f6f5bf7ee4fdc3
parent3cc2905368c76fe11bed854eb9944b3198627b0f (diff)
add cpuinfo for win
-rw-r--r--core/src/xmake/os/cpuinfo.c8
-rw-r--r--xmake/core/base/memory.lua2
2 files changed, 6 insertions, 4 deletions
diff --git a/core/src/xmake/os/cpuinfo.c b/core/src/xmake/os/cpuinfo.c
index 8a064f189..473db2fdc 100644
--- a/core/src/xmake/os/cpuinfo.c
+++ b/core/src/xmake/os/cpuinfo.c
@@ -93,7 +93,7 @@ static tb_float_t xm_os_cpuinfo_usagerate()
}
return cpu_count > 0? usagerate / cpu_count : 0;
#elif defined(TB_CONFIG_OS_WINDOWS)
- // kernel include IdleTime
+ // kernel include idle_time
tb_float_t usagerate = 0;
FILETIME idle, kernel, user;
if (GetSystemTimes(&idle, &kernel, &user))
@@ -108,11 +108,11 @@ static tb_float_t xm_os_cpuinfo_usagerate()
tb_uint64_t kernel_diff = xm_os_cpuinfo_subtract_times(&kernel, &kernel_prev);
tb_uint64_t user_diff = xm_os_cpuinfo_subtract_times(&user, &user_prev);
- // kernelTime - IdleTime = kernelTime, because kernel include IdleTime
+ // kernel_time - idle_time = kernel_time, because kernel include idle_time
tb_uint64_t sys_total = kernel_diff + user_diff;
tb_uint64_t kernel_total = kernel_diff - idle_diff;
- // sometimes kernelTime > idleTime
+ // sometimes kernel_time > idle_time
if (sys_total > 0)
usagerate = (tb_float_t)((tb_double_t)(kernel_total + user_diff) / sys_total);
}
@@ -153,7 +153,7 @@ tb_int_t xm_os_cpuinfo(lua_State* lua)
// get cpu usage rate
tb_float_t usagerate = xm_os_cpuinfo_usagerate();
- if (usagerate > 0)
+ if (usagerate >= 0)
{
lua_pushstring(lua, "usagerate");
lua_pushnumber(lua, usagerate);
diff --git a/xmake/core/base/memory.lua b/xmake/core/base/memory.lua
index ca90646f4..27b7331d6 100644
--- a/xmake/core/base/memory.lua
+++ b/xmake/core/base/memory.lua
@@ -32,6 +32,8 @@ function memory.info(name)
meminfo = os._meminfo()
if meminfo.totalsize and meminfo.availsize then
meminfo.usagerate = (meminfo.totalsize - meminfo.availsize) / meminfo.totalsize
+ else
+ meminfo.usagerate = 0
end
memory._MEMINFO = meminfo
memory._MEMTIME = os.time()