Module: VisualCallGraph

Extended by:
VisualCallGraph
Included in:
VisualCallGraph
Defined in:
lib/visual_call_graph.rb

Instance Method Summary collapse

Instance Method Details

#traceObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/visual_call_graph.rb', line 7

def trace
  stack  = ["start"]
  edges  = []

  g = GraphViz.new(:G, :type => :digraph)

  g.add_node("start")

  trace =
  TracePoint.new(:call, :return) do |event|
    case event.event
    when :return then stack.pop
    when :call   then add_edges(event, edges, stack, g)
    end
  end

  trace.enable
  yield
  trace.disable

  g.output(png: "call_graph.png")

  puts "Call graph created with a total of #{g.node_count} #{g.node_count > 1 ? 'nodes' : 'node'}."
end