From 14ad891d3dda829675898ef096ae6aa4c0616c5b Mon Sep 17 00:00:00 2001 From: Jaewon Chung Date: Fri, 7 Aug 2020 00:56:00 +0900 Subject: [PATCH 1/2] Support multi-gpu environment --- scripts/gpu_usage.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/gpu_usage.sh b/scripts/gpu_usage.sh index 3bb1445..f59e306 100755 --- a/scripts/gpu_usage.sh +++ b/scripts/gpu_usage.sh @@ -4,7 +4,7 @@ get_platform() { case $(uname -s) in Linux) - gpu=$(lspci -v | grep -i gpu | grep driver | awk '{print $5}') + gpu=$(lspci -v | grep VGA | head -n 1 | awk '{print $5}') echo $gpu ;; @@ -20,10 +20,12 @@ get_platform() get_gpu() { gpu=$(get_platform) - if [ $gpu == nvidia-gpu ]; then - usage=$(nvidia-smi | grep "%" | awk '{print $13}') - echo $usage + if [[ "$gpu" == NVIDIA ]]; then + usage=$(nvidia-smi | grep '%' | awk '{ sum += $13 } END { printf("%d%%\n", sum / NR) }') + else + usage='unknown' fi + echo $usage } main() { @@ -33,5 +35,3 @@ main() } # run the main driver main - - From 33703eb2d35b5612b9abd041c5e3f9f55fdc9b86 Mon Sep 17 00:00:00 2001 From: Gaganpreet Date: Mon, 31 Aug 2020 11:41:45 +0200 Subject: [PATCH 2/2] specify numeric locale for parsing top output --- scripts/cpu_info.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index c5180cd..92cec3b 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -4,7 +4,7 @@ get_percent() { case $(uname -s) in Linux) - percent=$(top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') + percent=$(LC_NUMERIC=en_US.UTF-8 top -bn1 | grep "Cpu(s)" | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}') echo $percent ;;