tmux-plugins / tmux-battery

Plug and play battery percentage and icon indicator for Tmux.
MIT License
495 stars 94 forks source link

Spikes in CPU usage of tmux on long uptimes attributed to tmux-battery #54

Open BensonMuriithi opened 7 years ago

BensonMuriithi commented 7 years ago

I had been having a problem with tmux whereby after it being running for periods of upwards of 12 or 24 hours I would observe spikes in cpu usage and it would always be caused by tmux. Cpu usage would oscillate between 15% to 80% in 2 seconds and keep on doing so. Similar problems were being faced by users of powerline with tmux. I however don't so I thought it could be tmux-battery as I don't have any intensive plugins and after removing it from the statusline the load vanished. My .tmux.conf relevant to this is below; the rest doesn't seem to be part of the problem.

#commented out setting including tmux-battery use
#set -g status-right '#{battery_status_fg}Batt:#{battery_icon} #{battery_percentage}\
 #[fg=colour114]cont:#{continuum_status}\
 #[fg=colour233,bg=colour241,bold] %d/%m #[fg=colour233,bg=colour245,bold] %H:%M '

#after removing the use of tmux-battery
set -g status-right '\
#[fg=colour114]cont:#{continuum_status}\
 #[fg=colour233,bg=colour241,bold] %d/%m #[fg=colour233,bg=colour245,bold] %H:%M '
martinbeentjes commented 7 years ago

That is strange behavior, there is an old issue with a same status. So when you remove the tmux-battery related parameters from your status-right the CPU spikes disappear? Did you test any of those three parameters you used?

BensonMuriithi commented 7 years ago

The spikes stopped when I removed the uses of tmux-battery without any further intervention. I've since had tmux running for more than 50 hours and it's all ok. I did try disbaling each of the three flags separately and resourcing. I noticed that for each removed flag the spikes in cpu use would be smaller - peaking at 50% - but were still present. Disabling any two flags simultaneously would reduce the spikes just a bit more. I did however not notice any flag to have any greater consequence than any of the other two.

I should add that though most times the issue occurred with the battery fully charged, it would not stop even after the battery would then start discharging to any level or even charging again. The indicators are also accurate and in line with the system indicators.

martinbeentjes commented 7 years ago

In the recent days I have been recognizing this behavior myself as well. For me it is not a single spike. I was monitoring the system for a while and it kept peaking at 100% for quite a while. And when I closed tmux, the CPU usage went back to normal.

And having my terminal doing the things I always do, does not make my CPU usage peak at all. I have not ruled out the reason for my personal problem. I will look into the question if it is caused by tmux-battery. I'll keep this updated.

rux616 commented 5 years ago

I was just experiencing a similar (though not as extreme) symptom. I am using Fedora 29 and when using upower to check the battery, I saw about an average 5% bump in sustained CPU usage. When I changed the scripts locally to call acpi instead, my CPU usage dropped down to my baseline again.

Has anyone else seen this? Would this be a good reason to use acpi instead of upower as the first choice?

martinbeentjes commented 5 years ago

@rux616 Thank you for your comment. When Googling on excessive power usage of upower it seems to be a general problem. I see bug reports from back in 2011, some in 2014.

If acpi and upower are available on a machine and acpi does not cause those cpu and memory spikes, then choosing acpi over upower seems okay to me.

The comment https://bugs.launchpad.net/ubuntu/+source/upower/+bug/876279/comments/7 also tells something interesting: a possible flooding of monitoring events on the battery.

I am curious if we could get to know what exactly causes upower to randomly request this amount of cpu.