-
-
Save bpradipt/47d43e5601a76a0636839a3646d1cd37 to your computer and use it in GitHub Desktop.
Generate JSON output of buildah build step timing, useful for profiling
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 | |
# script: time-buildah-build.sh | |
# | |
# All command line arguments are passed to buildah build command. | |
# | |
# usage: ./time-buildah-build.sh | |
# | |
# Acknowledgement: https://gist.github.com/philpoore/05eca572f3aadf70f529c470ac679147 | |
DATE_FORMAT="+%s" | |
( | |
# Output START line | |
echo "$(date $DATE_FORMAT) | - 0 - START" | |
buildah build $* . | \ | |
grep "^Step" | \ | |
while read line ; | |
do | |
# Output build output prefixed with date | |
echo "$(date $DATE_FORMAT) | $line"; | |
done; | |
# Output END line | |
echo "$(date $DATE_FORMAT) | - -1 - END" | |
) | ( | |
# Generate JSON array output. | |
# - START is step: 0 | |
# - END is step: -1 | |
echo "[" | |
FIRST_RUN=true | |
while read line ; | |
do | |
[[ -z "$FIRST_RUN" ]] && echo "," # if not first line, print ',' | |
lineArray=($line) | |
time="${lineArray[0]}" # step is 0th | |
step="${lineArray[3]}" # step is 2nd | |
cmd="${lineArray[@]:5}" # cmd is everything after 5th | |
stepNum=${step/\/*/} | |
escapedCmd="${cmd//\"/\\\"}" # escape all double quotes '"' | |
echo " {" | |
echo " \"time\": $time," | |
echo " \"step\": $stepNum," | |
echo " \"cmd\": \"$escapedCmd\"" | |
echo -n " }" | |
unset FIRST_RUN | |
done | |
echo | |
echo "]" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment