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):
This is particularly bad because Microsoft suggests the command Get-Counter
as the official way for DTU calculation before migrating to Azure SQL DB.
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
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.