class UltraMarathon::Instrumentation::Store

Attributes

options[R]

Public Class Methods

new(new_members=[], options={}) click to toggle source

@param new_members [Array, Set] @param options [Hash] @option options [String] :prefix ('') will prefix the name of every

name passed into {#instrument}
Calls superclass method
# File lib/ultra_marathon/instrumentation/store.rb, line 11
def initialize(new_members=[], options={})
  super(new_members)
  @options = {
    prefix: ''
  }.merge(options)
end

Public Instance Methods

[](name) click to toggle source

Access a profile by name. Instrumentations shouldn't have to know about their fully qualified name, so the unprefixed version should be passed @param name [String] name of the profile that was passed to

{#instrument}

@return [UltraMarathon::Instrumentation::Profile, nil]

# File lib/ultra_marathon/instrumentation/store.rb, line 41
def [](name)
  full_name = full_name(name)
  detect do |profile|
    profile.name == full_name
  end
end
instrument(name, &block) click to toggle source

Instruments given block, setting its start time and end time Stores the resulting profile in in itself @param name [String] name of the instrumented block @param block [Proc] block to instrument @return [Object] return value of the instrumented block

# File lib/ultra_marathon/instrumentation/store.rb, line 23
def instrument(name, &block)
  profile = Profile.new(full_name(name), &block)
  return_value = profile.call
  self.add(profile)
  return_value
end
mean_runtime() click to toggle source

@return [Float] the mean time for all profiles

# File lib/ultra_marathon/instrumentation/store.rb, line 55
def mean_runtime
  total_time / size
end
median() click to toggle source

@return [UltraMarthon::Instrumentation::Profile] the profile in the

middle of the pack per
{UltraMarthon::Instrumentation::Profile#total_time}
# File lib/ultra_marathon/instrumentation/store.rb, line 62
def median
  to_a[size / 2]
end
merge!(other_store) click to toggle source

Adds all profiles from the other_store @param other_store [UltraMarathon::Instrumentation::Profile] @return [self] the other_store

# File lib/ultra_marathon/instrumentation/store.rb, line 79
def merge!(other_store)
  other_store.each do |member|
    add(member)
  end
  self
end
prefix() click to toggle source

The passed in prefix @return [String]

# File lib/ultra_marathon/instrumentation/store.rb, line 32
def prefix
  options[:prefix]
end
standard_deviation() click to toggle source

Please forgive me Mr. Brooks, I had to Google it @return [Float] the standard deviation from the mean

# File lib/ultra_marathon/instrumentation/store.rb, line 69
def standard_deviation
  sum_of_squares = total_times.reduce(0) do |sum, total_time|
    sum + (mean_runtime - total_time) ** 2
  end
  Math.sqrt(sum_of_squares / size)
end
total_time() click to toggle source

Accumulated total time for all stored profiles @return [Float]

# File lib/ultra_marathon/instrumentation/store.rb, line 50
def total_time
  total_times.reduce(0.0, :+)
end

Private Instance Methods

full_name(name) click to toggle source

Adds the prefix to the name @param name [String] the raw name @return [String] the prefixed name

# File lib/ultra_marathon/instrumentation/store.rb, line 93
def full_name(name)
  "#{prefix}#{name}"
end
total_times() click to toggle source

@return [Array<Float>] the total times for all stored profiles

# File lib/ultra_marathon/instrumentation/store.rb, line 98
def total_times
  map(&:total_time)
end