visual_call_graph 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/visual_call_graph.rb +47 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cfbb41e6f6fbc0b3015d8c8da2a32ff08b8253fe
|
4
|
+
data.tar.gz: 98e17e00ac04f45d1692470772919044a7614bf8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1deaca5e27373f41a9c95ac94470320b282f425d025b8a73629b636462cdc6813d800e25b81f85a4ec81e01d3e0bb6dfb9fc1773ed4f574f59c8af473c04fda4
|
7
|
+
data.tar.gz: 95c6d052ef4c995603cf9458b97c78fe5bcde0816a0a66173ec5c9d82c2d791b9bcc1af9337688c648fa8d2f7b820dc3a43672ec0bd77337aea8cb628197bd44
|
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
require 'graphviz'
|
3
|
+
|
4
|
+
module VisualCallGraph
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def trace
|
8
|
+
stack = ["start"]
|
9
|
+
edges = []
|
10
|
+
|
11
|
+
g = GraphViz.new(:G, :type => :digraph)
|
12
|
+
|
13
|
+
g.add_node("start")
|
14
|
+
|
15
|
+
trace =
|
16
|
+
TracePoint.new(:call, :return) do |event|
|
17
|
+
case event.event
|
18
|
+
when :return then stack.pop
|
19
|
+
when :call then add_edges(event, edges, stack, g)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
trace.enable
|
24
|
+
yield
|
25
|
+
trace.disable
|
26
|
+
|
27
|
+
g.output(png: "call_graph.png")
|
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)
|
43
|
+
|
44
|
+
edges << edge
|
45
|
+
g.add_edge(*edges.last)
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: visual_call_graph
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jesus Castello
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Uses the TracePoint class & Graphviz to generate a visual representation
|
14
|
+
of all the methods called by another method.
|
15
|
+
email: jesus@blackbytes.info
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/visual_call_graph.rb
|
21
|
+
homepage:
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.5.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: ''
|
45
|
+
test_files: []
|
46
|
+
has_rdoc:
|