Class: UltraMarathon::Instrumentation::Profile
- Defined in:
- lib/ultra_marathon/instrumentation/profile.rb
Constant Summary collapse
- DATETIME_FORMAT =
'%H:%M:%S:%L'.freeze
- RAW_TIME_FORMAT =
'%02d:%02d:%02d:%03d'.freeze
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
-
#<=>(other_profile) ⇒ Integer
Comparison delegated to #total_time.
-
#call ⇒ Object
Sets #start_time, runs the initialized block, then sets #end_time.
-
#eql?(other_profile) ⇒ Boolean
Profiles are considered equal if their names are ‘eql?`.
-
#formatted_end_time ⇒ String
#end_time formatted per DATETIME_FORMAT.
-
#formatted_start_time ⇒ String
#start_time formatted per DATETIME_FORMAT.
-
#formatted_total_time ⇒ String
#total_time formatted per RAW_TIME_FORMAT.
-
#initialize(name, &block) ⇒ Profile
constructor
A new instance of Profile.
-
#total_time ⇒ Float
The total time in seconds to the nanosecond.
Constructor Details
#initialize(name, &block) ⇒ Profile
Returns a new instance of Profile.
13 14 15 16 17 18 19 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 13 def initialize(name, &block) @name = name # Ruby cannot marshal procs or lambdas, so we need to define a method. define_singleton_method :instrumented_block do block.call end end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
7 8 9 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 7 def end_time @end_time end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 7 def name @name end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
7 8 9 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 7 def start_time @start_time end |
Instance Method Details
#<=>(other_profile) ⇒ Integer
Comparison delegated to #total_time
56 57 58 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 56 def <=>(other_profile) total_time <=> other_profile.total_time end |
#call ⇒ Object
Sets #start_time, runs the initialized block, then sets #end_time
23 24 25 26 27 28 29 30 31 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 23 def call @start_time = Time.now begin return_value = instrumented_block ensure @end_time = Time.now end return_value end |
#eql?(other_profile) ⇒ Boolean
Profiles are considered equal if their names are ‘eql?`
63 64 65 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 63 def eql?(other_profile) name.eql? other_profile.name end |
#formatted_end_time ⇒ String
Returns #end_time formatted per DATETIME_FORMAT.
49 50 51 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 49 def formatted_end_time format_time(end_time) end |
#formatted_start_time ⇒ String
Returns #start_time formatted per DATETIME_FORMAT.
44 45 46 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 44 def formatted_start_time format_time(start_time) end |
#formatted_total_time ⇒ String
Returns #total_time formatted per RAW_TIME_FORMAT.
39 40 41 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 39 def formatted_total_time format_seconds(total_time) end |
#total_time ⇒ Float
Returns the total time in seconds to the nanosecond.
34 35 36 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 34 def total_time @total_time ||= end_time - start_time end |