Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/usr/bin/env ruby
require 'optparse'
require 'pathname'
require 'json'
# http://danielbeard.io/2016/08/17/swift-file-compile-times.html
# Helper function to parse filename
def parse(input)
result = ""
processing_space_escape = false
input.each_char { |c|
if c == '\\'
result += c
processing_space_escape = true
elsif c == ' ' && processing_space_escape == true
result += c
processing_space_escape = false
elsif c == ' ' && processing_space_escape == false
return result
else
result += c
end
}
return result
end
compiling_swift_file = false
current_filename = ""
current_offset = 0
# all stdin lines
ARGF.each do |line|
# Wait until we hit a CompileSwift file
if line =~ /^[\s]*CompileSwift[\s]+/
compiling_swift_file = true
current_filename = parse(line[line.index('/')..-1]).chomp
end
# If we get here and aren't currently compiling a swift file, skip all else
if compiling_swift_file == false
next
end
# Ignore everything until we hit the "Swift compilation line"
if current_offset == 0 && line =~ /Swift compilation/
current_offset = 1
elsif current_offset >= 1
current_offset += 1
# This line has the total elapsed time.
if current_offset == 3
wall_time = line.gsub(/^.*\(/, '').match(/[-+]?[0-9]*\.?[0-9]+/) # Second fp value is the one we want.
puts "#{wall_time}s #{current_filename}"
compiling_swift_file = false
current_filename = ""
current_offset = 0
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment