tmux-plugins / tmux-cpu

Plug and play cpu percentage and icon indicator for Tmux.
MIT License
444 stars 69 forks source link

cpu_percentage on linux #8

Closed mrflow closed 8 years ago

mrflow commented 8 years ago

The cpu_percentage value on linux does not show the current CPU load, but the overall average CPU load since the computer was started. I guess this is not intentional.

On linux there simply is no easy way (without installing strange extra packages) to get the current CPU load in a range of 0-100%.

The following might be considered as an alternative, but it gives values >100% (due to ps' way of calculating CPU loads):

More exact, but requires bc: printf "%.0f\n" $(ps -A -o pcpu | tail -n+2 | paste -sd+ | xargs -i echo "(" {} ") / $(nproc)" | bc)

Does the job without bc, in zsh you wouldn't need the sed part: `echo $(($(ps -A -o pcpu | tail -n+2 | paste -sd+ | sed 's/.[0-9]//g' | xargs -i echo "(" {} ") / $(nproc)")))``

ctjhoa commented 8 years ago

@mrflow Thanks for the report. Based on your suggestion I made a generic method for BSD and Linux. Tell me what you think.

mrflow commented 8 years ago

@ctjhoa works perfectly (for me on Linux at least). Thanks!