Class: UltraMarathon::Instrumentation::Profile
- Inherits:
-
Object
- Object
- UltraMarathon::Instrumentation::Profile
- Defined in:
- lib/ultra_marathon/instrumentation/profile.rb
Instance Attribute Summary collapse
-
#end_time ⇒ Object
readonly
Returns the value of attribute end_time.
-
#instrument_block ⇒ Object
readonly
Returns the value of attribute instrument_block.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
- #call ⇒ Object
-
#format_time(time) ⇒ Object
Private Instance Methods.
- #formatted_end_time ⇒ Object
- #formatted_start_time ⇒ Object
- #formatted_total_time ⇒ Object
-
#initialize(name, &block) ⇒ Profile
constructor
Public Instance Methods.
-
#total_time ⇒ Object
returns the total time, in seconds.
Constructor Details
#initialize(name, &block) ⇒ Profile
Public Instance Methods
8 9 10 11 12 13 14 15 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 8 def initialize(name, &block) @name = name # Ruby cannot marshal procs or lambdas, so we need to define a method. # Binding to self allows us to intercept logging calls. define_singleton_method :instrumentated_block do block.call end end |
Instance Attribute Details
#end_time ⇒ Object (readonly)
Returns the value of attribute end_time.
4 5 6 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 4 def end_time @end_time end |
#instrument_block ⇒ Object (readonly)
Returns the value of attribute instrument_block.
4 5 6 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 4 def instrument_block @instrument_block end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 4 def name @name end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
4 5 6 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 4 def start_time @start_time end |
Instance Method Details
#call ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 17 def call @start_time = Time.now begin return_value = instrumentated_block ensure @end_time = Time.now end return_value end |
#format_time(time) ⇒ Object
Private Instance Methods
50 51 52 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 50 def format_time(time) sprintf(TIME_FORMAT, time.hour, time.min, time.sec) end |
#formatted_end_time ⇒ Object
44 45 46 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 44 def formatted_end_time format_time(end_time) end |
#formatted_start_time ⇒ Object
40 41 42 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 40 def formatted_start_time format_time(start_time) end |
#formatted_total_time ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 32 def formatted_total_time duration = total_time seconds = (duration % 60).floor minutes = (duration / 60).floor hours = (duration / 3600).floor sprintf(TIME_FORMAT, hours, minutes, seconds) end |
#total_time ⇒ Object
returns the total time, in seconds
28 29 30 |
# File 'lib/ultra_marathon/instrumentation/profile.rb', line 28 def total_time (end_time - start_time).to_i end |