Module: VisualCallGraph

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

Instance Method Summary collapse

Instance Method Details

#node_count(graph) ⇒ Object



32
33
34
# File 'lib/visual_call_graph.rb', line 32

def node_count(graph)
  "#{graph.node_count} #{(graph.node_count > 1 ? 'nodes' : 'node')}"
end

#trace(options = {}) ⇒ Object



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(options = {})
  unless block_given?
    puts "Block required"
    return
  end

  graph = GraphManager.new(options)

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

  trace.enable
  yield
  trace.disable

  graph.output(png: "#{Dir.pwd}/call_graph.png")

  puts "Call graph created with a total of #{node_count(graph)}."
end