From 5beacea9c64cc66d5250931c6bdebf5db6078ce0 Mon Sep 17 00:00:00 2001 From: Samuel Hawarden Date: Thu, 24 Oct 2024 11:44:27 +1300 Subject: [PATCH 1/2] GPU Use/mem/power for AMD & Intel GPUs --- scripts/gpu_power.sh | 10 ++++++++-- scripts/gpu_ram_info.sh | 9 ++++++++- scripts/gpu_usage.sh | 2 +- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/scripts/gpu_power.sh b/scripts/gpu_power.sh index 33f1a742..1fd32592 100755 --- a/scripts/gpu_power.sh +++ b/scripts/gpu_power.sh @@ -52,9 +52,15 @@ get_gpu() elif [[ "$gpu" == apple ]]; then usage="$(sudo powermetrics --samplers gpu_power -i500 -n 1 | grep 'GPU Power' | sed 's/GPU Power: \(.*\) \(.*\)/\1\2/g')" else - usage='unknown' + usage=$( + for card in /sys/class/drm/card? + do + echo "$(($(cat "$card"/device/hwmon/hwmon?/power1_average) / 1000 / 1000))/$(($(cat "$card"/device/hwmon/hwmon?/power1_cap_max) / 1000 / 1000))W" + done | \ + sed -z -e 's/\n/|/g' -e 's/|$//g' + ) fi - normalize_percent_len $usage + echo $usage } main() diff --git a/scripts/gpu_ram_info.sh b/scripts/gpu_ram_info.sh index a3fceefa..c4d482c8 100755 --- a/scripts/gpu_ram_info.sh +++ b/scripts/gpu_ram_info.sh @@ -52,7 +52,14 @@ get_gpu() usage=$(nvidia-smi --query-gpu=memory.used,memory.total --format=csv,noheader,nounits | awk "{ used += \$0; total +=\$2 } END { printf(\"%${used_accuracy}GB/%${total_accuracy}GB\n\", used / 1024, total / 1024) }") fi else - usage='unknown' + usage="$( + for card in /sys/class/drm/card? + do + use=$(cat "$card"/device/mem_info_vram_used | numfmt --to=iec --suffix=B) + max=$(cat "$card"/device/mem_info_vram_total | numfmt --to=iec --suffix=B) + echo "$use/$max" + done | sed -z -e 's/\n/|/g' -e 's/|$//g' + )" fi echo $usage } diff --git a/scripts/gpu_usage.sh b/scripts/gpu_usage.sh index 70794aab..b052900c 100755 --- a/scripts/gpu_usage.sh +++ b/scripts/gpu_usage.sh @@ -47,7 +47,7 @@ get_gpu() elif [[ "$gpu" == apple ]]; then usage="$(sudo powermetrics --samplers gpu_power -i500 -n 1 | grep 'active residency' | sed 's/[^0-9.%]//g' | sed 's/[%].*$//g')%" else - usage='unknown' + usage="$(cat /sys/class/drm/card?/device/gpu_busy_percent | sed -z -e 's/\n/%|/g' -e 's/|$//g')" fi normalize_percent_len $usage } From 49d73f909f1da927b1c4964de8c578323b66d2f5 Mon Sep 17 00:00:00 2001 From: Samuel Hawarden Date: Fri, 25 Oct 2024 09:42:35 +1300 Subject: [PATCH 2/2] Intel & Matrox integrated do not work --- scripts/gpu_power.sh | 4 +++- scripts/gpu_ram_info.sh | 4 +++- scripts/gpu_usage.sh | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/gpu_power.sh b/scripts/gpu_power.sh index 1fd32592..efba040c 100755 --- a/scripts/gpu_power.sh +++ b/scripts/gpu_power.sh @@ -51,7 +51,7 @@ get_gpu() elif [[ "$gpu" == apple ]]; then usage="$(sudo powermetrics --samplers gpu_power -i500 -n 1 | grep 'GPU Power' | sed 's/GPU Power: \(.*\) \(.*\)/\1\2/g')" - else + elif [[ "$gpu" == Advanced ]]; then usage=$( for card in /sys/class/drm/card? do @@ -59,6 +59,8 @@ get_gpu() done | \ sed -z -e 's/\n/|/g' -e 's/|$//g' ) + else # "Intel" "Matrox", etc + usage="unknown" fi echo $usage } diff --git a/scripts/gpu_ram_info.sh b/scripts/gpu_ram_info.sh index c4d482c8..f2bfc735 100755 --- a/scripts/gpu_ram_info.sh +++ b/scripts/gpu_ram_info.sh @@ -51,7 +51,7 @@ get_gpu() total_accuracy=$(get_tmux_option "@dracula-gpu-vram-total-accuracy" "d") usage=$(nvidia-smi --query-gpu=memory.used,memory.total --format=csv,noheader,nounits | awk "{ used += \$0; total +=\$2 } END { printf(\"%${used_accuracy}GB/%${total_accuracy}GB\n\", used / 1024, total / 1024) }") fi - else + elif [[ "$gpu" == Advanced ]]; then usage="$( for card in /sys/class/drm/card? do @@ -60,6 +60,8 @@ get_gpu() echo "$use/$max" done | sed -z -e 's/\n/|/g' -e 's/|$//g' )" + else # "Intel" "Matrox", etc + usage="unknown" fi echo $usage } diff --git a/scripts/gpu_usage.sh b/scripts/gpu_usage.sh index b052900c..6477f211 100755 --- a/scripts/gpu_usage.sh +++ b/scripts/gpu_usage.sh @@ -46,8 +46,10 @@ get_gpu() usage=$(nvidia-smi --query-gpu=utilization.gpu --format=csv,noheader,nounits | awk '{ sum += $0 } END { printf("%d%%\n", sum / NR) }') elif [[ "$gpu" == apple ]]; then usage="$(sudo powermetrics --samplers gpu_power -i500 -n 1 | grep 'active residency' | sed 's/[^0-9.%]//g' | sed 's/[%].*$//g')%" - else + elif [[ "$gpu" == Advanced ]]; then usage="$(cat /sys/class/drm/card?/device/gpu_busy_percent | sed -z -e 's/\n/%|/g' -e 's/|$//g')" + else # "Intel" "Matrox", etc + usage="unknown" fi normalize_percent_len $usage }