Class: TraceGraph::Tracer

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

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Tracer

Returns a new instance of Tracer.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/trace_graph/tracer.rb', line 5

def initialize(options)
  @options = options
  # We check included paths differently than excluded ones to allow nil to be bassed, to include everyting
  @included_paths = options.key?(:included_paths) ? options[:included_paths] : []
  @excluded_paths = options[:excluded_paths] || []
  @include_protected = options[:include_protected] || false
  @mark_duplicate_calls = options.key?(:mark_duplicate_calls) ? options[:mark_duplicate_calls] : true
  @show_arguments = options[:show_arguments] || false
  @show_return_values = options[:show_return_values] || false
  @only_class_transitions = options[:only_class_transitions] || false

  @trace_point = build_trace_point
  @top_node = TraceGraph::TraceNode.new("trace")
  @stack = []
  @all_nodes = [@top_node]
  @edge_count = 0
  @unique_node_counts = {}
end

Instance Method Details

#call_traceObject



41
42
43
# File 'lib/trace_graph/tracer.rb', line 41

def call_trace
  @top_node
end

#node_countObject



45
46
47
# File 'lib/trace_graph/tracer.rb', line 45

def node_count
  @all_nodes.length - 1 # should top_node count as a node?
end

#traceObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/trace_graph/tracer.rb', line 24

def trace
  unless block_given?
    raise Error.new "You must pass a block to the tracer."
  end

  @edge_count = 0
  @unique_node_counts = {}
  @trace_point.enable
  yield
  @trace_point.disable
  # TODO : Maybe outputting this should be an options, or a different tracer?
  puts @top_node.tree_graph
  if @options[:png]
    write_png @options[:png]
  end
end