lib/heap_profiler/diff.rb in heap-profiler-0.1.0 vs lib/heap_profiler/diff.rb in heap-profiler-0.2.0
- old
+ new
@@ -1,33 +1,36 @@
# frozen_string_literal: true
module HeapProfiler
class Diff
+ class DumpSubset
+ def initialize(path, generation)
+ @path = path
+ @generation = generation
+ end
+
+ def each_object(&block)
+ Parser.load_many(@path, since: @generation, &block)
+ end
+ end
+
attr_reader :allocated
def initialize(report_directory)
@report_directory = report_directory
@allocated = open_dump('allocated')
@generation = Integer(File.read(File.join(report_directory, 'generation.info')))
end
def allocated_diff
- @allocated_diff ||= build_diff('allocated-diff', @allocated)
+ @allocated_diff ||= DumpSubset.new(@allocated.path, @generation)
end
def retained_diff
- @retained_diff ||= build_diff('retained-diff', open_dump('retained'))
+ @retained_diff ||= DumpSubset.new(open_dump('retained').path, @generation)
end
private
-
- def build_diff(name, base)
- diff = open_dump(name)
- unless diff.exist?
- base.filter(File.join(@report_directory, "#{name}.heap"), since: @generation)
- end
- diff
- end
def open_dump(name)
Dump.open(@report_directory, name)
end
end