Created
September 18, 2022 21:16
-
-
Save T3sT3ro/72927cac8a3d1f74715748ffd6c56613 to your computer and use it in GitHub Desktop.
bash profiling utility - use it as a custom rcfile to get accurate timings for the whole .bashrc loading process
This file contains 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
# Based on https://stackoverflow.com/a/20855353/5555799 | |
# Store this file in ~/.bashrc.profiler and add this alias to your .bashrc: | |
# alias profilebashstartup='exec bash --rcfile ~/.bashrc.profiler' | |
TRACEFILE=$(mktemp /tmp/trace.XXX) | |
TIMINGFILE=$(mktemp /tmp/timing.XXX) | |
STARTTIME=$(date +%s.%N) | |
exec 3>&2 2> >( tee $TRACEFILE | sed -u 's/^.*$/now/' | date -f - +%s.%N >$TIMINGFILE) | |
set -x | |
source ~/.bashrc | |
set +x | |
exec 2>&3 3>&- | |
BASHTRACELOG=$(mktemp /tmp/bashtracelog.XXX) | |
paste <(awk "{printf \"%f\t%f\",\$1,\$1-$STARTTIME; \$1=\"\"; print}" $TIMINGFILE) $TRACEFILE > $BASHTRACELOG | |
rm $TRACEFILE $TIMINGFILE | |
echo "Bash trace log saved to $BASHTRACELOG" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment