brndnmtthws / conky

Light-weight system monitor for X, Wayland (sort of), and other things, too
https://conky.cc
GNU General Public License v3.0
7.27k stars 620 forks source link

Incorrect top output (instantaneous vs interval average) #189

Open txtsd opened 8 years ago

txtsd commented 8 years ago

top output seems to show an instantaneous snapshot of CPU usage instead of average CPU usage over the last interval. Here's a screenshot of my compiling p7zip from source. I've used make -j2 and you can see both cores are maxed out in the graph. But the processes don't show two ~50% processes. I did see them intermittently, but that's not how CPU usage output should work. screenshot

Conky version: 1abd253470f5a230b221c2993e54f6137e0ed2b3

evelynharthbrooke commented 8 years ago

@txtsd Try updating your conky. That git commit is older than the current master.

txtsd commented 8 years ago

@KamranMackey None of the commits since then affect this issue and, as expected, the issue still exists.

TheTumultuousUnicornOfDarkness commented 7 years ago

Hi. Tested with a58a6d4, and I have the same issue: when a process use 4 cores of my CPU, the reported CPU usage is 200% for this process instead 400%, but CPU gauges are OK. These incorrect values are problematic.

TheTumultuousUnicornOfDarkness commented 7 years ago

In the same way, when I build something on GNU/Linux: conky The first line of CPU column is ${top cpu 1}.

lasers commented 6 years ago

2 years 8 months passed. Can you determine if you're still having this problem today on 1.10.8 or preferably 1.10.9_pre (git)? The older versions are not trustworthy due to too many changes that can be hard to track. Additionally, I'd like to see configs too so we know what variables are being used... and if we can reproduce this issue easily. Thank you.

TheTumultuousUnicornOfDarkness commented 6 years ago

Yes, of course (installed last Git version, AKA 1.10.8.r80.g3720e96c).

$ conky -v
conky 1.10.9_pre compiled jeu. août  9 00:57:18 CEST 2018 for Linux 4.17.11-1-ck-sandybridge x86_64

Compiled in features:

System config file: /etc/conky/conky.conf
Package library path: /usr/lib/conky

 General:
  * math
  * hddtemp
  * portmon
  * IPv6
  * Curl
  * RSS
  * Weather (METAR)
  * Weather (XOAP)
  * wireless
  * support for IBM/Lenovo notebooks
  * eve-online
  * builtin default configuration
  * old configuration syntax
  * Imlib2
  * OSS mixer support
  * apcupsd
  * iostats
  * ncurses
  * Internationalization support
 X11:
  * Xdamage extension
  * Xinerama extension (virtual display)
  * Xshape extension (click through)
  * XDBE (double buffer extension)
  * Xft
  * ARGB visual
  * Own window

 Music detection:
  * CMUS
  * MPD
  * MOC

 Default values:
  * Netdevice: eth0
  * Local configfile: $HOME/.conkyrc
  * Localedir: /usr/share/locale
  * Maximum netdevices: 64
  * Maximum text size: 16384
  * Size text buffer: 256

Some fresh screenshots: Screenshot 1 Screenshot 2 In my opinion, I still have this problem.

conkyrc:

conky.config = {
    alignment = 'bottom_right',
    gap_x = 5,
    gap_y = 0,
    minimum_width = 240,
    cpu_avg_samples = 2,
    diskio_avg_samples = 2,
    net_avg_samples = 2,
    default_color = 'lightgray',
    draw_borders = false,
    draw_graph_borders = false,
    draw_outline = false,
    draw_shades = false,
    use_xft = true,
    xftalpha = 0.1,
    font = '123:size=8',
    no_buffers = true,
    out_to_console = false,
    out_to_stderr = false,
    extra_newline = false,
    own_window = true,
    own_window_class = 'Conky',
    own_window_type = 'dock',
    own_window_hints = 'undecorated,below,sticky,skip_taskbar,skip_pager',
    own_window_argb_visual = true,
    own_window_argb_value = 100,
    update_interval = 1.0,
    uppercase = false,
    double_buffer = true,
    disable_auto_reload = false,
    top_cpu_separate = true,
    short_units = false,
    lua_load = '/home/xorg/.conky/conky_scripts.lua',
    pad_percents = 5,
    format_human_readable = true,
}

conky.text = [[
### CPU
${font Open Sans:Bold:size=10}${color dodgerblue3}CPU ${hr 2}${color}${font}
i5 2500K @${freq_g}GHz  |  ${hwmon 1 temp 1}°C  |  ${hwmon 2 in 0}V  |  ${hwmon 2 fan 2}rpm
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Core ${color dodgerblue3}1${color} ${hwmon 1 temp 2}°C @${lua_parse format %3.0f ${cpu cpu1}}% ${goto 115} ${color dodgerblue3}${cpubar cpu1}${color}
Core ${color dodgerblue3}2${color} ${hwmon 1 temp 3}°C @${lua_parse format %3.0f ${cpu cpu2}}% ${goto 115} ${color dodgerblue3}${cpubar cpu2}${color}
Core ${color dodgerblue3}3${color} ${hwmon 1 temp 4}°C @${lua_parse format %3.0f ${cpu cpu3}}% ${goto 115} ${color dodgerblue3}${cpubar cpu3}${color}
Core ${color dodgerblue3}4${color} ${hwmon 1 temp 5}°C @${lua_parse format %3.0f ${cpu cpu4}}% ${goto 115} ${color dodgerblue3}${cpubar cpu4}${color}

### TOP
${font Open Sans:Bold:size=10}${color dodgerblue3}TOP ${hr 2}${color}${font}
${font Open Sans:bold:size=8}PROCESSUS :${font} ${running_processes}/${processes} ${goto 145} ${font Open Sans:bold:size=8} MEM ${goto 220} CPU${font}
${top name 1} ${goto 140} ${top mem 1}% ${alignr} ${top cpu 1}%
${top name 2} ${goto 140} ${top mem 2}% ${alignr} ${top cpu 2}%
${top name 3} ${goto 140} ${top mem 3}% ${alignr} ${top cpu 3}%
${top name 4} ${goto 140} ${top mem 4}% ${alignr} ${top cpu 4}%
${top name 5} ${goto 140} ${top mem 5}% ${alignr} ${top cpu 5}%
]]

And conky_scripts.lua:

function conky_format(format, number)
    return string.format(format, conky_parse(number))
end

function conky_open(file)
      local f = io.open(file, "rb")
      if not f then return "" end
      local str = f:read()
      f:close()
      return str
end
lasers commented 6 years ago

@X0rg Okay. Just to be clear... You're referring to no more than just 180.27%?

I had to knock off few cores off before I can reproduce. I am able to get 303% for both ${top cpu 1} and ${top cpu 2} instead of 100.?. Apparently, it's not exclusive to ${top cpu 1}.

Your separators are throwing me off. In the second screenshot, top is reporting low numbers, eg 1,03 (1.03%) and the cpubars are too high for such numbers. Different screenshot = second issue?

2018-08-08-185018_348x300_scrot

TheTumultuousUnicornOfDarkness commented 6 years ago

@lasers ${cpubar} and ${top} are not reflecting the same CPU usage:

Another screenshot while running pts/c-ray-1.1.0 with Linux LTS 4.16.60: Screenshot 1 On this screenshot, the behavior is normal (395+2+2+1=400%). :heavy_check_mark:

And with Linux 4.17.11 with CK patchset: Screenshot 2 On left, top is showing 400% for c-ray-mt while Conky on right is showing 212.98%. :x:

On txtsd's screenshot, I can see he was using Linux-CK too. In other words, Conky doesn't deal properly with BFS/MuQSS CPU scheduler.

su8 commented 6 years ago

The sleep during intervals should be one clock tick which in linux is 100ms. Due to the nature of update time interval - the variable it collects cpu usage every x seconds instead.

su8 commented 6 years ago

@X0rg Can you try the following patch:

diff --git a/src/linux.cc b/src/linux.cc
index f2844d38..dc4222ab 100644
--- a/src/linux.cc
+++ b/src/linux.cc
@@ -932,6 +932,12 @@ int update_running_processes(void) {
 }

 int update_cpu_usage(void) {
+  struct timespec tc = {0L, 100L * 1000000L};
+  update_stat();
+  if (-1 == (nanosleep(&tc, NULL))) {
+    NORM_ERR("update_cpu_usage(): nanosleep failed");
+    return 0;
+  }
   update_stat();
   return 0;
 }

To compile against the master branch:

git clone https://github.com/brndnmtthws/conky
cd conky
mkdir -p build
cd build
cmake ..
make -j4 # 4 cores to run in parallel
TheTumultuousUnicornOfDarkness commented 6 years ago

@su8 Yes. There is no error about update_cpu_usage() with this patch.

lasers commented 6 years ago

@su8 Can you push the code? Don't open a PR.

su8 commented 6 years ago

Done mate :smiley:

lasers commented 6 years ago

Closed via https://github.com/brndnmtthws/conky/pull/600. Thank you @su8! :heart_eyes: :heart_eyes: :heart_eyes: :heart_eyes:

TheTumultuousUnicornOfDarkness commented 6 years ago

Oh, wait... I'm sorry, I misspoke... When I said "no error", I wanted to say that:

In the following code

if (-1 == (nanosleep(&tc, NULL))) {
  NORM_ERR("update_cpu_usage(): nanosleep() failed");
  return 0;
}

nanosleep works ("no error" = no NORM_ERR() in this case), but it doesn't fix this issue at all. :confused:

awakenedtechnologies commented 6 years ago

Testing with the patch from a few days ago, I see no difference. But, on the plus side, conky is still awesome.

github-actions[bot] commented 11 months ago

This issue is stale because it has been open 365 days with no activity. Remove stale label or comment, or this issue will be closed in 30 days.

txtsd commented 10 months ago

I don't use conky anymore as I've moved to wayland.