Class: LeakProfiler::MemoryMemsize
- Inherits:
-
Object
- Object
- LeakProfiler::MemoryMemsize
- Defined in:
- lib/leak_profiler/memory_memsize.rb
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Returns the value of attribute thread.
Instance Method Summary collapse
-
#initialize(output_dir:, interval:, filename: nil) ⇒ MemoryMemsize
constructor
A new instance of MemoryMemsize.
- #report ⇒ Object
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
#thread ⇒ Object (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
#report ⇒ Object
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.(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 |