是否有一个命令行实用程序来显示WS专用字节?

时间:2012-12-14 12:42:28

标签: windows memory

在Process Explorer术语中,它是 WS Private Bytes ,而在任务管理器术语中,它是私有工作集

我希望命令行实用程序在给定进程名称的情况下显示此信息。

修改

PowerShell脚本也可以。

1 个答案:

答案 0 :(得分:7)

PowerShell中,您可以使用:

<强> [编辑]

function ProcessInfo
{
    param
    ([String]$processName)

    $workingSet = get-counter -counter "\Process($processName)\Working Set - Private" | select -expandproperty countersamples | select cookedvalue
    $privateBytes = get-counter -counter "\Process($processName)\Private Bytes" | select -expandproperty countersamples | select cookedvalue

    get-process $processName | select `
        name, `
        @{Name="Private Working Set"; Expression = {$workingSet.CookedValue}},`
        @{Name="WS Private Bytes"; Expression = {$privateBytes.CookedValue}}
}

ProcessInfo("winrar")

<强> [EDIT2]

这是一个改进版本,它将进程ID作为参数。

function GetProcessInfoById
{
    param
    ([int]$processId)

    Get-WmiObject -class Win32_PerfFormattedData_PerfProc_Process | where{$_.idprocess -eq $processId} | select `
    @{Name="Process Id"; Expression = {$_.idprocess}},`
    @{Name="Counter Name"; Expression = {$_.name}},`
    @{Name="Private Working Set"; Expression = {$_.workingSetPrivate / 1kb}}        
}

GetProcessInfoById 380

这是一个将进程名称作为参数的版本。这可能会返回多个值(每个流程实例一个),您可以按Process Id的值来识别流程。

function GetProcessInfoByName
{
    param
    ([string]$processName)

    Get-WmiObject -class Win32_PerfFormattedData_PerfProc_Process | where{$_.name -like $processName+"*"} | select `
    @{Name="Process Id"; Expression = {$_.idprocess}},`
    @{Name="Counter Name"; Expression = {$_.name}},`
    @{Name="Private Working Set"; Expression = {$_.workingSetPrivate / 1kb}}
}

GetProcessInfoByName svchost