Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Values don't match Windows task manager? #51

Open
ScottBeeson opened this issue Sep 8, 2022 · 7 comments
Open

Values don't match Windows task manager? #51

ScottBeeson opened this issue Sep 8, 2022 · 7 comments

Comments

@ScottBeeson
Copy link

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

@gsass1
Copy link
Owner

gsass1 commented Sep 8, 2022

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.

@ScottBeeson
Copy link
Author

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?

@grepnick
Copy link

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

@gsass1
Copy link
Owner

gsass1 commented Jun 1, 2023

@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.

@grepnick
Copy link

grepnick commented Jun 3, 2023

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

@Ilya87
Copy link

Ilya87 commented Sep 25, 2023

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

@gsass1
Copy link
Owner

gsass1 commented Oct 18, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants