class Busted::Tracer

Attributes

child_pid[R]
lines[RW]

Public Class Methods

exists?() click to toggle source
# File lib/busted/tracer.rb, line 9
def self.exists?
  system "hash dtrace 2>/dev/null"
end
new() click to toggle source
# File lib/busted/tracer.rb, line 13
def initialize
  @lines = ""
end

Public Instance Methods

finish() click to toggle source
# File lib/busted/tracer.rb, line 22
def finish
  final_probe
  wait until finished?
  kill
ensure
  clean_up
end
report() click to toggle source
# File lib/busted/tracer.rb, line 30
def report
  lines.split("\n").each_with_object({method: []}) do |line, result|
    next if line =~ /\ABusted/
    trace = line.split
    result[:method] << { class: trace[0], sourcefile: trace[1], lineno: trace[2] }
  end
end
start() click to toggle source
# File lib/busted/tracer.rb, line 17
def start
  spawn
  wait until started?
end

Private Instance Methods

clean_up() click to toggle source
# File lib/busted/tracer.rb, line 80
def clean_up
  log.close!
end
command() click to toggle source
# File lib/busted/tracer.rb, line 84
def command
  "sudo dtrace -q -o #{log.path} -s #{probe} -p #{parent_pid}"
end
final_probe() click to toggle source
# File lib/busted/tracer.rb, line 55
def final_probe
  raise FinishedException
rescue FinishedException
end
finished?() click to toggle source
# File lib/busted/tracer.rb, line 51
def finished?
  (lines << log.read) =~ /Busted::Tracer::FinishedException/
end
kill() click to toggle source
# File lib/busted/tracer.rb, line 64
def kill
  `sudo kill -TERM #{child_pid}`
end
log() click to toggle source
# File lib/busted/tracer.rb, line 76
def log
  @log ||= Tempfile.new "busted-dtrace.log"
end
parent_pid() click to toggle source
# File lib/busted/tracer.rb, line 68
def parent_pid
  Process.pid
end
probe() click to toggle source
# File lib/busted/tracer.rb, line 72
def probe
  File.expand_path "../../../dtrace/probes/busted/method-cache-clear.d", __FILE__
end
spawn() click to toggle source
# File lib/busted/tracer.rb, line 60
def spawn
  @child_pid = Process.spawn command, STDERR => STDOUT
end
started?() click to toggle source
# File lib/busted/tracer.rb, line 47
def started?
  !(lines << log.read).empty?
end
wait() click to toggle source
# File lib/busted/tracer.rb, line 43
def wait
  sleep 0.1
end