我想找到单个进程的性能,例如“SqlServer”
我应该写出哪些命令来找出两件事:
我发现很多解决方案列出了所有进程,但我想只获得1个,即SqlServer。
答案 0 :(得分:8)
获取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.
答案 1 :(得分:3)
关于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)