Class: RegoValidate::Profiler::Delta

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

Overview

Computes deltas between snapshots.

Constant Summary collapse

SKIP_KEYS =
%i[TOTAL FREE].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allocations:, memory_bytes:, object_deltas:) ⇒ Delta

Returns a new instance of Delta.



134
135
136
137
138
# File 'lib/ruby/rego/cli/profiling.rb', line 134

def initialize(allocations:, memory_bytes:, object_deltas:)
  @allocations = allocations
  @memory_bytes = memory_bytes
  @object_deltas = object_deltas
end

Instance Attribute Details

#allocationsObject (readonly)

Returns the value of attribute allocations.



140
141
142
# File 'lib/ruby/rego/cli/profiling.rb', line 140

def allocations
  @allocations
end

#memory_bytesObject (readonly)

Returns the value of attribute memory_bytes.



140
141
142
# File 'lib/ruby/rego/cli/profiling.rb', line 140

def memory_bytes
  @memory_bytes
end

#object_deltasObject (readonly)

Returns the value of attribute object_deltas.



140
141
142
# File 'lib/ruby/rego/cli/profiling.rb', line 140

def object_deltas
  @object_deltas
end

Class Method Details

.skip_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


130
131
132
# File 'lib/ruby/rego/cli/profiling.rb', line 130

def self.skip_key?(key)
  SKIP_KEYS.include?(key)
end

Instance Method Details

#top_objects(limit: 3) ⇒ Object



142
143
144
145
146
147
# File 'lib/ruby/rego/cli/profiling.rb', line 142

def top_objects(limit: 3)
  object_deltas
    .sort_by { |(_, count)| -count }
    .first(limit)
    .map { |(key, count)| "#{key} +#{count}" }
end