Class: RegoValidate::Profiler::Snapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/rego/cli/profiling.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.



94
95
96
97
98
# File 'lib/ruby/rego/cli/profiling.rb', line 94

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

Instance Attribute Details

#allocatedObject (readonly)

Returns the value of attribute allocated.



100
101
102
# File 'lib/ruby/rego/cli/profiling.rb', line 100

def allocated
  @allocated
end

#memsizeObject (readonly)

Returns the value of attribute memsize.



100
101
102
# File 'lib/ruby/rego/cli/profiling.rb', line 100

def memsize
  @memsize
end

#objectsObject (readonly)

Returns the value of attribute objects.



100
101
102
# File 'lib/ruby/rego/cli/profiling.rb', line 100

def objects
  @objects
end

Class Method Details

.captureObject



64
65
66
67
68
69
# File 'lib/ruby/rego/cli/profiling.rb', line 64

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



75
76
77
# File 'lib/ruby/rego/cli/profiling.rb', line 75

def capture_after
  capture
end

.capture_beforeObject



71
72
73
# File 'lib/ruby/rego/cli/profiling.rb', line 71

def capture_before
  capture
end

Instance Method Details

#delta(other) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/ruby/rego/cli/profiling.rb', line 102

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