Wieviel Arbeitsspeicher belegt ein Programm?

  • Ich habe es als 32bit kompiliert und es bringt wie gesagt garkeine Werte.

    Edit: Ok jetzt gehts, wenn man calc.exe vorher aufruft. Mein Fehler. Allerdings stimmt keiner dieser Werte auch nur annähernd mit dem überein den der Taskmanager anzeigt.

    Andy hat mir ein Schnitzel gebacken aber da war ein Raupi drauf und bevor Oscar das Bugfixen konnte kam Alina und gab mir ein AspirinJunkie.

  • Ja das war mein Fehler habs oben noch editiert gehabt. Allerdings stimmt keiner der angezeigten Werte auch nur annähernd mit dem überein den der Taskmanager anzeigt. Der Taskmanager sagt 5005 das was am nächsten dran kommt ist PeakPagefielUsage mi 6448


    Edit: Hab nun das von UEZ und das von AspirinJunkie untern Win 7 x86 getestet beides mit dem selben Ergebniss wie unter Win 7 x64.

    AspirinJunkie keine Ahnung warum es bei dir geht. Bei mir geht es auf vier verschiedenen Win 7 x64 Rechnern und einem Win 7 x86 Rechner nicht.

    Andy hat mir ein Schnitzel gebacken aber da war ein Raupi drauf und bevor Oscar das Bugfixen konnte kam Alina und gab mir ein AspirinJunkie.

    2 Mal editiert, zuletzt von chip (24. Februar 2010 um 13:55)

  • Hier der verbesserte Code bzgl.>= Win7:

    Spoiler anzeigen
    [autoit]


    #AutoIt3Wrapper_UseX64=y
    #AutoIt3Wrapper_Change2CUI=y
    Global $PID
    Global Const $Process_All_Access = 0x1F0FFF

    [/autoit] [autoit][/autoit] [autoit]

    $PID = ProcessExists(@AutoItPID)
    If $PID = 0 Then
    ConsoleWrite(@CRLF & "ERROR! Process " & $PID & " not found! Aborting..." & @CRLF)
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    $ProcHandle = DllCall("kernel32.dll", "hwnd", "OpenProcess", "dword", $Process_All_Access, "int", False, "dword", $PID)
    $ProcHandle = $ProcHandle[0]

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0, "PrivateUsage Size", Round(_ProcessGetMem($ProcHandle) / 1024, 0) & " kb")

    [/autoit] [autoit][/autoit] [autoit]

    DllCall("psapi.dll", "int", "CloseHandle", "hwnd", $ProcHandle)
    DllCall("kernel32.dll", "int", "CloseHandle", "int", $ProcHandle)
    Exit

    [/autoit] [autoit][/autoit] [autoit]

    Func _ProcessGetMem($ProcessHandle) ;get physical memory of the process -> http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
    Local $structPROCESS_MEMORY_COUNTERS, $structPROCESS_MEMORY_COUNTERS_EX, $nSize, $aRet
    If @OSBuild < 7600 Then
    $structPROCESS_MEMORY_COUNTERS = DllStructCreate("dword cb; dword PageFaultCount; dword_ptr PeakWorkingSetSize; ulong_ptr WorkingSetSize; " & _
    "dword_ptr QuotaPeakPagedPoolUsage; dword_ptr QuotaPagedPoolUsage; dword_ptr QuotaPeakNonPagedPoolUsage; " & _
    "dword_ptr QuotaNonPagePoolUsage; dword_ptr PagefileUsage; dword_ptr PeakPagefileUsage") ;http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
    $nSize = DllStructGetSize($structPROCESS_MEMORY_COUNTERS)
    $aRet = DllCall("psapi.dll", "int", "GetProcessMemoryInfo", "hwnd", $ProcessHandle, "ptr", DllStructGetPtr($structPROCESS_MEMORY_COUNTERS), "dword", $nSize) ;call GetProcessMemoryInfo
    If $aRet[0] = 0 Then
    ConsoleWrite("(" & @ScriptLineNumber & ") : = Error in GetProcessMemoryInfo call" & @LF)
    SetError(1, 0, $aRet[0])
    EndIf
    Return DllStructGetData($structPROCESS_MEMORY_COUNTERS, "WorkingSetSize")
    Else
    $structPROCESS_MEMORY_COUNTERS_EX = DllStructCreate("dword cb; dword PageFaultCount; dword_ptr PeakWorkingSetSize; dword_ptr WorkingSetSize; " & _
    "dword_ptr QuotaPeakPagedPoolUsage; dword_ptr QuotaPagedPoolUsage; dword_ptr QuotaPeakNonPagedPoolUsage; " & _
    "dword_ptr QuotaNonPagePoolUsage; dword_ptr PagefileUsage; dword_ptr PeakPagefileUsage; " & _
    "ulong_ptr PrivateUsage") ;http://msdn.microsoft.com/en-us/library/…28VS.85%29.aspx
    $nSize = DllStructGetSize($structPROCESS_MEMORY_COUNTERS_EX)
    $aRet = DllCall("Kernel32.dll", "int", "K32GetProcessMemoryInfo", "hwnd", $ProcessHandle, "ptr", DllStructGetPtr($structPROCESS_MEMORY_COUNTERS_EX), "dword", $nSize) ;call GetProcessMemoryInfo
    If $aRet[0] = 0 Then
    ConsoleWrite("(" & @ScriptLineNumber & ") : = Error in GetProcessMemoryInfo call" & @LF)
    SetError(1, 0, $aRet[0])
    EndIf
    ConsoleWrite("WorkingSetSize: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "WorkingSetSize"), 0) & @CRLF & _
    "PageFaultCount: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PageFaultCount"), 0) & @CRLF & _
    "PeakWorkingSetSize: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PeakWorkingSetSize"), 0) & @CRLF & _
    "QuotaPeakPagedPoolUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "QuotaPeakPagedPoolUsage"), 0) & @CRLF & _
    "QuotaPagedPoolUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "QuotaPagedPoolUsage"), 0) & @CRLF & _
    "QuotaPeakNonPagedPoolUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "QuotaPeakNonPagedPoolUsage"), 0) & @CRLF & _
    "QuotaNonPagePoolUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "QuotaNonPagePoolUsage"), 0) & @CRLF & _
    "PagefileUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PagefileUsage"), 0) & @CRLF & _
    "PeakPagefileUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PeakPagefileUsage"), 0) & @CRLF & _
    "PrivateUsage: " & Round(DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PrivateUsage"), 0) & @CRLF & @CRLF)
    Return DllStructGetData($structPROCESS_MEMORY_COUNTERS_EX, "PrivateUsage")
    EndIf
    EndFunc ;==>_ProcessGetMem

    [/autoit]


    Nichts desto trotz liefert PrivateUsage nicht den Speicher zurück, der im Taskmanager (WS Private) erscheint!

    Die Suche geht weiter nach einer nicht WMI Lösung...


    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    Einmal editiert, zuletzt von UEZ (28. Februar 2010 um 19:04)

    • Offizieller Beitrag

    Also mit WMI bekomme ich bei mir (Win7, 64Bit) die gleichen Werte, wie im Taskmanager:

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <ListViewConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    $hGui = GUICreate('Process-Memory', 640, 480)
    $hListview = GUICtrlCreateListView('Process|PID|Mem (privat)|Mem (peak)', 5, 5, 630, 440)
    GUICtrlSendMsg($hListview, $LVM_SETCOLUMNWIDTH, 0, 150)
    GUICtrlSendMsg($hListview, $LVM_SETCOLUMNWIDTH, 1, 80)
    GUICtrlSendMsg($hListview, $LVM_SETCOLUMNWIDTH, 2, 120)
    GUICtrlSendMsg($hListview, $LVM_SETCOLUMNWIDTH, 3, 120)
    $hWndListview = GUICtrlGetHandle($hListview)
    $hRefresh = GUICtrlCreateButton('Refresh', 280, 450, 80, 25)
    _RefreshListview()
    GUISetState()
    While True
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    Case $hRefresh
    _RefreshListview()
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _RefreshListview()
    Local $wbemFlagReturnImmediately, $wbemFlagForwardOnly, $colItems, $strComputer
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = 'localhost'
    Local $objWMIService, $colItems, $sItem
    _GUICtrlListView_DeleteAllItems($hWndListview)
    $objWMIService = ObjGet('winmgmts:\\' & $strComputer & '\')
    $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_PerfRawData_PerfProc_Process', 'WQL', $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    For $objItem In $colItems
    $sItem = ''
    $sItem &= $objItem.Name & '|' & $objItem.CreatingProcessID & '|'
    $sItem &= _ByteAutoSize($objItem.WorkingSetPrivate, 0, 2) & '|' & _ByteAutoSize($objItem.WorkingSetPeak, 0, 2)
    GUICtrlCreateListViewItem($sItem, $hListview)
    Next
    EndFunc ;==>_RefreshListview

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ; Function Name: _ByteAutoSize($iSize[, $iRound][, $iFormat][, $bThousands])
    ; Description:: Gibt einen Bytewert in einer bestimmten Einheit zurück
    ; Parameter(s): $iSize = Größe in Byte übergeben
    ; $iRound = Anzahl der Nachkommastellen (0...8)
    ; $iFormat = bestimmt den Rückgabewert
    ; 0 = Automatisch (je nach übergebenen Wert)
    ; 1 = in Byte
    ; 2 = in KByte
    ; 3 = in MByte
    ; 4 = in GByte
    ; $bThousands = Rückgabe mit Tausendertrennzeichen (True/False)
    ; Requirement(s): #include <String.au3>
    ; Author(s): Oscar (http://www.autoit.de)
    ;===============================================================================
    Func _ByteAutoSize($iSize, $iRound = 2, $iFormat = 0, $bThousands = True)
    Local $aSize[4] = [' Byte', ' KByte', ' MByte', ' GByte'], $sReturn
    If $iFormat < 0 Or $iFormat > 4 Then $iFormat = 0
    If $iRound < 0 Or $iRound > 8 Then $iRound = 2
    If Not IsBool($bThousands) Then $bThousands = False
    $iSize = Abs($iSize)
    If $iFormat = 0 Then
    For $i = 30 To 0 Step -10
    If $iSize > (2 ^ $i) Then
    $iFormat = $i / 10 + 1
    ExitLoop
    EndIf
    Next
    EndIf
    If $iFormat = 0 Then $iFormat = 1
    $sReturn = StringFormat('%.' & $iRound & 'f', Round($iSize / (2 ^ (($iFormat - 1) * 10)), $iRound))
    If $bThousands Then $sReturn = _StringAddThousandsSep($sReturn, '.', ',')
    Return $sReturn & $aSize[$iFormat - 1]
    EndFunc ;==>_ByteAutoSize

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _StringAddThousandsSep
    ; Description ...: Returns the original numbered string with the Thousands delimiter inserted.
    ; Syntax.........: _StringAddThousandsSep($sString[, $sThousands = -1[, $sDecimal = -1]])
    ; Parameters ....: $sString - The string to be converted.
    ; $sThousands - Optional: The Thousands delimiter
    ; $sDecimal - Optional: The decimal delimiter
    ; Return values .: Success - The string with Thousands delimiter added.
    ; Author ........: SmOke_N (orignal _StringAddComma
    ; Modified.......: Valik (complete re-write, new function name)
    ; ===============================================================================================================================
    Func _StringAddThousandsSep($sString, $sThousands = -1, $sDecimal = -1)
    Local $sResult = "" ; Force string
    Local $rKey = "HKCU\Control Panel\International"
    If $sDecimal = -1 Then $sDecimal = RegRead($rKey, "sDecimal")
    If $sThousands = -1 Then $sThousands = RegRead($rKey, "sThousand")
    Local $aNumber = StringRegExp($sString, "(\D?\d+)\D?(\d*)", 1) ; This one works for negatives.
    If UBound($aNumber) = 2 Then
    Local $sLeft = $aNumber[0]
    While StringLen($sLeft)
    $sResult = $sThousands & StringRight($sLeft, 3) & $sResult
    $sLeft = StringTrimRight($sLeft, 3)
    WEnd
    $sResult = StringTrimLeft($sResult, StringLen($sThousands)) ; Strip leading thousands separator
    If $aNumber[1] <> "" Then $sResult &= $sDecimal & $aNumber[1]
    EndIf
    Return $sResult
    EndFunc ;==>_StringAddThousandsSep

    [/autoit]
  • Oscar schau mal zwei Posts höher den Link an ;). UEZ will das ja mit DLL machen ohne WMI.

    Andy hat mir ein Schnitzel gebacken aber da war ein Raupi drauf und bevor Oscar das Bugfixen konnte kam Alina und gab mir ein AspirinJunkie.