8

I want to find performance of single process, as example "SqlServer"

Which commands I should write to find out 2 things:

  1. RAM utilized by SqlServer
  2. CPU utilized by SqlServer

I found lot of solutions listing all processes, but I want to get only 1 i.e. SqlServer.

1

2 Answers 2

10

The command to get SQL server process information:

Get-Process SQLSERVR

The command to get information for any process that starts with S:

Get-Process S*

To get the amount of virtual memory that the SQLServer process is using:

Get-Process SQLSERVR | Select-Object VM

To get the size of the working set of the process, in kilobytes:

Get-Process SQLSERVR | Select-Object WS 

To get the amount of pageable memory that the process is using, in kilobytes:

Get-Process SQLSERVR - Select-Object PM

To get the amount of non-pageable memory that the process is using, in kilobytes:

Get-Process SQLSERVR - Select-Object NPM

To get CPU (The amount of processor time that the process has used on all processors, in seconds):

Get-process SQLSERVR | Select-Object CPU

To better understand the Get-Process cmdlet, check out the documentation on technet here.

6
  • Thanks mate! but why VM is showing in minus (-). and Does VM means RAM?
    – AK47
    Jun 11, 2014 at 6:24
  • I have gone through that link, but not able to understand that how VM is showing negative values?
    – AK47
    Jun 11, 2014 at 6:27
  • I am unsure, as I do not get negative values. What command are you using?
    – D3vtr0n
    Jun 11, 2014 at 6:33
  • Ok, now able to get correct value. Out of VM, WS .... which values is of RAM? which is show in task manager as Memory (Private working Set).
    – AK47
    Jun 11, 2014 at 6:37
  • 1
    @AK47 just came across this post; the reason the values may be negative is because the value is larger than what INT can hold. (which I think is 4gb)
    – mbourgon
    Jul 16, 2015 at 19:14
3

About the CPU I got this working the following way:

# 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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.