Skip to content

Commit

Permalink
Merge pull request #455 from cltnschlosser/optimize_performance_for_m…
Browse files Browse the repository at this point in the history
…any_binaries

Optimize performance for many binaries
  • Loading branch information
ksuther authored Apr 22, 2020
2 parents 985ff0a + f2b61c4 commit 7cb2e74
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 34 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ html
*.gcno

# JetBrains IDE
.idea/
.idea/

# Test output
report.llcov
report.json
23 changes: 14 additions & 9 deletions lib/slather/profdata_coverage_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@ def initialize(project, source, line_numbers_first)
end

def create_line_data
all_lines = source_code_lines
line_data = Hash.new
all_lines.each { |line| line_data[line_number_in_line(line, self.line_numbers_first)] = line }
self.line_data = line_data
end
private :create_line_data

def path_on_first_line?
path = self.source.split("\n")[0].sub ":", ""
!path.lstrip.start_with?("1|")
!source.lstrip.start_with?("1|")
end

def source_file_pathname
@source_file_pathname ||= begin
if path_on_first_line?
path = self.source.split("\n")[0].sub ":", ""
end_index = self.source.index(/:?\n/)
if end_index != nil
end_index -= 1
path = self.source[0..end_index]
else
# Empty file, output just contains path
path = self.source.sub ":", ""
end
path &&= Pathname(path)
else
# llvm-cov was run with just one matching source file
Expand Down Expand Up @@ -81,10 +86,7 @@ def source_data
end

def all_lines
if @all_lines == nil
@all_lines = source_code_lines
end
@all_lines
@all_lines ||= source_code_lines
end

def raw_source
Expand All @@ -103,6 +105,9 @@ def raw_data

def line_number_in_line(line, line_numbers_first = self.line_numbers_first)
if line_numbers_first
# Skip regex if the number is the first thing in the line
fastpath_number = line.to_i
return fastpath_number if fastpath_number != 0
line =~ /^(\s*)(\d*)/
group = $2
else
Expand Down Expand Up @@ -132,7 +137,7 @@ def line_number_in_line(line, line_numbers_first = self.line_numbers_first)
end

def line_coverage_data
source_code_lines.map do |line|
all_lines.map do |line|
coverage_for_line(line, self.line_numbers_first)
end
end
Expand Down
50 changes: 26 additions & 24 deletions lib/slather/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,36 +191,38 @@ def first_product_name
end

def profdata_coverage_dir
raise StandardError, "The specified build directory (#{self.build_directory}) does not exist" unless File.exists?(self.build_directory)
dir = nil
if self.scheme
dir = Dir[File.join(build_directory,"/**/CodeCoverage/#{self.scheme}")].first
else
dir = Dir[File.join(build_directory,"/**/#{first_product_name}")].first
end
@profdata_coverage_dir ||= begin
raise StandardError, "The specified build directory (#{self.build_directory}) does not exist" unless File.exists?(self.build_directory)
dir = nil
if self.scheme
dir = Dir[File.join(build_directory,"/**/CodeCoverage/#{self.scheme}")].first
else
dir = Dir[File.join(build_directory,"/**/#{first_product_name}")].first
end

if dir == nil
# Xcode 7.3 moved the location of Coverage.profdata
dir = Dir[File.join(build_directory,"/**/CodeCoverage")].first
end
if dir == nil
# Xcode 7.3 moved the location of Coverage.profdata
dir = Dir[File.join(build_directory,"/**/CodeCoverage")].first
end

if dir == nil && Slather.xcode_version[0] >= 9
# Xcode 9 moved the location of Coverage.profdata
coverage_files = Dir[File.join(build_directory, "/**/ProfileData/*/Coverage.profdata")]
if dir == nil && Slather.xcode_version[0] >= 9
# Xcode 9 moved the location of Coverage.profdata
coverage_files = Dir[File.join(build_directory, "/**/ProfileData/*/Coverage.profdata")]

if coverage_files.count == 0
# Look up one directory
# The ProfileData directory is next to Intermediates.noindex (in previous versions of Xcode the coverage was inside Intermediates)
coverage_files = Dir[File.join(build_directory, "../**/ProfileData/*/Coverage.profdata")]
end
if coverage_files.count == 0
# Look up one directory
# The ProfileData directory is next to Intermediates.noindex (in previous versions of Xcode the coverage was inside Intermediates)
coverage_files = Dir[File.join(build_directory, "../**/ProfileData/*/Coverage.profdata")]
end

if coverage_files != nil && coverage_files.count != 0
dir = Pathname.new(coverage_files.first).parent()
if coverage_files != nil && coverage_files.count != 0
dir = Pathname.new(coverage_files.first).parent()
end
end
end

raise StandardError, "No coverage directory found." unless dir != nil
dir
raise StandardError, "No coverage directory found." unless dir != nil
dir
end
end

def profdata_file
Expand Down

0 comments on commit 7cb2e74

Please sign in to comment.