|
发表于 2009-6-27 09:21:06
|
显示全部楼层
Func _Cpu_Usage($init = 0)
;~ if $cpu_halt = false then
Local $liOldIdleTime = 0
Local $liOldSystemTime = 0
$SYSTEM_BASIC_INFORMATION = DllStructCreate("int;uint;uint;uint;uint;uint;uint;ptr;ptr;uint;byte;byte;short")
$status = DllCall("ntdll.dll", "int", "NtQuerySystemInformation", "int", 0, _
"ptr", DllStructGetPtr($SYSTEM_BASIC_INFORMATION), _
"int", DllStructGetSize($SYSTEM_BASIC_INFORMATION), _
"int", 0)
ConsoleWrite("ispred -1" & @CRLF)
If $status[0]Then Return -1
ConsoleWrite("ispred while" & @CRLF)
While 1
$SYSTEM_PERFORMANCE_INFORMATION = DllStructCreate("int64;int[76]")
$SYSTEM_TIME_INFORMATION = DllStructCreate("int64;int64;int64;uint;int")
$status = DllCall("ntdll.dll", "int", "NtQuerySystemInformation", "int", 3, _
"ptr", DllStructGetPtr($SYSTEM_TIME_INFORMATION), _
"int", DllStructGetSize($SYSTEM_TIME_INFORMATION), _
"int", 0)
ConsoleWrite("ispred -2" & @CRLF)
If $status[0]Then Return -2
$status = DllCall("ntdll.dll", "int", "NtQuerySystemInformation", "int", 2, _
"ptr", DllStructGetPtr($SYSTEM_PERFORMANCE_INFORMATION), _
"int", DllStructGetSize($SYSTEM_PERFORMANCE_INFORMATION), _
"int", 0)
ConsoleWrite("ispred -3" & @CRLF)
If $status[0]Then Return -3
If $init = 1 Or $liOldIdleTime = 0 Then
$liOldIdleTime = DllStructGetData($SYSTEM_PERFORMANCE_INFORMATION, 1)
$liOldSystemTime = DllStructGetData($SYSTEM_TIME_INFORMATION, 2)
ConsoleWrite("sleep" & @CRLF)
;~ $cpu_halt = true
Sleep(50)
;~ $timer5 = TimerInit()
if $init = 1 Then
Return -99
;~ ExitLoop
EndIf
Else
ConsoleWrite("konacno" & @CRLF)
;~ if TimerDiff($timer5) >= 1000 then
$dbIdleTime = DllStructGetData($SYSTEM_PERFORMANCE_INFORMATION, 1) - $liOldIdleTime
$dbSystemTime = DllStructGetData($SYSTEM_TIME_INFORMATION, 2) - $liOldSystemTime
$liOldIdleTime = DllStructGetData($SYSTEM_PERFORMANCE_INFORMATION, 1)
$liOldSystemTime = DllStructGetData($SYSTEM_TIME_INFORMATION, 2)
$dbIdleTime = $dbIdleTime / $dbSystemTime
$dbIdleTime = 100.0 - $dbIdleTime * 100.0 / DllStructGetData($SYSTEM_BASIC_INFORMATION, 11) + 0.5
Return $dbIdleTime
;~ EndIf
EndIf
$SYSTEM_PERFORMANCE_INFORMATION = 0
$SYSTEM_TIME_INFORMATION = 0
ConsoleWrite("ponovo while" & @CRLF)
WEnd
;~ endif
EndFunc ;==>CurrentCPU |
|