stsdc / monitor

Manage processes and monitor system resources.
GNU General Public License v3.0
321 stars 44 forks source link

101% CPU utilization #345

Open davidak opened 1 year ago

davidak commented 1 year ago

Screenshot from 2023-02-16 16-31-03

The number seem wrong. See the individual cores!

It cycles between 99%, 100% and 101%.


Monitor 0.15.1 NixOS 22.11.2568.c43f676c938

stsdc commented 1 year ago

Here is how load is calculated: https://github.com/stsdc/monitor/blob/0dcfffe7714aebe9498ef70410bdb1c52fa25f44/src/Resources/CPU.vala#L112-L126

And here is how percentage is being calculated: https://github.com/stsdc/monitor/blob/0dcfffe7714aebe9498ef70410bdb1c52fa25f44/src/Resources/CPU.vala#L24-L28

Might be a rounding issue?

davidak commented 1 year ago

Rounding issue sounds likely.

Do you need more information to solve it, like the cpu.user + cpu.sys + cpu.nice + cpu.irq + cpu.softirq from top?

stsdc commented 1 year ago

Would be nice to have, just in case of.

davidak commented 1 year ago

top is running with top -1 -d 0.1 and monitor updates every 1s. It could be an issue that they are not in sync.

Here are 3 screenshots:

Screenshot from 2023-02-20 03-26-22 Screenshot from 2023-02-20 03-26-09 Screenshot from 2023-02-20 03-24-15

Here is a video. Maybe it helps to check it frame-by-frame with like VLC: https://www.youtube.com/watch?v=sW3jGuMZOgI It might stutter a bit since the system was 100% used while also recording.

stsdc commented 1 year ago

obraz

** (com.github.stsdc.monitor:68837): DEBUG: 21:25:26.790: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:26.791: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:28.701: CPU.vala:26: 0,999381, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:28.702: CPU.vala:26: 0,999381, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:30.812: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:30.812: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:32.722: CPU.vala:26: 0,999379, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:32.723: CPU.vala:26: 0,999379, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:34.767: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:34.767: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:36.751: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:36.751: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:38.809: CPU.vala:26: 0,999375, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:38.809: CPU.vala:26: 0,999375, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:40.712: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:40.713: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:42.709: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:42.710: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:44.725: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:44.726: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:46.710: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:46.710: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:48.683: CPU.vala:26: 0,999370, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:48.684: CPU.vala:26: 0,999370, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:50.710: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:50.710: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:52.727: CPU.vala:26: 1,000000, 100
** (com.github.stsdc.monitor:68837): DEBUG: 21:25:52.729: CPU.vala:26: 1,000000, 100

Can't reproduce on my machine :(

I'm debugging it with this log line:

    public int percentage {
        get {
            debug ("%f, %d", load, ((int) (Math.round (load * 100))));
            return (int) (Math.round (load * 100));
        }
    }

I have prepared a branch for this issue: https://github.com/stsdc/monitor/tree/101-percent You may checkout and build.

davidak commented 1 year ago

I tried to build from the commit, but it fails.

building '/nix/store/z5c5afwm2ic9zfypvlk49b8c3v7fczdm-monitor-0.15.1.drv'...
unpacking sources
unpacking source archive /nix/store/7gvkvd8c082niqkkl8dscqg5imgjk5a0-source
source root is source
patching sources
patching script interpreter paths in meson/post_install.py
meson/post_install.py: interpreter directive changed from "#!/usr/bin/env python3" to "/nix/store/0pyymzxf7n0fzpaqnvwv92ab72v3jq8d-python3-3.10.9/bin/python3"
configuring
meson flags: --buildtype=plain         --libdir=/nix/store/ckbp5xhv63amjbswv6a1wvjaisb8fnqr-monitor-0.15.1/lib --libexecdir=/nix/store/ckbp5xhv63amjbswv6a1wvjaisb8fnqr-monitor-0.15.1/libexec         --bindir=/nix/store/ckbp5xhv63amjbswv6a1wvjaisb8fnqr-monitor-0.15.1/bin --sbindir=/nix/store/ckbp5xhv63amjbswv6a1wvjaisb8fnqr-monitor-0.15.1/sbin         --includedir=/nix/store/ckbp5xhv63amjbswv6a1wvjaisb8fnqr-monitor-0.15.1/include         --mandir=/nix/store/ckbp5xhv63amjbswv6a1wvjaisb8fnqr-monitor-0.15.1/share/man --infodir=/nix/store/ckbp5xhv63amjbswv6a1wvjaisb8fnqr-monitor-0.15.1/share/info         --localedir=/nix/store/ckbp5xhv63amjbswv6a1wvjaisb8fnqr-monitor-0.15.1/share/locale         -Dauto_features=enabled         -Dwrap_mode=nodownload         --prefix=/nix/store/ckbp5xhv63amjbswv6a1wvjaisb8fnqr-monitor-0.15.1 -Dindicator-wingpanel=enabled 
The Meson build system
Version: 1.0.0
Source dir: /build/source
Build dir: /build/source/build
Build type: native build
Project name: com.github.stsdc.monitor
Project version: 0.15.1
C compiler for the host machine: gcc (gcc 12.2.0 "gcc (GCC) 12.2.0")
C linker for the host machine: gcc ld.bfd 2.40
Vala compiler for the host machine: valac (valac 0.56.3)
Host machine cpu family: x86_64
Host machine cpu: x86_64
Program sassc found: YES (/nix/store/crcqig751q842br0rrivir6fv74yd9fq-sassc-3.6.2/bin/sassc)

meson.build:20:0: ERROR: Subproject exists but has no meson.build file

Same error also at previous commit (7786ca34d6425068e7275468497109f6758e3f29).

Package source changed with:

{ config, pkgs, lib, ... }:

let
  unstable = import <nixos-unstable> { config.allowUnfree = true;
  overlays = [ (
    self: super:
      {
        monitor = super.monitor.overrideAttrs (old: {
          src = super.fetchFromGitHub {
            owner = "stsdc";
            repo = "monitor";
            # for debugging https://github.com/stsdc/monitor/commit/9475ebfdc569020886686cca5991a59458c204bb
            rev = "9475ebf";
            hash = "sha256-mdle+i80WoajZ9GHxsSJbPcuKcAi2Vm3Uf3xjbFQLMA=";
          };
        });
      })
    ];
  };

in
{

...

  environment.systemPackages = with pkgs; [
    unstable.monitor
  ];

}
stsdc commented 1 year ago

I'm not familiar with NixOS, can't help with packaging. But maybe you can just clone the repo and try to build from sources?

davidak commented 1 year ago

The issue was that the repo was not cloned with submodules.

https://gitlab.gnome.org/GNOME/glib/-/issues/2716

davidak commented 1 year ago

Here are the results:

You should be able to reproduce the issue with: stress-ng --cpu 8 (number of cpu cores)

** (com.github.stsdc.monitor:1544884): DEBUG: 13:27:49.249: CPU.vala:120: us 70418957, sy 8669191, ni 102484, id 108252248
** (com.github.stsdc.monitor:1544884): DEBUG: 13:27:49.249: CPU.vala:125: diff_used: 1576.000000, diff_total: 1568.000000
** (com.github.stsdc.monitor:1544884): DEBUG: 13:27:50.150: CPU.vala:26: 1.005102, 101
** (com.github.stsdc.monitor:1544884): DEBUG: 13:27:50.150: CPU.vala:26: 1.005102, 101

Video: https://youtu.be/kwRwTUMl5mY