tmux-plugins / tmux-cpu

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

Added WSL support #86

Open PastaMasta opened 1 year ago

PastaMasta commented 1 year ago

This PR adds support to gather CPU & RAM % usage of the Windows host system when using Windows subsystem for Linux.

As the guest CPU / RAM can be limited by WSL config the current methods are not indicative of the whole system.

This also adds two new options: @cpu_wsl_host and @ram_wsl_host to control if this data should come from the guest or the host - when set the data comes from querying wmic.exe

PastaMasta commented 1 year ago

I didn't quite understand "guest CPU / RAM can be limited by WSL config the current methods are not indicative of the whole system"

I raised the PR quite late in the day and re-reading with coffee I should have explained more.

When using WSL the running guest can only access it's own child processes - so ps / top / htop etc can only see the stats of processes inside of the Linux instance and not the Windows processes of the host (which would include the WSL usage under a vmmem proc). My intension was to display the same stats as Task Manager so I can see my status bar go red when I open too many chrome tabs on the host system.

You can also specify CPU / Memory limits for the guest in .wslconfig: https://learn.microsoft.com/en-us/windows/wsl/wsl-config#configuration-setting-for-wslconfig so if the guest had 50% memory then free would only be reporting on that.

From my tests, it seems a bit slower (WSL2 debian on Win11):

I'm seeing about the same, running WSL2 AmazonLinux2 on W10 - there may be a faster way to find this, I'll have another dig about when I've got chance.