Skip to content

Instantly share code, notes, and snippets.

@woolpeeker
Created May 25, 2021 09:24
Show Gist options
  • Save woolpeeker/24fc3f1d4bce5114d5e5486a4e53915c to your computer and use it in GitHub Desktop.
Save woolpeeker/24fc3f1d4bce5114d5e5486a4e53915c to your computer and use it in GitHub Desktop.
GPU_load_statistic
"""
Usage:
python gpu_analysis.py <gpu_load.txt> <gpu_num>
"""
import sys
gpu_num = int(sys.argv[2])
total = 0
utilized = 0
for line in open(sys.argv[1]).readlines():
line = line.rstrip()
data = line.split()[2:]
assert len(data) == gpu_num
data = [1 if int(x)>0 else 0 for x in data]
total += len(data)
utilized += sum(data)
print('utilization: %.3f' % (utilized / total))
# Usage:
# nohup bash gpu_load.sh &> gpu_load.txt &
while true;
do
t=`date --rfc-3339=second`;
u=`nvidia-smi | grep % | awk -F'|' '{print $4}' | awk -F'%' '{print $1}'`;
u=`echo $u | tr -s "\n" " "`
echo "$t $u";
sleep 1;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment