Skip to content

Commit

Permalink
GPU Use/mem/power for AMD & Intel GPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
shawarden committed Oct 23, 2024
1 parent ea1a45d commit 5beacea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
10 changes: 8 additions & 2 deletions scripts/gpu_power.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 8 additions & 1 deletion scripts/gpu_ram_info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/gpu_usage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5beacea

Please sign in to comment.