2018-11-20 02:01:13 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-04 18:13:19 +00:00
|
|
|
module Gitlab
|
|
|
|
module Sherlock
|
|
|
|
class FileSample
|
|
|
|
attr_reader :id, :file, :line_samples, :events, :duration
|
|
|
|
|
2015-11-05 17:01:05 +00:00
|
|
|
# file - The full path to the file this sample belongs to.
|
|
|
|
# line_samples - An array of LineSample objects.
|
|
|
|
# duration - The total execution time in milliseconds.
|
|
|
|
# events - The total amount of events.
|
2015-11-04 18:13:19 +00:00
|
|
|
def initialize(file, line_samples, duration, events)
|
|
|
|
@id = SecureRandom.uuid
|
|
|
|
@file = file
|
|
|
|
@line_samples = line_samples
|
|
|
|
@duration = duration
|
|
|
|
@events = events
|
|
|
|
end
|
|
|
|
|
|
|
|
def relative_path
|
2018-01-27 05:35:53 +00:00
|
|
|
@relative_path ||= @file.gsub(%r{^#{Rails.root.to_s}/?}, '')
|
2015-11-04 18:13:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_param
|
|
|
|
@id
|
|
|
|
end
|
|
|
|
|
|
|
|
def source
|
|
|
|
@source ||= File.read(@file)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|