Conversation
There was a problem hiding this comment.
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"
| 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 |
There was a problem hiding this comment.
any reason not to just do this?
| 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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
no need to install cygwin -- I mean we can change is_cygwin to simply is_win (i.e. is_wsl_or_cygwin)
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
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. |
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_hostand@ram_wsl_hostto control if this data should come from the guest or the host - when set the data comes from querying wmic.exe