Skip to content

Instantly share code, notes, and snippets.

@chooban
Last active November 7, 2019 16:46
Show Gist options
  • Save chooban/e765469751b102a59b4d00129bbfc4db to your computer and use it in GitHub Desktop.
Save chooban/e765469751b102a59b4d00129bbfc4db to your computer and use it in GitHub Desktop.
Script for graphing heroku build and slug size data
#! /bin/zsh
autoload colors
if [[ "$terminfo[colors]" -gt 8 ]]; then
colors
fi
eval RESET='$reset_color'
function spin() {
spinner="/|\\-/|\\-"
while :
do
for i in `seq 0 7`
do
echo -n "${spinner:$i:1}"
echo -en "\010"
sleep 1
done
done
}
function join_by { local IFS="$1"; shift; echo "$*"; }
app=''
debug=false
while getopts "a:d" o; do
case "${o}" in
a)
app=${OPTARG}
;;
d)
debug=true
;;
esac
done
if [ $debug = false ]; then
spin &
SPIN_PID=$!
trap "kill -9 $SPIN_PID" `seq 0 15`
fi
build_data=()
build_ids=($(heroku builds --app $app | awk 'NR > 1 {print $1}'))
for id in $build_ids; do
$debug && printf "Fetching data for %s\n" $id
log=$(heroku builds:output $id --app $app 2>&1 >/dev/null)
elapsed=$(echo $log | awk '/Done in/ { match($0, /([0-9]{1,3})\./, arr); sum += arr[1] } END { print sum }')
release=$(echo $log | awk '/Released v/ { match($0, /([0-9]{1,3})/, arr); print arr[1] }')
size=$(echo $log | awk '/Done: / { match($0, /([0-9]{1,3}(\.[0-9])?)/, arr); print arr[1] }')
if (( $size > 0 )); then
printf -v row '%d,%d,%d' $release $elapsed $size
build_data=($row $build_data[@])
fi
done
data=$(join_by $'\n' "${build_data[@]}")
printf -v full_data "@ Time,Size\n%s" $data
echo $full_data | termgraph --color {blue,red}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment