Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added WSL support #86

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

PastaMasta
Copy link

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

Copy link
Collaborator

@casperdcl casperdcl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

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

  • CPU wmic: 1.3sec
  • CPU ps -aux: 0.3sec
  • RAM wmic: 0.54sec
  • RAM free: 0.14sec

are there any advantages to using wmic? Is it more accurate? I didn't quite understand "guest CPU / RAM can be limited by WSL config the current methods are not indicative of the whole system"

@@ -10,7 +10,10 @@ cpu_percentage_format="%3.1f%%"
print_cpu_percentage() {
cpu_percentage_format=$(get_tmux_option "@cpu_percentage_format" "$cpu_percentage_format")

if command_exists "iostat"; then
if [[ $(get_tmux_option @cpu_wsl_host) == "true" && -n "${WSL_DISTRO_NAME}" ]] ; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason not to just do this?

Suggested change
if [[ $(get_tmux_option @cpu_wsl_host) == "true" && -n "${WSL_DISTRO_NAME}" ]] ; then
if command_exists "wmic.exe"; then

or even better, alter the is_cygwin function & convert pre-exisiting WMIC calls to wmic.exe?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to ensure we gave users the options if they wanted to just see the guest/WSL performance or the whole system and to make sure it only ran if you actually were inside WSL (I use the same .tmux.conf on multiple systems)

or even better, alter the is_cygwin function & convert pre-exisiting WMIC calls to wmic.exe?

This might be a better option, although cygwin and WSL are different beasts - I'll install cygwin and give it a go when I've got chance.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to install cygwin -- I mean we can change is_cygwin to simply is_win (i.e. is_wsl_or_cygwin)

@PastaMasta
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants