class UltraMarathon::Instrumentation::Profile
Constants
- DATETIME_FORMAT
- RAW_TIME_FORMAT
Attributes
end_time[R]
name[R]
start_time[R]
Public Class Methods
new(name, &block)
click to toggle source
@param name [String] name of the instrumented block @param block [Proc] block to be instrumented
# 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
Public Instance Methods
<=>(other_profile)
click to toggle source
Comparison delegated to {#total_time} @param other_profile [Profile] @return [Integer] {#total_time} <=> other_profile.total_time
# File lib/ultra_marathon/instrumentation/profile.rb, line 56 def <=>(other_profile) total_time <=> other_profile.total_time end
call()
click to toggle source
Sets {#start_time}, runs the initialized block, then sets {#end_time} @return [Object] the return value of the initialized block
# 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)
click to toggle source
Profiles are considered equal if their names are `eql?` @param other_profile [Profile] @return [Boolean] delegates to {#name}
# File lib/ultra_marathon/instrumentation/profile.rb, line 63 def eql?(other_profile) name.eql? other_profile.name end
formatted_end_time()
click to toggle source
@return [String] {#end_time} formatted per {DATETIME_FORMAT}
# File lib/ultra_marathon/instrumentation/profile.rb, line 49 def formatted_end_time format_time(end_time) end
formatted_start_time()
click to toggle source
@return [String] {#start_time} formatted per {DATETIME_FORMAT}
# File lib/ultra_marathon/instrumentation/profile.rb, line 44 def formatted_start_time format_time(start_time) end
formatted_total_time()
click to toggle source
@return [String] {#total_time} formatted per {RAW_TIME_FORMAT}
# File lib/ultra_marathon/instrumentation/profile.rb, line 39 def formatted_total_time format_seconds(total_time) end
total_time()
click to toggle source
@return [Float] the total time in seconds to the nanosecond
# File lib/ultra_marathon/instrumentation/profile.rb, line 34 def total_time @total_time ||= end_time - start_time end
Private Instance Methods
format_seconds(total_seconds)
click to toggle source
Private Instance Methods
# File lib/ultra_marathon/instrumentation/profile.rb, line 71 def format_seconds(total_seconds) seconds = (total_seconds % 60).floor minutes = (total_seconds / 60).floor hours = (total_seconds / 3600).floor milliseconds = (total_seconds - total_seconds.to_i) * 1000.0 sprintf(RAW_TIME_FORMAT, hours, minutes, seconds, milliseconds) end
format_time(time)
click to toggle source
# File lib/ultra_marathon/instrumentation/profile.rb, line 79 def format_time(time) time.strftime(DATETIME_FORMAT) end