gsass1 / NTop

💻 htop-like system-monitor for Windows with Vi-keybindings.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Values don't match Windows task manager?

ScottBeeson opened this issue · comments

I've tried this on a couple PCs at this point, one Win 11 and one 10. They both have similar results. NTop reports significantly lower utilization than Windows Task Manager for any given process (I've tested with a browser on a CPU load test site, Unity apps, etc).

The weird thing is that I only found NTop because I was trying to do this with PowerShell and it was inaccurate. The inaccuracies for Get-Process and Get-Counter seem to be similar to NTop. Again, I've tried this on multiple systems. What is going on?

Here's an example: https://imgur.com/gyApdCS

Task Manager calculates CPU usage for processes by also including the child processes in the final value, if I'm not mistaken. NTop doesn't do that (yet). Task Manager also likely uses a different API and a different schedule for sampling data which should explain further discrepancies in the data.

I noticed the child-process issue, but if you look at my screenshot you'll see that's not the problem.

It's very frustrating that it's different. One of them must be "wrong", right?

I'm writing a book about Powershell and I have been looking into this problem. This information is very hard to gather using Windows native commands. I had hoped to be able to refer readers to ntop to solve this problem, but I am finding large discrepancies between task manager and ntop. I get that there can be differences in the sampling, but it seems like ntop is very conservative and almost always under reports CPU utilization. I'm on Windows 11. Hope this information helps.
image

@grepnick NTop calculates its "own" CPU utilization in https://github.com/gsass1/NTop/blob/master/ntop.c#L756 and does not use any Windows APIs for directly grabbing these values. My algorithm is not very sophisticated, but the precision may be improved if you tweak the "sampling rate" as defined in https://github.com/gsass1/NTop/blob/master/ntop.c#L907

My own assumption is that Task Manager uses some kind of Windows-internal API that calculates CPU usage on the kernel level with much better precision.

Update @gsass1
At first glance, it seems that Ntop appears underestimate CPU utilization. However, in my testing I found that Windows Task Manager actually seems to greatly overestimate CPU utilization. In fact, Ntop CPU utilization is probably much closer to actual CPU usage than Windows Task Manager.

You can see this phenomenon by comparing the Windows Performance Monitor CPU utilization to Task Manager.
image

image

As you can see from the Windows Performance Monitor, the average CPU utilization is 6% (roughly the same at Ntop). At the same time, Windows Task manager shows CPU usage as about 70%.

image

While the Task Manager was consistently reporting 70% CPU utilization, CIM performance counters show the total overall CPU usage at 5%.

PS C:\> Get-CimInstance Win32_PerfFormattedData_PerfOS_Processor | Select Name, PercentProcessorTime

Name   PercentProcessorTime
----   --------------------
0                         8
1                         8
2                         2
3                         8
4                         8
5                         2
6                         8
7                         2
_Total                    5

NTop shows incorrect CPU load data - CPUz Stress test 16 threads 5800h - only 77% used.
Снимок экрана 2023-09-25 234445

I think it's time we switch from calculating our own usage values to just using Windows' performance counter API.