泌採資誼CPU聞喘楕
作者 佚名技术
来源 程序设计
浏览
发布时间 2012-06-30
rmation(SystemTimeInformation,&SysTimeInfo,sizeof(SysTimeInfo),0); if (status!=NO_ERROR) return; // get new CPU''s idle time status = NtQuerySystemInformation(SystemPerformanceInformation,&SysPerfInfo,sizeof(SysPerfInfo),NULL); if (status != NO_ERROR) return; // if it''s a first call - skip it if (liOldIdleTime.QuadPart != 0) { // CurrentValue = NewValue - OldValue dbIdleTime = Li2Double(SysPerfInfo.liIdleTime) - Li2Double(liOldIdleTime); dbSystemTime = Li2Double(SysTimeInfo.liKeSystemTime) - Li2Double(liOldSystemTime); // CurrentCpuIdle = IdleTime / SystemTime dbIdleTime = dbIdleTime / dbSystemTime; // CurrentCpuUsage% = 100 - (CurrentCpuIdle * 100) / NumberOfProcessors dbIdleTime = 100.0 - dbIdleTime * 100.0 / (double)SysBaseInfo.bKeNumberProcessors + 0.5; printf("\b\b\b\b%3d%%",(UINT)dbIdleTime); } // store new CPU''s idle and system time liOldIdleTime = SysPerfInfo.liIdleTime; liOldSystemTime = SysTimeInfo.liKeSystemTime; // wait one second Sleep(1000); } printf("\n"); } //------------------------------------------------------------- W9X: #include <windows.h> #include <conio.h> #include <stdio.h> void main(void) { HKEY hkey; DWORD dwDataSize; DWORD dwType; DWORD dwCpuUsage; // starting the counter if ( RegOpenKeyEx( HKEY_DYN_DATA, "PerfStats\\StartStat", 0,KEY_ALL_ACCESS, &hkey ) != ERROR_SUCCESS) return; dwDataSize=sizeof(DWORD); RegQueryValueEx( hkey, "KERNEL\\CPUUsage", NULL,&dwType, (LPBYTE)&dwCpuUsage, &dwDataSize ); RegCloseKey(hkey); // geting current counter''s value if ( RegOpenKeyEx( HKEY_DYN_DATA, "PerfStats\\StatData", 0,KEY_READ, &hkey ) != ERROR_SUCCESS) return; printf("\nCPU Usage (press any key to exit): "); while(!_kbhit()) { dwDataSize=sizeof(DWORD); RegQueryValueEx( hkey, "KERNEL\\CPUUsage", NULL,&dwType, (LPBYTE)&dwCpuUsage, &dwDataSize ); Sleep(500); printf("\b\b\b\b%3d%%",dwCpuUsage); } printf("\n"); RegCloseKey(hkey); // stoping the counter if ( RegOpenKeyEx( HKEY_DYN_DATA, "PerfStats\\StopStat", 0,KEY_ALL_ACCESS, &a |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
上一篇: Windows的动态链接库原理及使用1下一篇: 用快照枚举当前系统中所有进程
关于泌採資誼CPU聞喘楕的所有评论