Class: HeapProfiler::Reporter
- Inherits:
-
Object
- Object
- HeapProfiler::Reporter
- Defined in:
- lib/heap_profiler/reporter.rb
Instance Method Summary collapse
-
#initialize(dir_path) ⇒ Reporter
constructor
A new instance of Reporter.
- #run ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(dir_path) ⇒ Reporter
Returns a new instance of Reporter.
34 35 36 37 38 |
# File 'lib/heap_profiler/reporter.rb', line 34 def initialize(dir_path) @dir_path = dir_path @enable_tracing = !allocation_tracing_enabled? @generation = nil end |
Instance Method Details
#run ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/heap_profiler/reporter.rb', line 70 def run start begin yield rescue Exception ObjectSpace.trace_object_allocations_stop if @enable_tracing GC.enable raise else stop end end |
#start ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/heap_profiler/reporter.rb', line 40 def start FileUtils.mkdir_p(@dir_path) ObjectSpace.trace_object_allocations_start if @enable_tracing @allocated_heap = open_heap("allocated") @retained_heap = open_heap("retained") HeapProfiler.name_anonymous_modules! 4.times { GC.start } GC.disable @generation = GC.count end |
#stop ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/heap_profiler/reporter.rb', line 54 def stop HeapProfiler.name_anonymous_modules! ObjectSpace.trace_object_allocations_stop if @enable_tracing # we can't use partial dump for allocated.heap, because we need old generations # as well to build the classes and strings indexes. dump_heap(@allocated_heap) GC.enable 4.times { GC.start } dump_heap(@retained_heap, partial: true) @allocated_heap.close @retained_heap.close write_info("generation", @generation.to_s) end |