Class: Gitlab::Sherlock::LineSample

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/sherlock/line_sample.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(duration, events) ⇒ LineSample

duration - The execution time in milliseconds. events - The amount of events.


8
9
10
11
# File 'lib/gitlab/sherlock/line_sample.rb', line 8

def initialize(duration, events)
  @duration = duration
  @events = events
end

Instance Attribute Details

#durationObject (readonly)

Returns the value of attribute duration


4
5
6
# File 'lib/gitlab/sherlock/line_sample.rb', line 4

def duration
  @duration
end

#eventsObject (readonly)

Returns the value of attribute events


4
5
6
# File 'lib/gitlab/sherlock/line_sample.rb', line 4

def events
  @events
end

Instance Method Details

#majority_of?(total_duration) ⇒ Boolean

Returns true if the current sample takes up the majority of the given duration.

total_duration - The total duration to compare with.


31
32
33
# File 'lib/gitlab/sherlock/line_sample.rb', line 31

def majority_of?(total_duration)
  percentage_of(total_duration) >= 30
end

#percentage_of(total_duration) ⇒ Object

Returns the sample duration percentage relative to the given duration.

Example:

sample.duration            # => 150
sample.percentage_of(1500) # => 10.0

total_duration - The total duration to compare with.

Returns a float


23
24
25
# File 'lib/gitlab/sherlock/line_sample.rb', line 23

def percentage_of(total_duration)
  (duration.to_f / total_duration) * 100.0
end