xxxserxxx / gotop

A terminal based graphical activity monitor inspired by gtop and vtop
Other
2.76k stars 140 forks source link

Inconsistent CPU when compared to htop #17

Open xxxserxxx opened 4 years ago

xxxserxxx commented 4 years ago

Required information:

I've seen inconsistent CPU usage from gotop and htop. For the gotop process, CPU usage ranges from 7 to 15% continuously on htop, but gotop reports around 3%, continuously.

I would guess this is because htop shows the total CPU usage in all CPUs and gotop is showing the CPU usage divided by the number of cores. Is this correct? Is this the intended behavior? Or should it follow htop style and go to 400% in a 4 core CPU?

screenshot 2019-02-05 15 11 24

xxxserxxx commented 4 years ago

Yah, gotop divides the CPU usage by the number of cores to show overall CPU usage which differs from the way htop/top works. I hadn't noticed that descrepency before so thanks for pointing that out. Is one way better than the other? If people want per-core CPU usage then maybe we could add a cli option to allow choosing between the two.

xxxserxxx commented 4 years ago

afaik, it's common that cores go to 100%, CPU goes to 100%*nr of cores. So a process using 150% CPU in a quad-core will, in fact, be using one core at 100% and another at 50% - or any other combination of it.

Good reference: https://unix.stackexchange.com/questions/145247/understanding-cpu-while-running-top-command

xxxserxxx commented 4 years ago

It is common and it's used by top/htop, but other resource monitors use gotop's method too like ksysguard. I think it's mostly preference. I personally prefer displaying overall % CPU and I think the default should stay that way, but if we want to add an option or keybind to switch between the two then that sounds good to me!

xxxserxxx commented 4 years ago

I'd really like to have an option to switch between both ways of showing CPU usage.

xxxserxxx commented 4 years ago

It seems to me there is more discrepancy than can be explained by the above reason.

I have a VMBox with windows inside running on OSX. gotop showed me max 10% on the VirtualBoxVM provess (mostly around 5%). That would be approx 1 core on my 12 core machine. htop easily goes up to 300-500% (3-5 cores).

Any idea what that could be?

Very nice tool none the less! I love it!

xxxserxxx commented 4 years ago

@tehsphinx So assuming htop is correctly reporting that information, that discrepancy sounds like a gotop bug and must have something to do with the way we're gather CPU usage information. I'm not immediately sure what that could be, since we're just running ps, so feel free to create an issue for that. I'd also recommend cross referencing the information given with some other resource monitors like top and ksysguard to make sure it's a gotop error.

xxxserxxx commented 4 years ago

@cjbassi Since this is currently hard to compare (because of the different measuring mentioned in this issue) I'm going wait for the suggested option. Keeping an eye out in the meantime.

xxxserxxx commented 4 years ago

@suroa FYI

xxxserxxx commented 4 years ago

I see two topics in this ticket.

  1. Is gotop's CPU usage correct? There's some indication that it might, in some environments, at least. Correcting this will require building a test, because eyeballing against a different top tool isn't going to cut it.
  2. Provide alternate views for CPU data. I see three possible values:
    1. AVG over all CPU processing power in the machine (already implemented with AVG)
    2. Per-core view. Currently, the labels imply a CPU view when it's really showing cores. This is likely just a label change.
    3. Per-CPU view. This is the sum of the core usage percents per each CPU.

I'm not interested in displaying paradoxical values > 100%. Not only is it a very silly thing, to know how much CPU is really being used, the user still has to do mental math to know what the max value is. Therefore, given:

Then:

2.1 - ∑C/Δt (actually, it should be a rolling average over a time window, so slightly more complex than that) 2.2 - ∀p, ∑Cp 2.3 - ∀p, (∑Cp) / (|Cp|)

So: I'm short-cutting this ticket to the first issue; are the CPU usages reported by gotop correct? The other one, I'll create a feature request for.

dkwo commented 3 years ago

I'd also like to report cpu usage different from htop, and inconsistent whitin gotop itself. 1621005405