Class: HeapScope::AllocationTracer

Inherits:
Object
  • Object
show all
Defined in:
lib/heapscope/retention.rb

Overview

Allocation tracing helpers — opt-in only; never globally enable by surprise.

Instance Method Summary collapse

Constructor Details

#initialize(runtime: Runtime.current) ⇒ AllocationTracer

Returns a new instance of AllocationTracer.



60
61
62
63
# File 'lib/heapscope/retention.rb', line 60

def initialize(runtime: Runtime.current)
  @runtime = runtime
  @active = false
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/heapscope/retention.rb', line 65

def available?
  @runtime.allocation_tracing?
end

#start!Object



69
70
71
72
73
74
75
# File 'lib/heapscope/retention.rb', line 69

def start!
  return false unless available?

  @runtime.start_allocation_tracing
  @active = true
  true
end

#stop!Object



77
78
79
80
81
82
# File 'lib/heapscope/retention.rb', line 77

def stop!
  return unless @active

  @runtime.stop_allocation_tracing
  @active = false
end

#with_tracingObject



84
85
86
87
88
89
# File 'lib/heapscope/retention.rb', line 84

def with_tracing
  started = start!
  yield
ensure
  stop! if started
end