class UltraMarathon::Instrumentation::Store
Attributes
Public Class Methods
@param new_members [Array, Set] @param options [Hash] @option options [String] :prefix ('') will prefix the name of every
name passed into {#instrument}
# 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
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
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
@return [Float] the mean time for all profiles
# File lib/ultra_marathon/instrumentation/store.rb, line 55 def mean_runtime total_time / size end
@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
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
The passed in prefix @return [String]
# File lib/ultra_marathon/instrumentation/store.rb, line 32 def prefix options[:prefix] end
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
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
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
@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