【发布时间】:2017-11-15 04:11:52
【问题描述】:
我想查找单个进程的性能,例如“SqlServer”
我应该写哪些命令来找出两件事:
- SqlServer 使用的 RAM
- SqlServer 使用的 CPU
我找到了很多列出所有进程的解决方案,但我只想获得 1 个,即 SqlServer。
【问题讨论】:
标签: powershell
我想查找单个进程的性能,例如“SqlServer”
我应该写哪些命令来找出两件事:
我找到了很多列出所有进程的解决方案,但我只想获得 1 个,即 SqlServer。
【问题讨论】:
标签: powershell
获取SQL server进程信息的命令:
Get-Process SQLSERVR
获取任何以 S 开头的进程的信息的命令:
Get-Process S*
获取 SQLServer 进程正在使用的虚拟内存量:
Get-Process SQLSERVR | Select-Object VM
获取进程工作集的大小,以千字节为单位:
Get-Process SQLSERVR | Select-Object WS
要获取进程正在使用的可分页内存量,以千字节为单位:
Get-Process SQLSERVR - Select-Object PM
要获取进程正在使用的不可分页内存量,以千字节为单位:
Get-Process SQLSERVR - Select-Object NPM
获取CPU(进程在所有处理器上使用的处理器时间,以秒为单位):
Get-process SQLSERVR | Select-Object CPU
要更好地理解 Get-Process cmdlet,请查看文档 on technet here.
【讨论】:
关于 CPU,我的工作方式如下:
# To get the PID of the process (this will give you the first occurrance if multiple matches)
$proc_pid = (get-process "slack").Id[0]
# To match the CPU usage to for example Process Explorer you need to divide by the number of cores
$cpu_cores = (Get-WMIObject Win32_ComputerSystem).NumberOfLogicalProcessors
# This is to find the exact counter path, as you might have multiple processes with the same name
$proc_path = ((Get-Counter "\Process(*)\ID Process").CounterSamples | ? {$_.RawValue -eq $proc_pid}).Path
# We now get the CPU percentage
$prod_percentage_cpu = [Math]::Round(((Get-Counter ($proc_path -replace "\\id process$","\% Processor Time")).CounterSamples.CookedValue) / $cpu_cores)
【讨论】: