找回密码
 加入
搜索
查看: 11521|回复: 36

如何获得CPU使用率和内存占用率?

 火... [复制链接]
发表于 2010-1-25 09:44:12 | 显示全部楼层 |阅读模式
本帖最后由 kemyliu 于 2010-1-25 17:16 编辑

请各位达人有谁知道Autoit有什么UDF或函数可以获得computer CPU使用率和内存占用率。

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-1-25 10:36:21 | 显示全部楼层
 楼主| 发表于 2010-1-25 13:30:32 | 显示全部楼层
MemGetStats(),查询内存的可以用这个函数,那再问高手CPU利用率用什么可以得到啊
发表于 2010-1-25 13:37:49 | 显示全部楼层
发表于 2010-1-25 13:37:59 | 显示全部楼层
发表于 2010-1-25 14:13:02 | 显示全部楼层
freesky的博客里有,去看看吧
发表于 2010-1-25 16:38:17 | 显示全部楼层
小小玩一下
#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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×

评分

参与人数 3金钱 +71 贡献 +20 收起 理由
nxbigdaddy + 1
pusofalse + 50 + 20 学习了。
afan + 20

查看全部评分

发表于 2010-1-25 16:42:41 | 显示全部楼层
小小玩一下
gapkiller 发表于 2010-1-25 16:38



    KAO,帅!
发表于 2010-1-25 16:50:56 | 显示全部楼层
回复 7# gapkiller

太帅了,不服不行啊,呵呵
发表于 2010-1-25 16:54:22 | 显示全部楼层
小小玩一下
gapkiller 发表于 2010-1-25 16:38



    - -!原来这东西....这么搞的 =- =
 楼主| 发表于 2010-1-25 17:16:15 | 显示全部楼层
非常感谢楼上的各位!
发表于 2010-1-25 17:54:27 | 显示全部楼层
感谢LS......
发表于 2010-1-25 18:03:37 | 显示全部楼层
28个字母俺完全都认识,组合在一起么。。。

这个.....

有困难..找民警。
发表于 2010-1-25 18:27:05 | 显示全部楼层
小小玩一下
gapkiller 发表于 2010-1-25 16:38



    非常的不错,很好的例子!
发表于 2010-1-25 19:05:53 | 显示全部楼层
太帅了,不服不行啊,呵呵
llztt 发表于 2010-1-25 16:50



不顶不行!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-20 17:01 , Processed in 0.092570 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表