Skip to content

Instantly share code, notes, and snippets.

@pddkhanh
Last active September 10, 2018 07:32
Show Gist options
  • Save pddkhanh/a5e135cb10f5d9f013a7e23931403a1d to your computer and use it in GitHub Desktop.
Save pddkhanh/a5e135cb10f5d9f013a7e23931403a1d to your computer and use it in GitHub Desktop.
My oh-my-zsh plugin
alias xcdd='rm -rf ~/Library/Developer/Xcode/DerivedData/*'
alias xctp='xcbuild_time_profiling'
function xcbuild_time_profiling {
local fileToOpen='';
local is_workspace=true;
local scheme=$1;
if [ -n "$scheme" ]
then
echo "Given scheme: ${scheme}"
fi
for file in `find . -maxdepth 1 -name *.xcworkspace`; do
fileToOpen=$(basename $file)
if [ -z "$scheme" ]
then
scheme="${fileToOpen%.*}"
fi
done
if [ -n "$fileToOpen" ]
then
echo "Found workspace ${fileToOpen}, scheme: ${scheme}"
else
for file in `find . -maxdepth 1 -name *.xcodeproj`; do
fileToOpen=$(basename $file)
is_workspace=false
if [ -z "$scheme" ]
then
scheme="${fileToOpen%.*}"
fi
done
if [ -n "$fileToOpen" ]
then
echo "Found project ${fileToOpen}, scheme: ${scheme}"
else
echo "Exit: No xcode files to open."
return 0
fi
fi
echo "Create output directory profiling/"
mkdir -p ./profiling
if [[ "$is_workspace" = true ]]; then
xcodebuild -destination 'platform=iOS Simulator,name=iPhone X' \
-sdk iphonesimulator -workspace $fileToOpen \
-scheme $scheme -configuration Debug \
clean build \
OTHER_SWIFT_FLAGS="-driver-time-compilation \
-Xfrontend -debug-time-function-bodies \
-Xfrontend -debug-time-compilation" | \
tee profiling/profile.log
else
xcodebuild -destination 'platform=iOS Simulator,name=iPhone X' \
-sdk iphonesimulator -project $fileToOpen \
-scheme $scheme -configuration Debug \
clean build \
OTHER_SWIFT_FLAGS="-driver-time-compilation \
-Xfrontend -debug-time-function-bodies \
-Xfrontend -debug-time-compilation" | \
tee profiling/profile.log
fi
awk '/Driver Compilation Time/,/Total$/ { print }' profiling/profile.log | \
grep compile | \
cut -c 55- | \
sed -e 's/^ *//;s/ (.*%) compile / /;s/ [^ ]*Bridging-Header.h$//' | \
sed -e "s|$(pwd)/||" | \
sort -rn | \
tee profiling/slowest.log
echo "============================================"
echo "============================================"
echo "Profiling build time completed. Check the profile.log and slowest.log in profiling/ redirectory for more detail"
echo "Below are 10 slowest files to compile"
head -10 profiling/slowest.log
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment