Class: Barnes::Instruments::Stopwatch
- Inherits:
-
Object
- Object
- Barnes::Instruments::Stopwatch
- Defined in:
- lib/barnes/instruments/stopwatch.rb
Instance Method Summary collapse
-
#initialize(timepiece = Timepiece) ⇒ Stopwatch
constructor
A new instance of Stopwatch.
- #instrument!(state, counters, gauges) ⇒ Object
- #start!(state) ⇒ Object
Constructor Details
Instance Method Details
#instrument!(state, counters, gauges) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/barnes/instruments/stopwatch.rb', line 36 def instrument!(state, counters, gauges) last = state[:stopwatch] wall_elapsed = @timepiece.wall - last[:wall] counters[:'Time.wall'] = wall_elapsed if @has_cpu_time cpu_elapsed = @timepiece.cpu - last[:cpu] idle_elapsed = wall_elapsed - cpu_elapsed counters[:'Time.cpu'] = cpu_elapsed counters[:'Time.idle'] = idle_elapsed if wall_elapsed == 0 counters[:'Time.pct.cpu'] = 0 counters[:'Time.pct.idle'] = 0 else counters[:'Time.pct.cpu'] = 100.0 * cpu_elapsed / wall_elapsed counters[:'Time.pct.idle'] = 100.0 * idle_elapsed / wall_elapsed end end state[:stopwatch] = current end |
#start!(state) ⇒ Object
32 33 34 |
# File 'lib/barnes/instruments/stopwatch.rb', line 32 def start!(state) state[:stopwatch] = current end |