()()()()多CPU 计算出各进程CPU使用百分比
多CPU 计算出各进程CPU使用百分比
在单CPU与双核系统时,运行结果是正确的,
1.各位可以帮我讲讲机制
2.帮检视脚本在多cpu是是否存在缺陷
谢谢
代码大致如下:
For Each objInstance1 in objService.ExecQuery("Select * from Win32_PerfRawData_PerfProc_Process")
N1 = objInstance1.PercentProcessorTime
D1 = objInstance1.TimeStamp_Sys100NS
WScript.Sleep(500)
For Each perf_instance2 in objService.ExecQuery("Select * from Win32_PerfRawData_PerfProc_Process")
N2 = perf_instance2.PercentProcessorTime
D2 = perf_instance2.TimeStamp_Sys100NS
Nd = (N2 - N1)
Dd = (D2 - D1)
PercentProcessorTime = ((Nd/Dd)) * 100
多CPU运行结果大致如下:(以下进程名乱写的),是否存在问题?
[PID] [CPU(%)] [PROCESS]
0 239 System Idle Process
6236 95 c:\dfasfa\xxx.exe
12716 17 cdsa.exe
876 12 C:\Program Files\Symantec\ecvxz.exe
828 10 C:\WINDOWS\system32\bsaost.exe
[解决办法]