Class: LeakProfiler::MemoryMemsize

Inherits:
Object
  • Object
show all
Defined in:
lib/leak_profiler/memory_memsize.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(output_dir:, interval:, filename: nil) ⇒ MemoryMemsize



14
15
16
17
18
# File 'lib/leak_profiler/memory_memsize.rb', line 14

def initialize(output_dir:, interval:, filename: nil)
  @output_dir = output_dir
  @interval = interval
  @filename = filename || "memory-memsize-#{Process.pid}.csv"
end

Instance Attribute Details

#threadObject (readonly)

Returns the value of attribute thread.



9
10
11
# File 'lib/leak_profiler/memory_memsize.rb', line 9

def thread
  @thread
end

Instance Method Details

#reportObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/leak_profiler/memory_memsize.rb', line 20

def report
  @thread = Thread.start do
    i = 0
    File.open(File.expand_path(File.join(@output_dir, @filename)), 'w') do |f|
      f.puts('elapsed [sec],ObjectSpace.memsize_of_all values [MB]')

      loop do
        memsize = Float(ObjectSpace.memsize_of_all) / (1024 * 1024)
        f.puts("#{i},#{memsize}")
        f.fsync
        i += @interval
        sleep(@interval)
      end
    end
  end
end