递归火山软件开发平台
标题:
视窗取CPU使用率
[打印本页]
作者:
ゞ情非得已Sky
时间:
2023-4-17 23:51
标题:
视窗取CPU使用率
视窗取CPU使用率
<火山程序 类型 = "通常" 版本 = 1 />
方法 取CPU使用率 <公开 静态 类型 = 整数 注释 = "获取cpu使用率" 折叠 @禁止流程检查 = 真>
{
@ FILETIME idleTime, kernelTime, userTime;
@ ULARGE_INTEGER prevIdleTime, prevKernelTime, prevUserTime;
@ prevIdleTime.QuadPart = 0;
@ prevKernelTime.QuadPart = 0;
@ prevUserTime.QuadPart = 0;
@ while (true) {
@ GetSystemTimes(&idleTime, &kernelTime, &userTime);
@ ULARGE_INTEGER currentIdleTime, currentKernelTime, currentUserTime;
@ currentIdleTime.LowPart = idleTime.dwLowDateTime;
@ currentIdleTime.HighPart = idleTime.dwHighDateTime;
@ currentKernelTime.LowPart = kernelTime.dwLowDateTime;
@ currentKernelTime.HighPart = kernelTime.dwHighDateTime;
@ currentUserTime.LowPart = userTime.dwLowDateTime;
@ currentUserTime.HighPart = userTime.dwHighDateTime;
@ if (prevIdleTime.QuadPart != 0) {
@ ULONGLONG idleTicks = currentIdleTime.QuadPart - prevIdleTime.QuadPart;
@ ULONGLONG totalTicks = (currentKernelTime.QuadPart - prevKernelTime.QuadPart) + (currentUserTime.QuadPart - prevUserTime.QuadPart);
@ double cpuUsage = (1.0 - ((double)idleTicks) / totalTicks) * 100.0;
@ return cpuUsage;
@ }
@ prevIdleTime = currentIdleTime;
@ prevKernelTime = currentKernelTime;
@ prevUserTime = currentUserTime;
@ Sleep(1000);
@ }
@ return 0;
}
(, 下载次数: 28)
上传
点击文件名下载附件
作者:
as853749515
时间:
2023-5-27 12:41
会卡UI
作者:
ゞ情非得已Sky
时间:
2023-5-27 13:30
as853749515 发表于 2023-5-27 12:41
会卡UI
把这一段死循环删除
(, 下载次数: 32)
上传
点击文件名下载附件
作者:
server
时间:
2023-5-27 14:01
努力一下,把单进程占有率也做了。
作者:
dxp04
时间:
2023-8-1 00:49
用上了,这个确实挺好用的,佩服大佬
欢迎光临 递归火山软件开发平台 (https://bbs.voldp.com/)
Powered by Discuz! X3.4