Class: RegoValidate::Profiler::Snapshot

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

Overview

Captures a memory snapshot for diffing.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(allocated:, memsize:, objects:) ⇒ Snapshot

Returns a new instance of Snapshot.



592
593
594
595
596
# File 'lib/ruby/rego/cli.rb', line 592

def initialize(allocated:, memsize:, objects:)
  @allocated = allocated
  @memsize = memsize
  @objects = objects
end

Instance Attribute Details

#allocatedObject (readonly)

Returns the value of attribute allocated.



598
599
600
# File 'lib/ruby/rego/cli.rb', line 598

def allocated
  @allocated
end

#memsizeObject (readonly)

Returns the value of attribute memsize.



598
599
600
# File 'lib/ruby/rego/cli.rb', line 598

def memsize
  @memsize
end

#objectsObject (readonly)

Returns the value of attribute objects.



598
599
600
# File 'lib/ruby/rego/cli.rb', line 598

def objects
  @objects
end

Class Method Details

.captureObject



562
563
564
565
566
567
# File 'lib/ruby/rego/cli.rb', line 562

def capture
  require "objspace"
  build_snapshot(memsize: ObjectSpace.memsize_of_all, objects: ObjectSpace.count_objects)
rescue LoadError, NoMethodError
  build_snapshot(memsize: 0, objects: empty_object_counts)
end

.capture_afterObject



573
574
575
# File 'lib/ruby/rego/cli.rb', line 573

def capture_after
  capture
end

.capture_beforeObject



569
570
571
# File 'lib/ruby/rego/cli.rb', line 569

def capture_before
  capture
end

Instance Method Details

#delta(other) ⇒ Object



600
601
602
603
604
605
606
# File 'lib/ruby/rego/cli.rb', line 600

def delta(other)
  Delta.new(
    allocations: other.allocated - allocated,
    memory_bytes: other.memsize - memsize,
    object_deltas: object_delta_map(other.objects)
  )
end