This repository has been archived by the owner on Oct 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
profile.sh
executable file
·138 lines (114 loc) · 3.32 KB
/
profile.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh
# https://github.com/apple/swift/blob/master/docs/CompilerPerformance.md#diagnostic-options
ARTIFACTS_DIR=./ProfilingArtifacts
# =============================
# Utility functions
# =============================
function testForLogFile {
if [ ! -f "$ARTIFACTS_DIR/build-profile.log" ]; then
echo "$ARTIFACTS_DIR/build-profile.log does not exist."
echo "Run build first."
exit 1
fi
}
function ensureArtifactsDirExists {
mkdir -p $ARTIFACTS_DIR
}
# =============================
# Private functions
# =============================
function _buildAndLog {
ensureArtifactsDirExists
echo "Building..."
xcodebuild \
-workspace "Slide for Reddit.xcworkspace" \
-scheme "Slide for Reddit" \
-configuration "Debug" \
-destination "generic/platform=iOS" \
-showBuildTimingSummary \
clean build \
OTHER_SWIFT_FLAGS="-Xfrontend -debug-time-compilation -Xfrontend -debug-time-function-bodies -Xfrontend -debug-time-expression-type-checking" | \
tee $ARTIFACTS_DIR/build-profile.log
echo "Build complete."
echo "Output has been captured in $ARTIFACTS_DIR/build-profile.log"
}
# =============================
# Public functions
# =============================
function build {
time _buildAndLog
}
function run_xclogparser {
if ! type "xclogparser" > /dev/null; then
echo "XCLogParser is not installed!"
exit 1
fi
# _buildAndLog
# Create xclogparser output from existing build | extract path of output | open output path in browser
xclogparser parse --project Slide_for_Reddit --reporter html | awk 'NF>1{print $NF}' | xargs -I{} open {}
}
function step1 {
printBuildTimingSummary
}
function step2 {
printDebugCompilationTiming
}
function step3 {
printSlowestFunctionBodies
}
# https://irace.me/swift-profiling
# Print top 20 slowest function bodies
function printCulprits {
testForLogFile
grep .[0-9]ms $ARTIFACTS_DIR/build-profile.log |
grep -v ^0.[0-9]ms |
sort -nr |
head -100
}
function printBadCulprits {
testForLogFile
grep .[0-9]ms $ARTIFACTS_DIR/build-profile.log |
grep -v ^([0-9]{1,3}).[0-9]ms |
sort -nr |
head -100
}
# https://github.com/fastred/Optimizing-Swift-Build-Times
# function printSlowest {
# awk '/Driver Compilation Time/,/Total$/ { print }' $ARTIFACTS_DIR/build-profile.log | \
# grep compile | \
# cut -c 55- | \
# sed -e 's/^ *//;s/ (.*%) compile / /;s/ [^ ]*Bridging-Header.h$//' | \
# sed -e "s|$(pwd)/||" | \
# sort -rn
# }
# Step 1
function printBuildTimingSummary {
testForLogFile
cat $ARTIFACTS_DIR/build-profile.log | sed -n -e '/Build Timing Summary/,$p'
}
# Step 2
function printDebugCompilationTiming {
testForLogFile
awk '/CompileSwift normal/,/Swift compilation/{print; getline; print; getline; print}' $ARTIFACTS_DIR/build-profile.log |
grep -Eo "^CompileSwift.+\.swift|\d+\.\d+ seconds" |
sed -e 'N;s/\(.*\)\n\(.*\)/\2 \1/' |
sed -e "s|CompileSwift normal x86_64 $(pwd)/||" |
sort -rn |
head -3
}
# Step 3
function printSlowestFunctionBodies {
testForLogFile
grep -o "^\d*.\d*ms\t[^$]*$" $ARTIFACTS_DIR/build-profile.log |
awk '!visited[$0]++' |
sed -e "s|$(pwd)/||" |
sort -rn |
head -5
}
# cat build-profile-2.log |
# grep -o "^\d*.\d*ms\t[^$]*$" |
# awk '!visited[$0]++' |
# sed -e "s|$(pwd)/||" |
# sort -rn |
# head -50
eval $1