如何获得CPU使用率和内存占用率?
本帖最后由 kemyliu 于 2010-1-25 17:16 编辑请各位达人有谁知道Autoit有什么UDF或函数可以获得computer CPU使用率和内存占用率。 http://www.autoitx.com/forum.php?mod=viewthread&tid=2292&extra=page%3D3
for your information MemGetStats(),查询内存的可以用这个函数,那再问高手CPU利用率用什么可以得到啊 http://bbs.wglm.net/read.php?tid=106264
http://bbs.wglm.net/att9527/Mon_1001/44_12_4cdd02c9bb9c3db.jpg http://www.autoitx.com/forum.php?mod=viewthread&tid=9562&highlight=cpu freesky的博客里有,去看看吧 小小玩一下
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
Global $IDLETIME, $KERNELTIME, $USERTIME
Global $StartIdle, $StartKernel, $StartUser
Global $EndIdle, $EndKernel, $EndUser
Global $Timer
$IDLETIME = DllStructCreate("dword;dword")
$KERNELTIME = DllStructCreate("dword;dword")
$USERTIME = DllStructCreate("dword;dword")
Opt("GUIOnEventMode",1)
$hGUI = GUICreate("CPUmon", 200, 100, @DesktopWidth-210, @DesktopHeight-140, 0x80800000);, $WS_EX_TOPMOST)
GUISetBkColor(0x000000)
GUISetOnEvent(-3,"Quit")
GUICtrlCreateGraphic(0,0,200,100)
GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x008040)
For $y=25 To 75 Step 25
GUICtrlSetGraphic(-1, $GUI_GR_MOVE,0,$y)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, 200, $y)
Next
For $x=25 To 175 Step 25
GUICtrlSetGraphic(-1, $GUI_GR_MOVE, $x, 0)
GUICtrlSetGraphic(-1, $GUI_GR_LINE, $x, 100)
Next
$gr = GUICtrlCreateGraphic(0,0,210,100)
$lb=GUICtrlCreateLabel("",0,0,25,25)
GUICtrlSetColor(-1,0x00FF00)
GUISetState()
GUICtrlSetGraphic($gr, $GUI_GR_COLOR, 0x00FF00)
$x=0
$y=0
$dx=200
$dy=100
GUICtrlSetGraphic($gr, $GUI_GR_MOVE,$dx,$dy)
While 1
$rCPU = _TimerProc()
GUICtrlSetData($lb,$rCPU&"%")
$dx += 2
$dy = 100-$rCPU
;MsgBox(0,"",$dy)
GUICtrlSetGraphic($gr, $GUI_GR_LINE, $dx, $dy)
GUICtrlSetGraphic($gr, $GUI_GR_REFRESH)
$x -= 2
GUICtrlSetPos($gr, $x, $y)
Sleep(1000)
WEnd
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
Func _TimerProc()
_GetSysTime($EndIdle, $EndKernel, $EndUser)
$res = _CPUCalc()
_GetSysTime($StartIdle, $StartKernel, $StartUser)
Return $res
EndFunc
Func _GetSysTime(ByRef $sIdle, ByRef $sKernel, ByRef $sUser)
DllCall("kernel32.dll", "int", "GetSystemTimes", "ptr", DllStructGetPtr($IDLETIME), _
"ptr", DllStructGetPtr($KERNELTIME), _
"ptr", DllStructGetPtr($USERTIME))
$sIdle = DllStructGetData($IDLETIME, 1)
$sKernel = DllStructGetData($KERNELTIME, 1)
$sUser = DllStructGetData($USERTIME, 1)
EndFunc ;==>_GetSysTime
Func _CPUCalc()
Local $iSystemTime, $iTotal, $iCalcIdle, $iCalcKernel, $iCalcUser
$iCalcIdle = ($EndIdle - $StartIdle)
$iCalcKernel = ($EndKernel - $StartKernel)
$iCalcUser = ($EndUser - $StartUser)
$iSystemTime = ($iCalcKernel + $iCalcUser)
$iTotal = Int(($iSystemTime - $iCalcIdle) * (100 / $iSystemTime))
Return $iTotal
EndFunc
func Quit()
Exit
EndFunc
小小玩一下
gapkiller 发表于 2010-1-25 16:38 http://www.autoitx.com/images/common/back.gif
KAO,帅! 回复 7# gapkiller
太帅了,不服不行啊,呵呵 小小玩一下
gapkiller 发表于 2010-1-25 16:38 http://www.autoitx.com/images/common/back.gif
- -!原来这东西....这么搞的 =- = 非常感谢楼上的各位! 感谢LS...... 28个字母俺完全都认识,组合在一起么。。。
这个.....
有困难..找民警。 小小玩一下
gapkiller 发表于 2010-1-25 16:38 http://www.autoitx.com/images/common/back.gif
非常的不错,很好的例子!
太帅了,不服不行啊,呵呵
llztt 发表于 2010-1-25 16:50 http://www.autoitx.com/images/common/back.gif
不顶不行!