Class: UltraMarathon::Instrumentation::Store
- Defined in:
- lib/ultra_marathon/instrumentation/store.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#[](name) ⇒ UltraMarathon::Instrumentation::Profile?
Access a profile by name.
-
#initialize(new_members = [], options = {}) ⇒ Store
constructor
A new instance of Store.
-
#instrument(name, &block) ⇒ Object
Instruments given block, setting its start time and end time Stores the resulting profile in in itself.
-
#mean_runtime ⇒ Float
The mean time for all profiles.
-
#median ⇒ UltraMarthon::Instrumentation::Profile
The profile in the middle of the pack per UltraMarthon::Instrumentation::Profile#total_time.
-
#merge!(other_store) ⇒ self
Adds all profiles from the other_store.
-
#prefix ⇒ String
The passed in prefix.
-
#standard_deviation ⇒ Float
Please forgive me Mr.
-
#total_time ⇒ Float
Accumulated total time for all stored profiles.
Constructor Details
#initialize(new_members = [], options = {}) ⇒ Store
Returns a new instance of Store.
11 12 13 14 15 16 |
# File 'lib/ultra_marathon/instrumentation/store.rb', line 11 def initialize(new_members=[], ={}) super(new_members) @options = { prefix: '' }.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/ultra_marathon/instrumentation/store.rb', line 5 def @options end |
Instance Method Details
#[](name) ⇒ UltraMarathon::Instrumentation::Profile?
Access a profile by name. Instrumentations shouldn’t have to know about their fully qualified name, so the unprefixed version should be passed
41 42 43 44 45 46 |
# 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) ⇒ Object
Instruments given block, setting its start time and end time Stores the resulting profile in in itself
23 24 25 26 27 28 |
# 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 ⇒ Float
Returns the mean time for all profiles.
55 56 57 |
# File 'lib/ultra_marathon/instrumentation/store.rb', line 55 def mean_runtime total_time / size end |
#median ⇒ UltraMarthon::Instrumentation::Profile
Returns the profile in the middle of the pack per UltraMarthon::Instrumentation::Profile#total_time.
62 63 64 |
# File 'lib/ultra_marathon/instrumentation/store.rb', line 62 def median to_a[size / 2] end |
#merge!(other_store) ⇒ self
Adds all profiles from the other_store
79 80 81 82 83 84 |
# File 'lib/ultra_marathon/instrumentation/store.rb', line 79 def merge!(other_store) other_store.each do |member| add(member) end self end |
#prefix ⇒ String
The passed in prefix
32 33 34 |
# File 'lib/ultra_marathon/instrumentation/store.rb', line 32 def prefix [:prefix] end |
#standard_deviation ⇒ Float
Please forgive me Mr. Brooks, I had to Google it
69 70 71 72 73 74 |
# 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 ⇒ Float
Accumulated total time for all stored profiles
50 51 52 |
# File 'lib/ultra_marathon/instrumentation/store.rb', line 50 def total_time total_times.reduce(0.0, :+) end |