Class: IRWebmachine::Tracer

Inherits:
Object
  • Object
show all
Defined in:
lib/irwebmachine/tracer.rb

Instance Method Summary collapse

Constructor Details

#initializeTracer



3
4
5
6
7
8
9
# File 'lib/irwebmachine/tracer.rb', line 3

def initialize
  @thread  = nil
  @queue   = SizedQueue.new(1)
  @targets = [BasicObject]
  @events  = ["call", "c-call", "return", "c-return", "class", "end", "line",
  "raise"]
end

Instance Method Details

#continueIRwebmachine::Frame?

Examples:

#
# Each call to continue resumes & then suspends the tracer.
# If you want to trace until there is no more code to trace you
# could wrap this method in a loop.
#
tracer.continue
tracer.continue


75
76
77
78
79
80
81
# File 'lib/irwebmachine/tracer.rb', line 75

def continue
  while @queue.empty?
    sleep 0.01
    return if finished?
  end
  @queue.deq
end

#events=(events) ⇒ void

This method returns an undefined value.

The set_trace_func API documentation has a list of possible events.

Examples:

#
# Push a frame onto the queue when the "call" or "return" event is
# emitted by set_trace_func. By default, all events push a frame
# onto the queue.
#
tracer.events = ["call", "return"]


28
29
30
# File 'lib/irwebmachine/tracer.rb', line 28

def events=(events)
  @events = events
end

#finished?Boolean



54
55
56
# File 'lib/irwebmachine/tracer.rb', line 54

def finished?
  @queue.empty? && [false, nil].include?(@thread.status)
end

#targets=(targets) ⇒ void

This method returns an undefined value.

Examples:

#
# Push a frame onto the queue when `binding.eval('self')` has
# Webmachine::Resource::Callbacks somewhere in its ancestry tree.
# By default, targets is equal to [BasicObject].
#
tracer.targets = [Webmachine::Resource::Callbacks]


46
47
48
# File 'lib/irwebmachine/tracer.rb', line 46

def targets=(targets)
  @targets = targets
end

#trace(&block) ⇒ void

This method returns an undefined value.

Examples:

tracer.trace do
  

See Also:



98
99
100
101
102
103
104
105
# File 'lib/irwebmachine/tracer.rb', line 98

def trace
  @thread ||=
  Thread.new do
    Thread.current.set_trace_func method(:tracer).to_proc
    yield
    Thread.current.set_trace_func(nil)
  end
end