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

[Bug]: Top CPU is always zero #1376

Open madhur opened 1 year ago

madhur commented 1 year ago

What happened?

The CPU percentages are always zero. Even if I run stress occupying 6 cpu's 100% of my 12 cpu processor.

I understand its because of total_run_times being 1. Here is the output

Name          CPU             PID
conky              0.00%     761794
sleep              0.00%     761617
stress             0.00%     761370
stress             0.00%     761369
stress             0.00%     761368

If I make the total_run_times as 2

Name          CPU             PID
conky              0.00%     761794
sleep              0.00%     761617
stress             0.00%     761370
stress             0.00%     761369
stress             0.00%     761368
Name          CPU             PID
stress             8.36%     761365
stress             8.34%     761366
stress             8.34%     761367
stress             8.34%     761369
stress             8.34%     761370

The output is correct. I understand its calculating CPU usage of processor across all CPU. Thus 100/12 ~ 8.33 %

Version

conky 1.17.1_pre compiled 2023-01-21 for Linux x86_64

Which OS/distro are you seeing the problem on?

Linux (other)

Conky config

conky.config = {
background = false,
out_to_x=false,
out_to_console=true,    
total_run_times=1   
}

conky.text = [[
Name          CPU             PID
${top name 1} ${top cpu 1}%    ${top pid 1}
${top name 2} ${top cpu 2}%    ${top pid 2}
${top name 3} ${top cpu 3}%    ${top pid 3}
${top name 4} ${top cpu 4}%    ${top pid 4}
${top name 5} ${top cpu 5}%    ${top pid 5}
]]%    

### Stack trace

_No response_

### Relevant log output

```Shell
Name          CPU             PID
conky              0.00%     761794
sleep              0.00%     761617
stress             0.00%     761370
stress             0.00%     761369
stress             0.00%     761368
Name          CPU             PID
stress             8.36%     761365
stress             8.34%     761366
stress             8.34%     761367
stress             8.34%     761369
stress             8.34%     761370
Mayuresh0072 commented 1 year ago

@marius @alip @madhur I want to work on this issue , Please assign me . Thanks.

madhur commented 1 year ago

@marius @alip @madhur I want to work on this issue , Please assign me . Thanks.

I assume you can just fix and raise PR. There is no assignment needed.

ahmogit commented 1 year ago

Fwiw, seeing the same behavior with total_run_times = 0.

OS: Arch linux. Conky version report: conky 1.18.1_pre compiled 2023-09-03 for Linux x86_64

brndnmtthws commented 1 year ago

The math requires 2 data points to calculate the usage, so you can't have a result with just 1 sample (which is what total_run_times = 1 will do).

The math happens here on Linux: https://github.com/brndnmtthws/conky/blob/53973402b4fda399267c225b9fc7395ed862bde9/src/linux.cc#L1055-L1073

ahmogit commented 1 year ago

I don't think that explains the entire issue.

As mentioned earlier in the thread, my .conkyrc explicitly sets total_run_times to 0, yet the top CPU usage is often (though not always) reported as "0.00". Example annotated screenshot attached.

top_cpu_zero

brndnmtthws commented 1 year ago

Ah, I think I misunderstood. It doesn't make sense that the top value would be zero in this case, so it probably warrants further investigation.

Caellian commented 5 days ago

@epsheldoni confirms the same issue on OpenBSD. Still present in at least 1.9.0, but likely in latest version too.

epsheldoni commented 5 days ago

I notice that I have total_run_times 0 in my .conkyrc. After I change total_run_times to 1 or greater, conky crashes Here is what I get

pangolin$ conky -d Conky: forked to background, pid is 98789 pangolin$ Conky: desktop window (1a00003) is subwindow of root window (538) Conky: window type - normal Conky: drawing to created window (0x2000002) Conky: drawing to double buffer

and nothing is displayed. So, I try to kill the process and I get

pangolin$ kill 98789 ksh: kill: 98789: No such process pangolin$

After I change total_run_times back to zero and relaunch conky, I did notice that initially the ${cpu cpu1}% values show something other than zero briefly and then change to zero.