visual_call_graph 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/graph_manager.rb +44 -0
- data/lib/visual_call_graph.rb +7 -28
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e548d83e3737eefca0445354f1a5cbb84c216946
|
4
|
+
data.tar.gz: d01124dd37f6a0867fb57a5a7c93049f0ccfe42b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4fb3bd2ab4736345b55cb13b2372443e315ce4f3d4d8bc79db6ec25d87c8e57fc41817c151ec166ae8ae73e9c610dc482b9fd754129a48ff3de19500eb406d3
|
7
|
+
data.tar.gz: 96aac7d88ae62fa3db87acffe616d02e82b7ace9c10db308a866ad1a9fff8d6a3fe300004b04e294cfc4e7eebd6ae3103296122b1c2fec2f4ff7c87d5f9d2371
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
require 'graphviz'
|
3
|
+
|
4
|
+
class GraphManager
|
5
|
+
def initialize(options)
|
6
|
+
@stack = ["start"]
|
7
|
+
@edges = []
|
8
|
+
@options = options
|
9
|
+
|
10
|
+
@g = GraphViz.new(:G, :type => :digraph)
|
11
|
+
|
12
|
+
@g.add_node("start")
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_edges(event)
|
16
|
+
node =
|
17
|
+
if @options[:show_path]
|
18
|
+
"#{event.defined_class}##{event.method_id}\n#{event.path}".freeze
|
19
|
+
else
|
20
|
+
"#{event.defined_class}##{event.method_id}".freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
edge = [@stack.last, node]
|
24
|
+
|
25
|
+
@stack << node
|
26
|
+
|
27
|
+
return if @edges.include?(edge)
|
28
|
+
|
29
|
+
@edges << edge
|
30
|
+
@g.add_edge(*@edges.last)
|
31
|
+
end
|
32
|
+
|
33
|
+
def output(*args)
|
34
|
+
@g.output(*args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def node_count
|
38
|
+
@g.node_count
|
39
|
+
end
|
40
|
+
|
41
|
+
def pop
|
42
|
+
@stack.pop
|
43
|
+
end
|
44
|
+
end
|
data/lib/visual_call_graph.rb
CHANGED
@@ -1,22 +1,17 @@
|
|
1
1
|
|
2
|
-
|
2
|
+
require_relative 'graph_manager'
|
3
3
|
|
4
4
|
module VisualCallGraph
|
5
5
|
extend self
|
6
6
|
|
7
|
-
def trace
|
8
|
-
|
9
|
-
edges = []
|
10
|
-
|
11
|
-
g = GraphViz.new(:G, :type => :digraph)
|
12
|
-
|
13
|
-
g.add_node("start")
|
7
|
+
def trace(options = {})
|
8
|
+
graph = GraphManager.new(options)
|
14
9
|
|
15
10
|
trace =
|
16
11
|
TracePoint.new(:call, :return) do |event|
|
17
12
|
case event.event
|
18
|
-
when :return then
|
19
|
-
when :call then add_edges(event
|
13
|
+
when :return then graph.pop
|
14
|
+
when :call then graph.add_edges(event)
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
@@ -24,24 +19,8 @@ module VisualCallGraph
|
|
24
19
|
yield
|
25
20
|
trace.disable
|
26
21
|
|
27
|
-
|
28
|
-
|
29
|
-
puts "Call graph created with a total of #{g.node_count} #{g.node_count > 1 ? 'nodes' : 'node'}."
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def add_edges(event, edges, stack, g)
|
35
|
-
node = "#{event.defined_class}##{event.method_id}".freeze
|
36
|
-
|
37
|
-
g.add_node(node)
|
38
|
-
stack << node
|
39
|
-
|
40
|
-
edge = [stack[-2], stack[-1]]
|
41
|
-
|
42
|
-
return if edges.include?(edge)
|
22
|
+
graph.output(png: "#{Dir.pwd}/call_graph.png")
|
43
23
|
|
44
|
-
|
45
|
-
g.add_edge(*edges.last)
|
24
|
+
puts "Call graph created with a total of #{graph.node_count} #{graph.node_count > 1 ? 'nodes' : 'node'}."
|
46
25
|
end
|
47
26
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: visual_call_graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jesus Castello
|
@@ -37,6 +37,7 @@ executables: []
|
|
37
37
|
extensions: []
|
38
38
|
extra_rdoc_files: []
|
39
39
|
files:
|
40
|
+
- lib/graph_manager.rb
|
40
41
|
- lib/visual_call_graph.rb
|
41
42
|
homepage: http://www.blackbytes.info
|
42
43
|
licenses:
|