call_graph 1.4.3 → 2.0.0.pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4e23fffc3451464c540fae79d3fd0f7225cddabb6a5e24f6dbe65d3a89fec77c
4
- data.tar.gz: c3049da23574bca206ad15829ed9698422c98a1cd53c2f0f818479035b00e563
3
+ metadata.gz: 1cd7595348f729124dcfb2f6539fa64a07cf9252a95f064db16f213a2d4eb5d9
4
+ data.tar.gz: 0363b8ea3eac72bddf9333e2b13b4719a877d0a81356df724413f8db616f40b9
5
5
  SHA512:
6
- metadata.gz: c4d62a6850b0a0b4b04f6e88f1f37ca69945d41db3b234540504e38b4b087409f52a1cf321e1350ff5af8ea0e1e48de40fb168e4b63ece09f5de73a9276568da
7
- data.tar.gz: 0b359aaf33665363b7fbacf32600d98dee01518036afcd48aea8579400ef7178d13f8f2574db91c12b002d1a90d40df8dc98da018b54474a1986df37703cf690
6
+ metadata.gz: 65e02be5c6814108da3345da3f004c17b53a4fb3d8266f060db92be498fad222f7c558633119adfcfeb433af3b68ea823e61a047b6c71f193fb68d3160b1ad2f
7
+ data.tar.gz: 5e4fbc1daa3ca4dc6d2e03bd8f9bc2e09d976efc589e7e1e945ff94b7b5e90b63c3b80ad491573e0e41c8b0d60cf232047d698b871ad3e86c3c2a6d44faafb3d
data/README.md CHANGED
@@ -41,9 +41,9 @@ CallGraph.config do |config|
41
41
  config.file_path = "examples/call-graph"
42
42
  end
43
43
 
44
- CallGraph.start
45
- A.x
46
- CallGraph.stop
44
+ CallGraph.trace do
45
+ A.x
46
+ end
47
47
  ```
48
48
 
49
49
  Print the captured execution with the provided rake tasks.
@@ -68,9 +68,6 @@ rake call_graph:printer:png # write png file from dot file
68
68
  ```ruby
69
69
  CallGraph.config do |config|
70
70
  config.file_path = "examples/call-graph"
71
- config.ignore_paths.clear
72
- config.ignore_methods << "stop"
73
- config.path(:png)
74
71
  end
75
72
  ```
76
73
 
data/examples/foobar.rb CHANGED
@@ -34,6 +34,6 @@ end
34
34
  `rm -f #{path}`
35
35
  end
36
36
 
37
- CallGraph.start
38
- A.x
39
- CallGraph.stop
37
+ CallGraph.trace do
38
+ A.x
39
+ end
@@ -1,14 +1,14 @@
1
1
  require 'set'
2
2
  require 'binding_of_caller'
3
3
 
4
+ INTROSPECT = "(self.class == Class ? self.name : self.class.name) + ' ' + (self.class == Class ? '(Class)' : '(Instance)')"
5
+
4
6
  module CallGraph
5
7
  class Instrument
6
- attr_accessor :file_path, :ignore_paths, :ignore_methods, :set
8
+ attr_accessor :file_path, :set
7
9
 
8
- def initialize(file_path: default_file_path, ignore_paths: default_ignore_paths, ignore_methods: default_ignore_methods)
10
+ def initialize(file_path: default_file_path)
9
11
  @file_path = file_path
10
- @ignore_paths = ignore_paths
11
- @ignore_methods = ignore_methods
12
12
  @set = Set.new
13
13
  end
14
14
 
@@ -17,72 +17,38 @@ module CallGraph
17
17
  end
18
18
 
19
19
  def default_file_path
20
- 'call_graph'
21
- end
22
-
23
- def default_ignore_paths
24
- [
25
- /#{RUBY_VERSION}/,
26
- /\(eval\)/,
27
- /bundle\/gems/,
28
- /spec/,
29
- /test/
30
- ]
20
+ 'call-graph'
31
21
  end
32
22
 
33
- def default_ignore_methods
34
- [
35
- :require,
36
- :set_encoding,
37
- :initialize,
38
- :new,
39
- :attr_reader,
40
- :method_added,
41
- :private,
42
- :inherited,
43
- :singleton_method_added,
44
- :set_trace_func,
45
- :call
46
- ]
47
- end
23
+ def trace(&block)
24
+ trace_point.enable
25
+ yield
26
+ trace_point.disable
48
27
 
49
- def start
50
- # :nocov:
51
- set_trace_func ->(event, file, _line, id, receiver_binding, classname) do
52
- return if ignore_paths.any? { |path| file && file[path] }
53
-
54
- case event
55
- when 'call', 'c-call'
56
- caller_binding = receiver_binding.of_caller(2)
28
+ File.open(path(:tmp), 'w') { |fd| fd.write set.to_a.compact.join("\n") }
57
29
 
58
- caller_class = caller_binding.eval('self.class == Class ? self.name : self.class.name')
59
- caller_class = caller_binding.frame_description unless caller_class
60
- caller_class = caller_class + ' ' + caller_binding.eval("self.class == Class ? '(Class)' : '(Instance)'")
30
+ set.clear
31
+ end
61
32
 
33
+ private
62
34
 
63
- receiver_class = receiver_binding.eval('self.class == Class ? self.name : self.class.name')
64
- receiver_class = caller_binding.frame_description if receiver_class.nil?
65
- receiver_class = receiver_class + ' ' + receiver_binding.eval("self.class == Class ? '(Class)' : '(Instance)'")
35
+ def trace_point
36
+ @trace_point ||= begin
37
+ TracePoint.new(:call) do |trace|
38
+ next if trace.defined_class == self.class
66
39
 
67
- return if classname == CallGraph
68
- return if classname == CallGraph::Instrument
69
- return if caller_class == receiver_class
70
- return if ignore_methods.include?(id)
40
+ case trace.event
41
+ when :call
42
+ id = trace.method_id
43
+ caller = trace.binding.of_caller(2).eval(INTROSPECT)
44
+ receiver = trace.binding.eval(INTROSPECT)
71
45
 
72
- set.add("#{caller_class},#{receiver_class},#{id}")
46
+ next if caller == receiver
47
+
48
+ set.add("#{caller},#{receiver},#{id}")
49
+ end
73
50
  end
74
- rescue Exception => e
75
- puts e.message
76
51
  end
77
- #:nocov:
78
- end
79
-
80
- def stop
81
- set_trace_func nil
82
-
83
- File.open(path(:tmp), 'w') { |fd| fd.write set.to_a.compact.join("\n") }
84
-
85
- set.clear
86
52
  end
87
53
  end
88
54
  end
@@ -1,3 +1,3 @@
1
1
  module CallGraph
2
- VERSION = '1.4.3'.freeze
2
+ VERSION = '2.0.0.pre'.freeze
3
3
  end
data/lib/call_graph.rb CHANGED
@@ -4,8 +4,8 @@ require 'call_graph/printers/dot'
4
4
  require 'call_graph/printers/png'
5
5
 
6
6
  module CallGraph
7
- def self.start
8
- instrument.start
7
+ def self.trace(&block)
8
+ instrument.trace(&block)
9
9
  end
10
10
 
11
11
  def self.config
@@ -16,10 +16,6 @@ module CallGraph
16
16
  end
17
17
  end
18
18
 
19
- def self.stop
20
- instrument.stop
21
- end
22
-
23
19
  private
24
20
 
25
21
  def self.instrument
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: call_graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.3
4
+ version: 2.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Moriarty
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-02 00:00:00.000000000 Z
11
+ date: 2019-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -109,9 +109,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  requirements:
112
- - - ">="
112
+ - - ">"
113
113
  - !ruby/object:Gem::Version
114
- version: '0'
114
+ version: 1.3.1
115
115
  requirements: []
116
116
  rubygems_version: 3.0.1
117
117
  signing_key: