$ xcodebuild clean build -workspace 'MyApp.xcworkspace' -scheme 'MyApp' OTHERFLAGS="-Xfrontend -debug-time-function-bodies" | tee xcode_raw.log
$ python slow.py xcode_raw.log
23559.6ms ./Sources/A.swift:219:16 @objc dynamic func doneButtonDidTap()
23439.6ms ./Sources/B.swift:763:8 @objc final func checkCondition()
9346.7ms ./Sources/C.swift:741:8 @objc final func updatePreviewComments()
2652.9ms ./Sources/D.swift:865:8 @objc final func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
1049.5ms ./Sources/E.swift:41:8 final func transformToJSON(_ value: UIColor?) -> String?
653.0ms ./Sources/F.swift:49:8 func flush()
Total Build Time: 227042.500002ms
Slow Functions : 66860.6ms
Last active
November 21, 2016 08:54
-
-
Save devxoul/82f52a67feda8102d99c8e527799c626 to your computer and use it in GitHub Desktop.
List slow compile functions in Swift
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
# encoding: utf-8 | |
import os | |
import re | |
import sys | |
def help_exit(): | |
print 'Usage: python slow.py [threshold-ms] [inputfile]' | |
exit(1) | |
if len(sys.argv) > 1 and sys.argv[1] in ['-h', '--help']: | |
help_exit() | |
if len(sys.argv) != 3: | |
help_exit() | |
try: | |
threshold = int(sys.argv[1]) | |
except ValueError: | |
print "Error: Threshold must be an integer: '{}'".format(sys.argv[1]) | |
exit(1) | |
input = sys.argv[2] | |
try: | |
with open(input, 'r') as f: | |
lines = f.readlines() | |
except IOError: | |
print "Error: File doesn\'t exist: '{}'".format(input) | |
exit(1) | |
slow_lines = [] # (duration, line) | |
pattern = re.compile('(\s*\d+\.\d+)ms.*') | |
total_duration = 0 | |
pwd = os.path.abspath(os.path.curdir) | |
for line in lines: | |
match = pattern.match(line) | |
if match is None: | |
continue | |
duration = float(match.group(1)) | |
total_duration += duration | |
if duration >= threshold: | |
simple_line = line.replace(pwd, '.') | |
slow_lines.append((duration, simple_line)) | |
slow_lines.sort(reverse=True) | |
for duration, line in slow_lines: | |
print line.strip() | |
total_slow_duration = sum([line[0] for line in slow_lines]) | |
print '' | |
print 'Total Build Time: {}ms'.format(total_duration) | |
print 'Slow Functions : {}ms'.format(total_slow_duration) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment