add cuda-smi support

fixes #24
This commit is contained in:
Casper da Costa-Luis 2019-02-21 16:10:08 +00:00 committed by Camille TJHOA
parent d7d3501fda
commit d943588bb4
2 changed files with 11 additions and 6 deletions

View file

@ -36,6 +36,8 @@ If format strings are added to `status-right`, they should now be visible.
`iostat` or `sar` are the best way to get an accurate CPU percentage.
A fallback is included using `ps -aux` but could be inaccurate.
`nvidia-smi` is required for GPU information.
For OSX, `cuda-smi` is required instead (but only shows GPU memory use rather
than load).
## Usage
@ -128,4 +130,3 @@ twitter if you want to hear about new tmux plugins or feature updates.
### License
[MIT](LICENSE.md)

View file

@ -6,13 +6,17 @@ source "$CURRENT_DIR/helpers.sh"
print_gpu_percentage() {
if command_exists "nvidia-smi"; then
loads=$(nvidia-smi | sed -nr 's/.*\s([0-9]+)%.*/\1/p')
gpus=$(echo "$loads" | wc -l)
load=$(echo "$loads" | awk '{count+=$1} END {print count}')
echo "$load $gpus" | awk '{printf "%3.0f%%", $1/$2}'
loads=$(nvidia-smi)
elif command_exists "cuda-smi"; then
loads=$(cuda-smi)
else
echo "nvidia-smi not found"
echo "nvidia-smi/cuda-smi not found"
return
fi
loads=$(echo "$loads" | sed -nr 's/.*\s([0-9]+)%.*/\1/p')
gpus=$(echo "$loads" | wc -l)
load=$(echo "$loads" | awk '{count+=$1} END {print count}')
echo "$load $gpus" | awk '{printf "%3.0f%%", $1/$2}'
}
main() {