Class: RegoValidate::Profiler::Measurement

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/rego/cli/profiling.rb

Overview

Tracks measurement state for a single sample.

Instance Method Summary collapse

Constructor Details

#initialize(label:, before:, start:) ⇒ Measurement

Returns a new instance of Measurement.



152
153
154
155
156
# File 'lib/ruby/rego/cli/profiling.rb', line 152

def initialize(label:, before:, start:)
  @label = label
  @before = before
  @start = start
end

Instance Method Details

#finish(after:, finish:) ⇒ Object



158
159
160
161
162
163
164
165
166
167
# File 'lib/ruby/rego/cli/profiling.rb', line 158

def finish(after:, finish:)
  delta = before.delta(after)
  Sample.new(
    label: label,
    duration_ms: ((finish - start) * 1000.0),
    allocations: delta.allocations,
    memory_bytes: delta.memory_bytes,
    top_objects: delta.top_objects
  )
end