Class: PSI::Sampler
- Inherits:
-
Object
- Object
- PSI::Sampler
- Defined in:
- lib/psi/sampler.rb
Overview
Calculates exact stall ratios from cumulative PSI totals.
Instance Method Summary collapse
-
#initialize(resource, cgroup: nil) ⇒ Sampler
constructor
A new instance of Sampler.
-
#sample ⇒ Delta?
Takes a sample and returns a delta after the first call.
Constructor Details
#initialize(resource, cgroup: nil) ⇒ Sampler
Returns a new instance of Sampler.
9 10 11 12 |
# File 'lib/psi/sampler.rb', line 9 def initialize(resource, cgroup: nil) @resource = resource @cgroup = cgroup end |
Instance Method Details
#sample ⇒ Delta?
Takes a sample and returns a delta after the first call.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/psi/sampler.rb', line 16 def sample reading = PSI.read(@resource, cgroup: @cgroup) sampled_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) return remember(reading, sampled_at) unless @previous elapsed = sampled_at - @sampled_at previous = @previous remember(reading, sampled_at) Delta.new( some_ratio: ratio(reading.some, previous.some, elapsed), full_ratio: ratio(reading.full, previous.full, elapsed), elapsed: elapsed ) end |