视窗取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;
}
会卡UI as853749515 发表于 2023-5-27 12:41
会卡UI
把这一段死循环删除 努力一下,把单进程占有率也做了。 用上了,这个确实挺好用的,佩服大佬
页:
[1]