performancepowershellazure-sql-databasecpu-usagetaskmanager

PowerShell :: Get-Counter shows wrong CPU usage


Following the official Microsoft documentation I found a command that should print the CPU usage:

Get-Counter -Counter "\Processor(_Total)\% Processor Time" -Continuous

The problem is that it prints the CPU usage with a good 5-10% of discrepancy (click on the GIF to have a better view):

enter image description here

This is particularly bad because Microsoft suggests the command Get-Counter as the official way for DTU calculation before migrating to Azure SQL DB.


Solution

  • Even if I run:

    typeperf "\Processor(_Total)\% Processor Time"
    

    There is always discrepancy in the CPU calculation.

    Get-Counter Works as intended, there will always be discrepancy.

    You can reduce such discrepancy if you go to Task Manager > View > Update Speed > High

    enter image description here

    This way the refresh rate will be higher and the results of Get-Counter closer to what you see in the Task Manager. But don't expect to be the same.