Last active
March 17, 2018 23:24
-
-
Save maxchuquimia/a841f52e10bb28c958f6a13d4bc9af5d to your computer and use it in GitHub Desktop.
Track how much time you spend waiting for you Swift project to compile over the day
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Start this in the morning when you get to work | |
# Control+C to kill it before you leave | |
# The time spent is printed on the screen | |
# Use it to make a case for a faster laptop! | |
INTERVAL=5 | |
COMPILE_TIME=0 | |
ALL_TIMES=() | |
PREV_TIME=0 | |
trap ctrl_c INT | |
function ctrl_c() { | |
max=0 | |
for v in ${ALL_TIMES[@]}; do | |
if (( $v > $max )); then max=$v; fi; | |
done | |
TIME_SPENT_S=$(date -u -r $max +%T) | |
TIME_SPENT=$(date -u -r $COMPILE_TIME +%T) | |
echo -en "\n" | |
echo -en "Longest build time : $TIME_SPENT_S\n" | |
echo -en "Number of builds : ${#ALL_TIMES[@]}\n" | |
echo -en "Total time spent : $TIME_SPENT\n" | |
exit 0 | |
} | |
while true; | |
do | |
SWIFTC_TASKS=$(ps -A | grep -v grep | grep -i swiftc | wc -l | sed -e 's/ //g') | |
if [ "$SWIFTC_TASKS" -gt 0 ] | |
then | |
COMPILE_TIME=$((COMPILE_TIME + INTERVAL)) | |
PREV_TIME=$((PREV_TIME + INTERVAL)) | |
echo -en "($COMPILE_TIME)" | |
else | |
echo -en "-" | |
if [ "$PREV_TIME" -gt 0 ] | |
then | |
ALL_TIMES+=($PREV_TIME) | |
PREV_TIME=0 | |
fi | |
fi | |
sleep $INTERVAL | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment