Skip to content

Instantly share code, notes, and snippets.

@jonatw
Created March 3, 2014 10:27
Show Gist options
  • Save jonatw/9322244 to your computer and use it in GitHub Desktop.
Save jonatw/9322244 to your computer and use it in GitHub Desktop.
home-made GPU top using nvidia-smi
#!/bin/bash
SAMPLE_COUNT=20;
INTERVAL=0.5;
for (( c=1; c<=$SAMPLE_COUNT; c++ )); do nvidia-smi --query-gpu=utilization.gpu,utilization.memory --format=csv,noheader,nounits >> /tmp/GPU_$TIMESTAMP; sleep $INTERVAL; done;
GPU_USG_SUM=`cat /tmp/GPU_$TIMESTAMP | sed 's/, / /g' | awk '{sum+=$1}END{print sum}'`
GPU_USG_MIN=`cat /tmp/GPU_$TIMESTAMP | sed 's/, / /g' |cut -d ' ' -f 1 | sort | head -n 1`
GPU_USG_MAX=`cat /tmp/GPU_$TIMESTAMP | sed 's/, / /g' |cut -d ' ' -f 1 | sort | tail -n 1`
GPU_MEM_SUM=`cat /tmp/GPU_$TIMESTAMP | sed 's/, / /g' | awk '{sum+=$2}END{print sum}'`
GPU_MEM_MIN=`cat /tmp/GPU_$TIMESTAMP | sed 's/, / /g' |cut -d ' ' -f 2 | sort | head -n 1`
GPU_MEM_MAX=`cat /tmp/GPU_$TIMESTAMP | sed 's/, / /g' |cut -d ' ' -f 2 | sort | tail -n 1`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment