Class: Wildsight::Profiler::Profiler
- Inherits:
-
Object
- Object
- Wildsight::Profiler::Profiler
- Defined in:
- lib/wildsight/profiler/profiler.rb
Instance Method Summary collapse
- #duration(name, time = nil, options = {}, &block) ⇒ Object
- #durations ⇒ Object
-
#initialize(context) ⇒ Profiler
constructor
A new instance of Profiler.
Constructor Details
#initialize(context) ⇒ Profiler
Returns a new instance of Profiler.
5 6 7 8 |
# File 'lib/wildsight/profiler/profiler.rb', line 5 def initialize(context) @context = context @context.data[:profiler] ||= {} end |
Instance Method Details
#duration(name, time = nil, options = {}, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/wildsight/profiler/profiler.rb', line 10 def duration(name, time = nil, = {}, &block) if block_given? start = DateTime.now.to_f result = block.call stop = DateTime.now.to_f item = { before: start, after: stop } else result = nil item = { before: time[0], after: time[1] } end item[:duration] = (item[:after] - item[:before]) * 1000 durations[name] ||= { intervals: [], duration: 0.0 } durations[name][:intervals] << item durations[name][:duration] += item[:duration] return result end |
#durations ⇒ Object
27 28 29 |
# File 'lib/wildsight/profiler/profiler.rb', line 27 def durations @context.data[:profiler][:durations] ||= {} end |